Fix md2gemtext convert

master
kirbylife 2024-08-07 01:19:18 -06:00
parent f843d89b74
commit 0f30612b8b
4 changed files with 9 additions and 36 deletions

View File

@ -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"

View File

@ -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<dyn std::error::Error>> {
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("<pre>", "```")
.replace("</pre>", "```");
.replace("</pre>", "```")
.replace("<b>", "")
.replace("</b>", "");
let content = md2gemtext::convert(&content);
context.insert("header", &gen_title());
context.insert("title", &post.title);

View File

@ -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<String> = 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
}

View File

@ -4,4 +4,4 @@
# {{ title }}
Publicado el: {{ created_at | date(format="%Y-%m-%d") }}
{{ content | striptags }}
{{ content }}