diff options
| author | Fuwn <[email protected]> | 2023-02-04 05:02:03 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-02-04 05:02:03 +0000 |
| commit | 1d498c946f58dc1fdaf6e932d2186520125d23d4 (patch) | |
| tree | 748b398cc0dc69e8dae46ee224448261bf3e84dc /src | |
| parent | fix(gemini_to_html.rs): remove html escaping (diff) | |
| download | september-1d498c946f58dc1fdaf6e932d2186520125d23d4.tar.xz september-1d498c946f58dc1fdaf6e932d2186520125d23d4.zip | |
feat: markdown to html
Diffstat (limited to 'src')
| -rw-r--r-- | src/gemini_to_html.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/gemini_to_html.rs b/src/gemini_to_html.rs index 72574a4..ea09336 100644 --- a/src/gemini_to_html.rs +++ b/src/gemini_to_html.rs @@ -20,6 +20,7 @@ use std::env::var; use germ::ast::Node; use gmi::url::Url; +use markly::to_html; fn link_from_host_href(url: &Url, href: &str) -> String { format!( @@ -50,7 +51,7 @@ pub fn gemini_to_html( for node in ast { match node { - Node::Text(text) => html.push_str(&format!("<p>{text}</p>")), + Node::Text(text) => html.push_str(&format!("<p>{}</p>", to_html(text))), Node::Link { to, text } => { let mut href = to.clone(); let mut surface = false; @@ -111,7 +112,7 @@ pub fn gemini_to_html( html.push_str(&format!( "<p><a href=\"{}\">{}</a></p>\n", href, - text.clone().unwrap_or_default() + to_html(&text.clone().unwrap_or_default()) )); } Node::Heading { level, text } => { @@ -127,19 +128,19 @@ pub fn gemini_to_html( 3 => "h3", _ => "p", }, - text + to_html(text) )); } Node::List(items) => html.push_str(&format!( "<ul>{}</ul>", items .iter() - .map(|i| format!("<li>{i}</li>")) + .map(|i| format!("<li>{}</li>", to_html(i))) .collect::<Vec<String>>() .join("\n") )), Node::Blockquote(text) => { - html.push_str(&format!("<blockquote>{text}</blockquote>")); + html.push_str(&format!("<blockquote>{}</blockquote>", to_html(text))); } Node::PreformattedText { text, .. } => { html.push_str(&format!("<pre>{text}</pre>")); |