diff options
| author | Fuwn <[email protected]> | 2023-04-17 06:19:59 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-04-17 06:20:09 +0000 |
| commit | 8ac6d02386955ad00a809cbaaf60f029b12ccdcc (patch) | |
| tree | 979c375d3939bbe981189f3d15674b425e1b4648 | |
| parent | style(response): format style (diff) | |
| download | september-8ac6d02386955ad00a809cbaaf60f029b12ccdcc.tar.xz september-8ac6d02386955ad00a809cbaaf60f029b12ccdcc.zip | |
fix(to_html): messy markdown to html conversion
| -rw-r--r-- | Cargo.toml | 5 | ||||
| -rw-r--r-- | src/gemini_to_html.rs | 31 |
2 files changed, 8 insertions, 28 deletions
@@ -2,7 +2,7 @@ [package] name = "september" -version = "0.2.4" +version = "0.2.5" authors = ["Fuwn <[email protected]>"] edition = "2021" description = "A simple and efficient Gemini-to-HTTP proxy." @@ -34,9 +34,6 @@ log = "0.4.16" # Environment Variables dotenv = "0.15.0" -# Markdown to HTML -markly = "0.3.0" - [build-dependencies] # Environment Variables vergen = "7.0.0" diff --git a/src/gemini_to_html.rs b/src/gemini_to_html.rs index f4ab38b..593f9dd 100644 --- a/src/gemini_to_html.rs +++ b/src/gemini_to_html.rs @@ -21,25 +21,6 @@ use std::env::var; use germ::ast::Node; use gmi::url::Url; -fn to_html(text: &str) -> String { - let html = if text.contains('$') { - text.to_string() - } else { - markly::to_html(text) - }; - - if (html.ends_with("</p>") || html.ends_with("</p>\n")) - && html.starts_with("<p>") - { - html - .trim_start_matches("<p>") - .trim_end_matches("</p>") - .to_string() - } else { - html - } -} - fn link_from_host_href(url: &Url, href: &str) -> String { format!( "gemini://{}{}{}", @@ -69,7 +50,7 @@ pub fn gemini_to_html( for node in ast { match node { - Node::Text(text) => html.push_str(&format!("<p>{}</p>", to_html(text))), + Node::Text(text) => html.push_str(&format!("<p>{text}</p>")), Node::Link { to, text } => { let mut href = to.clone(); let mut surface = false; @@ -148,24 +129,26 @@ pub fn gemini_to_html( 3 => "h3", _ => "p", }, - to_html(text), + text, )); } Node::List(items) => html.push_str(&format!( "<ul>{}</ul>", items .iter() - .map(|i| format!("<li>{}</li>", to_html(i))) + .map(|i| format!("<li>{i}</li>")) .collect::<Vec<String>>() .join("\n") )), Node::Blockquote(text) => { - html.push_str(&format!("<blockquote>{}</blockquote>", to_html(text))); + html.push_str(&format!("<blockquote>{text}</blockquote>")); } Node::PreformattedText { text, .. } => { html.push_str(&format!("<pre>{text}</pre>")); } - Node::Whitespace => {} + Node::Whitespace => { + println!("i am white"); + } } } |