From 53ef3245842738dfc2e4dbb68df310614ed36ab6 Mon Sep 17 00:00:00 2001 From: Adam Israel Date: Sun, 15 Feb 2026 17:59:46 -0500 Subject: [PATCH 1/2] Convert double hyphens to em-dash When we encounter a double-hyphen in Markdown, convert it to a proper em-dash and remove any extraneous spaces around it. --- src/markdown.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/markdown.rs b/src/markdown.rs index 70bc19f..5a16f4f 100644 --- a/src/markdown.rs +++ b/src/markdown.rs @@ -19,6 +19,13 @@ fn strip_comments(mut content: String) -> String { content.trim().to_string() } +/// Convert hyphens to em-dashes +fn convert_hyphens_to_em_dashes(mut content: String) -> String { + let re = Regex::new(r"(\s+--\s+)").unwrap(); + content = Regex::replace_all(&re, content.as_str(), "—").to_string(); + content.trim().to_string() +} + /// Convert the content of a Markdown into a collection of paragraphs. fn content_to_paragraphs(mut content: String) -> Vec { // Pre-process the content @@ -26,6 +33,9 @@ fn content_to_paragraphs(mut content: String) -> Vec { // Add support single and multi-line %% comment blocks %% content = strip_comments(content); + // Replace double-hyphens to em-dashes + content = convert_hyphens_to_em_dashes(content); + let mut paragraphs: Vec = vec![]; let sep = Paragraph::new() .add_run(Run::new().add_text("#")) @@ -262,6 +272,12 @@ mod tests { assert!(content.is_empty()); } + #[test] + fn test_convert_hyphens_to_em_dashes() { + let content = convert_hyphens_to_em_dashes("This is a test -- only a test -- he was told.".to_string()); + assert!(content == "This is a test—only a test—he was told."); + } + #[test] fn test_trim_doublespace() { let s = "This is a test. This is only a test.\nIf this were an actual emergency, you would be instructed where to go and what to do."; From 55bea43c8a9cbcb2d808d49efc3694b57f6d03ba Mon Sep 17 00:00:00 2001 From: Adam Israel Date: Sun, 22 Mar 2026 12:41:30 -0400 Subject: [PATCH 2/2] fix: rustfmt --- src/markdown.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/markdown.rs b/src/markdown.rs index 5a16f4f..c205485 100644 --- a/src/markdown.rs +++ b/src/markdown.rs @@ -274,7 +274,9 @@ mod tests { #[test] fn test_convert_hyphens_to_em_dashes() { - let content = convert_hyphens_to_em_dashes("This is a test -- only a test -- he was told.".to_string()); + let content = convert_hyphens_to_em_dashes( + "This is a test -- only a test -- he was told.".to_string(), + ); assert!(content == "This is a test—only a test—he was told."); }