From d98b9a0e6b8cbe499e92a49cd749d0248f0d8e47 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Wed, 21 May 2025 12:57:14 +1200 Subject: 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. --- src/generate_html.rs | 7 +++++-- 1 file 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), } -- cgit v1.2.3-70-g09d2