From b13c3e6b0dbf46d7fa1828a3104bcaef7db31a8f Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 4 Feb 2023 05:02:03 +0000 Subject: feat: markdown to html --- Cargo.toml | 3 +++ src/gemini_to_html.rs | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8b9092b..f4cc638 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,6 +34,9 @@ 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 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!("

{text}

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

{}

", 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!( "

{}

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