diff options
| author | Ben Bridle <bridle.benjamin@gmail.com> | 2026-02-06 14:55:05 +1300 |
|---|---|---|
| committer | Ben Bridle <bridle.benjamin@gmail.com> | 2026-02-06 14:55:05 +1300 |
| commit | 8c2ac6d92f6a4579591f748eebcbca2b9913d92d (patch) | |
| tree | b93f4fed5676f292e5070d11e2817655516fb355 /src/generate_html.rs | |
| parent | dc985df5fe8c748e05181a8f5062eba3f9a2b64a (diff) | |
| download | toaster-8c2ac6d92f6a4579591f748eebcbca2b9913d92d.zip | |
Move string utilities to separate module
This makes things tidier.
Diffstat (limited to 'src/generate_html.rs')
| -rw-r--r-- | src/generate_html.rs | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/src/generate_html.rs b/src/generate_html.rs index b635767..5526a06 100644 --- a/src/generate_html.rs +++ b/src/generate_html.rs @@ -467,58 +467,6 @@ fn parse_external_link(label: &str, path: &str, page: &Page, website: &Website) ParsedLink { path, class: "external", label } } - -/// Replace each HTML-reserved character with an HTML-escaped character. -fn sanitize_text(text: &str, fancy: bool) -> String { - let mut output = String::new(); - let chars: Vec<char> = text.chars().collect(); - for (i, c) in chars.iter().enumerate() { - let prev = match i > 0 { - true => chars[i - 1], - false => ' ', - }; - let next = match i + 1 < chars.len() { - true => chars[i + 1], - false => ' ', - }; - let is_whitespace = |c: char| c.is_whitespace() || "()[].,".contains(c); - - match c { - '&' => { - // The HTML syntax for unicode characters is � - if let Some('#') = chars.get(i+1) { output.push(*c) } - else { output.push_str("&") } - }, - '<' => output.push_str("<"), - '>' => output.push_str(">"), - '"' => match fancy { - true => match is_whitespace(prev) { - true => output.push('“'), - false => output.push('”'), - } - false => output.push_str("""), - }, - '\'' => match fancy { - true => match is_whitespace(prev) { - true => output.push('‘'), - false => output.push('’'), - } - false => output.push_str("'"), - }, - '-' if fancy => match prev.is_whitespace() && next.is_whitespace() { - 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), - } - } - return output; -} - - /// Remove a 'Appendix #: ' prefix from a string. pub fn strip_appendix(text: &str) -> &str { if let Some((prefix, name)) = text.split_once(": ") { |
