diff --git a/src/markdown.rs b/src/markdown.rs index 21793bc..b82ef0e 100644 --- a/src/markdown.rs +++ b/src/markdown.rs @@ -1,7 +1,9 @@ +use pulldown_cmark::{ + BlockQuoteKind, CodeBlockKind, CowStr, Event, LinkType, Options, Parser, Tag, TagEnd, + TextMergeStream, +}; use syntect::highlighting::ThemeSet; use syntect::parsing::SyntaxSet; -use pulldown_cmark::{CodeBlockKind, BlockQuoteKind, Event, Options, Parser, Tag, TagEnd, TextMergeStream, CowStr, LinkType}; - pub fn markdown_to_html(markdown: &str, ss: &SyntaxSet, ts: &ThemeSet, _file_path: &str) -> String { let mut options = Options::empty(); @@ -10,8 +12,6 @@ pub fn markdown_to_html(markdown: &str, ss: &SyntaxSet, ts: &ThemeSet, _file_pat options.insert(Options::ENABLE_STRIKETHROUGH); options.insert(Options::ENABLE_TASKLISTS); options.insert(Options::ENABLE_HEADING_ATTRIBUTES); - options.insert(Options::ENABLE_DEFINITION_LIST); - options.insert(Options::ENABLE_MATH); options.insert(Options::ENABLE_GFM); let mut in_code_block = false; @@ -29,40 +29,45 @@ pub fn markdown_to_html(markdown: &str, ss: &SyntaxSet, ts: &ThemeSet, _file_pat code_content.clear(); } html_output.push_str(render_start_tag(tag).as_str()); - }, + } Event::End(tag) => { if let TagEnd::CodeBlock = tag { in_code_block = false; - html_output.push_str(escape_html(code_content.as_str()).as_str()); + html_output.push_str(escape_html(&code_content).as_str()); } html_output.push_str(render_end_tag(tag).as_str()); - - }, + } Event::Text(text) => { if in_code_block { code_content.push_str(&text); } else { html_output.push_str(&escape_html(&text)); } - }, - Event::TaskListMarker(checked) => { - if checked { - html_output.push_str(""); - } else { - html_output.push_str(""); - } - }, + } + Event::TaskListMarker(true) => { + html_output.push_str(""); + } + Event::TaskListMarker(false) => { + html_output.push_str(""); + } Event::Code(code) => { html_output.push_str(format!("{}", escape_html(&code)).as_str()); - }, - Event::SoftBreak => html_output.push_str(""), + } + Event::SoftBreak => html_output.push_str(" "), + Event::HardBreak => html_output.push_str("
"), + + Event::Html(html) => html_output.push_str(&html), Event::Rule => html_output.push_str("
"), - Event::InlineHtml(_) => (), - Event::Html(_) => (), + Event::FootnoteReference(fref) => html_output.push_str(&format!( + "", + fref, fref + )), - other => println!("[*] Event {:?}", other), + Event::InlineHtml(_) => (), + Event::InlineMath(_) => (), + Event::DisplayMath(_) => (), } } @@ -72,12 +77,12 @@ pub fn markdown_to_html(markdown: &str, ss: &SyntaxSet, ts: &ThemeSet, _file_pat fn render_start_tag(tag: Tag<'_>) -> String { let mut output = String::new(); match tag { - Tag::Heading{level, ..} => { + Tag::Heading { level, .. } => { output.push_str(format!("<{level}>").as_str()); - }, + } Tag::Strikethrough => { output.push_str(""); - }, + } Tag::List(Some(_)) => output.push_str("
    "), Tag::List(None) => output.push_str("