From 0f30612b8b88befd6bf693aba810c17bb23202c4 Mon Sep 17 00:00:00 2001 From: kirbylife Date: Wed, 7 Aug 2024 01:19:18 -0600 Subject: [PATCH] Fix md2gemtext convert --- Cargo.toml | 2 +- src/bin/gemini.rs | 10 +++++++--- src/misc.rs | 31 ------------------------------- templates/gemini/post.gmi.tera | 2 +- 4 files changed, 9 insertions(+), 36 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c7fac3c..ad2eaa2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,5 +18,5 @@ isbot = "0.1.3" once_cell = "1.19.0" windmark = { version = "0.3.10", features = ["response-macros", "logger"] } tokio = { version = "1.26.0", features = ["full"] } -md2gemtext = "0.1.0" +md2gemtext = { git = "https://git.kirbylife.dev/kirbylife/md2gemtext" } glob = "0.3.1" diff --git a/src/bin/gemini.rs b/src/bin/gemini.rs index 3c42cfa..b3e2ed8 100644 --- a/src/bin/gemini.rs +++ b/src/bin/gemini.rs @@ -2,7 +2,7 @@ use codigocomentado::*; use controllers::posts; use dotenv::dotenv; -use misc::{gen_title, replace_tables}; +use misc::gen_title; use tera::Tera; use tokio::sync::OnceCell; @@ -64,9 +64,13 @@ async fn main() -> Result<(), Box> { let result = match posts::get_post(id) { Ok(post) => { let mut context = tera::Context::new(); - let content = replace_tables(post.content) + let content = post + .content .replace("
", "```")
-                            .replace("
", "```"); + .replace("", "```") + .replace("", "") + .replace("", ""); + let content = md2gemtext::convert(&content); context.insert("header", &gen_title()); context.insert("title", &post.title); diff --git a/src/misc.rs b/src/misc.rs index 914294a..9de44f0 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -81,34 +81,3 @@ pub fn ascii_table(raw_table: String) -> String { format!("```\n{}\n```\n", result) } - -pub fn replace_tables(text: String) -> String { - let mut result = String::new(); - let mut table: Option = None; - let mut is_code = false; - - for line in text.lines() { - if line.starts_with('|') & !is_code { - if table.is_none() { - table = Some(String::new()); - } - if let Some(ref mut tab) = table { - tab.push_str(&format!("{}\n", line)); - } - } else { - let temp = match table { - Some(ref tab) => { - println!("raw:\n{}", tab); - let new_table = ascii_table(tab.to_string()); - println!("formated:\n{}", new_table); - table = None; - new_table - } - None => line.to_string(), - }; - result.push_str(&temp); - result.push('\n'); - } - } - result -} diff --git a/templates/gemini/post.gmi.tera b/templates/gemini/post.gmi.tera index b6829bd..3005d62 100644 --- a/templates/gemini/post.gmi.tera +++ b/templates/gemini/post.gmi.tera @@ -4,4 +4,4 @@ # {{ title }} Publicado el: {{ created_at | date(format="%Y-%m-%d") }} -{{ content | striptags }} +{{ content }}