diff options
author | James Campos <james.r.campos@gmail.com> | 2020-09-21 06:16:11 -0700 |
---|---|---|
committer | James Campos <james.r.campos@gmail.com> | 2020-09-21 06:16:11 -0700 |
commit | 0b267abb97922fd6e9f07f63e77b5b066cdaaa9a (patch) | |
tree | 6603948dbd8e305d41fdce4f85c55598f26f8d31 /src | |
parent | eb3bd9fc920d72e129bc5137e32d9855db36031e (diff) | |
download | bk-0b267abb97922fd6e9f07f63e77b5b066cdaaa9a.tar.gz |
normalize whitespace
Diffstat (limited to 'src')
-rw-r--r-- | src/epub.rs | 12 |
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; } |