aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/epub.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/epub.rs b/src/epub.rs
index d09b100..2df924c 100644
--- a/src/epub.rs
+++ b/src/epub.rs
@@ -66,7 +66,7 @@ impl Epub {
frag: Vec::new(),
};
render(body, &mut c);
- if c.text.is_empty() {
+ if c.text.trim().is_empty() {
continue;
}
let relative = path.rsplit('/').next().unwrap();
@@ -164,8 +164,14 @@ impl Chapter {
fn render(n: Node, c: &mut Chapter) {
if n.is_text() {
let text = n.text().unwrap();
- if !text.trim().is_empty() {
- c.text.push_str(text);
+ let content: Vec<_> = text.split_ascii_whitespace().collect();
+
+ if text.starts_with(char::is_whitespace) {
+ c.text.push(' ');
+ }
+ c.text.push_str(&content.join(" "));
+ if text.ends_with(char::is_whitespace) {
+ c.text.push(' ');
}
return;
}