summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2026-01-30 19:26:26 +1300
committerBen Bridle <bridle.benjamin@gmail.com>2026-01-30 19:26:26 +1300
commit200bb2c3c2af8f43d8403015198cc1932293b7bf (patch)
tree3943a5c604e353f79c47a783eb03b175f5a98fee /src
parentfac075a91fef0ecac8ad1ca8c276ce3ccebd537b (diff)
downloadtoaster-200bb2c3c2af8f43d8403015198cc1932293b7bf.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/generate_html.rs6
1 files changed, 4 insertions, 2 deletions
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 &#0000
@@ -477,14 +479,14 @@ fn sanitize_text(text: &str, fancy: bool) -> String {
'<' => output.push_str("&lt;"),
'>' => output.push_str("&gt;"),
'"' => match fancy {
- true => match prev.is_whitespace() {
+ true => match is_whitespace(prev) {
true => output.push('“'),
false => output.push('”'),
}
false => output.push_str("&#34;"),
},
'\'' => match fancy {
- true => match prev.is_whitespace() {
+ true => match is_whitespace(prev) {
true => output.push('‘'),
false => output.push('’'),
}