From 8ac6d02386955ad00a809cbaaf60f029b12ccdcc Mon Sep 17 00:00:00 2001 From: Fuwn Date: Mon, 17 Apr 2023 06:19:59 +0000 Subject: fix(to_html): messy markdown to html conversion --- Cargo.toml | 5 +---- src/gemini_to_html.rs | 31 +++++++------------------------ 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7371e54..2022cd3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "september" -version = "0.2.4" +version = "0.2.5" authors = ["Fuwn "] 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("

") || html.ends_with("

\n")) - && html.starts_with("

") - { - html - .trim_start_matches("

") - .trim_end_matches("

") - .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!("

{}

", to_html(text))), + Node::Text(text) => html.push_str(&format!("

{text}

")), 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!( "", items .iter() - .map(|i| format!("
  • {}
  • ", to_html(i))) + .map(|i| format!("
  • {i}
  • ")) .collect::>() .join("\n") )), Node::Blockquote(text) => { - html.push_str(&format!("
    {}
    ", to_html(text))); + html.push_str(&format!("
    {text}
    ")); } Node::PreformattedText { text, .. } => { html.push_str(&format!("
    {text}
    ")); } - Node::Whitespace => {} + Node::Whitespace => { + println!("i am white"); + } } } -- cgit v1.2.3