Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,23 @@ 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<Paragraph> {
// Pre-process the content

// 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<Paragraph> = vec![];
let sep = Paragraph::new()
.add_run(Run::new().add_text("#"))
Expand Down Expand Up @@ -262,6 +272,14 @@ 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.";
Expand Down
Loading