aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-02-04 05:02:03 +0000
committerFuwn <[email protected]>2023-02-04 05:02:03 +0000
commit1d498c946f58dc1fdaf6e932d2186520125d23d4 (patch)
tree748b398cc0dc69e8dae46ee224448261bf3e84dc
parentfix(gemini_to_html.rs): remove html escaping (diff)
downloadseptember-1d498c946f58dc1fdaf6e932d2186520125d23d4.tar.xz
september-1d498c946f58dc1fdaf6e932d2186520125d23d4.zip
feat: markdown to html
-rw-r--r--Cargo.toml3
-rw-r--r--src/gemini_to_html.rs11
2 files changed, 9 insertions, 5 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 7a0573f..a2ed987 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!("<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>"));