From 200bb2c3c2af8f43d8403015198cc1932293b7bf Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Fri, 30 Jan 2026 19:26:26 +1300 Subject: Improve smart-quote direction around punctuation An apostrophe or quotation mark should point right (start a quote) if it is preceded either by whitespace or a punctuation character. --- src/generate_html.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/generate_html.rs b/src/generate_html.rs index 6909871..36f3325 100644 --- a/src/generate_html.rs +++ b/src/generate_html.rs @@ -468,6 +468,8 @@ fn sanitize_text(text: &str, fancy: bool) -> String { true => chars[i + 1], false => ' ', }; + let is_whitespace = |c: char| c.is_whitespace() || "()[].,".contains(c); + match c { '&' => { // The HTML syntax for unicode characters is � @@ -477,14 +479,14 @@ fn sanitize_text(text: &str, fancy: bool) -> String { '<' => output.push_str("<"), '>' => output.push_str(">"), '"' => match fancy { - true => match prev.is_whitespace() { + true => match is_whitespace(prev) { true => output.push('“'), false => output.push('”'), } false => output.push_str("""), }, '\'' => match fancy { - true => match prev.is_whitespace() { + true => match is_whitespace(prev) { true => output.push('‘'), false => output.push('’'), } -- cgit v1.2.3-70-g09d2