diff options
author | Ben Bridle <ben@derelict.engineering> | 2025-05-21 12:57:14 +1200 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2025-05-21 19:50:09 +1200 |
commit | d98b9a0e6b8cbe499e92a49cd749d0248f0d8e47 (patch) | |
tree | eeb0129dd3bb95191e822062dcb7b2428bbce793 | |
parent | 24bc3c6bd64be8ed84ae3aff75cf9f2901214555 (diff) | |
download | toaster-d98b9a0e6b8cbe499e92a49cd749d0248f0d8e47.zip |
Refine dash replacement rules
A dash that isn't mid-word will be replaced with an em dash if in the
middle of a line, or with an en dash if at the start of a line.
-rw-r--r-- | src/generate_html.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/generate_html.rs b/src/generate_html.rs index a6aa0b6..e329739 100644 --- a/src/generate_html.rs +++ b/src/generate_html.rs @@ -415,8 +415,11 @@ fn sanitize_text(text: &str, fancy: bool) -> String { false => output.push('’'), }, '-' if fancy => match prev.is_whitespace() && next.is_whitespace() { - true => output.push('—'), - false => output.push('-'), + true => match i > 0 { + true => output.push('—'), // em-dash, for mid-sentence + false => output.push('–'), // en-dash, for start of line + } + false => output.push('-'), // regular dash, for mid-word } _ => output.push(*c), } |