diff --git a/src/generator/code.rs b/src/generator/code.rs index bfe6bc3..d915ca0 100644 --- a/src/generator/code.rs +++ b/src/generator/code.rs @@ -2,10 +2,12 @@ use markdown::mdast::Code; // use super::highlighter::highlight; +use crate::config::Config; + use super::Printable; impl Printable for Code { - fn to_html(&self) -> String { + fn to_html(&self, _: &Config) -> String { let code = &self.value; // highlight(&self.value); if let Some(lang) = &self.lang { diff --git a/src/generator/emphasis.rs b/src/generator/emphasis.rs index 53c4e9f..0b76af5 100644 --- a/src/generator/emphasis.rs +++ b/src/generator/emphasis.rs @@ -1,12 +1,12 @@ use markdown::mdast::Emphasis; -use crate::utils; +use crate::{utils, config::Config}; use super::Printable; impl Printable for Emphasis { - fn to_html(&self) -> String { - let html = utils::collect_children_html(&self.children); + fn to_html(&self, config: &Config) -> String { + let html = utils::collect_children_html(config, &self.children); format!("{}", html) } diff --git a/src/generator/heading.rs b/src/generator/heading.rs index 44e7409..f5eaadd 100644 --- a/src/generator/heading.rs +++ b/src/generator/heading.rs @@ -1,15 +1,15 @@ use markdown::mdast::Heading; -use crate::utils; +use crate::{utils, config::Config}; use super::Printable; impl Printable for Heading { - fn to_html(&self) -> String { + fn to_html(&self, config: &Config) -> String { let mut result = Vec::::new(); for node in &self.children { - result.push(node.to_html()) + result.push(node.to_html(config)) } let text: String = result.into_iter().collect(); diff --git a/src/generator/inline_code.rs b/src/generator/inline_code.rs index 43e02bf..fee81e3 100644 --- a/src/generator/inline_code.rs +++ b/src/generator/inline_code.rs @@ -1,10 +1,12 @@ use markdown::mdast::InlineCode; +use crate::config::Config; + // use super::highlighter::highlight; use super::Printable; impl Printable for InlineCode { - fn to_html(&self) -> String { + fn to_html(&self, _: &Config) -> String { /* let tokens = misti::tokenize(&self.value); println!("INLINE CODE ==== tokens ====\n\n{:?}\n\n==== code ====\n\n{}\n\n", tokens, self.value); diff --git a/src/generator/list.rs b/src/generator/list.rs index 0a1a161..eec25c0 100644 --- a/src/generator/list.rs +++ b/src/generator/list.rs @@ -1,15 +1,15 @@ use markdown::mdast::{List, ListItem, Node}; -use crate::utils; +use crate::{utils, config::Config}; use super::Printable; impl Printable for List { - fn to_html(&self) -> String { + fn to_html(&self, config: &Config) -> String { let mut result = Vec::::new(); for node in &self.children { - result.push(format!("
  • {}
  • ", node.to_html())) + result.push(format!("
  • {}
  • ", node.to_html(config))) } let str: String = result.into_iter().collect(); @@ -27,12 +27,12 @@ impl Printable for List { } impl Printable for ListItem { - fn to_html(&self) -> String { + fn to_html(&self, config: &Config) -> String { let mut result = Vec::::new(); for node in &self.children { let s = match node { - Node::Paragraph(p) => utils::collect_children_html(&p.children), + Node::Paragraph(p) => utils::collect_children_html(config, &p.children), _ => panic!("A thing other than Paragraph inside ListItem (?)"), }; result.push(format!("{}", s)) diff --git a/src/generator/mod.rs b/src/generator/mod.rs index 9da11ab..1406652 100644 --- a/src/generator/mod.rs +++ b/src/generator/mod.rs @@ -1,5 +1,7 @@ use markdown::mdast::Node; +use crate::config::Config; + mod code; mod emphasis; mod heading; @@ -13,25 +15,25 @@ mod text; // mod highlighter; pub trait Printable { - fn to_html(&self) -> String; + fn to_html(&self, c: &Config) -> String; fn get_text(&self) -> String; } impl Printable for Node { - fn to_html(&self) -> String { + fn to_html(&self, config: &Config) -> String { match self { - Node::Root(root) => root.to_html(), - Node::Heading(heading) => heading.to_html(), - Node::Text(text) => text.to_html(), - Node::Paragraph(p) => p.to_html(), + Node::Root(root) => root.to_html(config), + Node::Heading(heading) => heading.to_html(config), + Node::Text(text) => text.to_html(config), + Node::Paragraph(p) => p.to_html(config), Node::ThematicBreak(_) => String::from("
    "), - Node::InlineCode(i) => i.to_html(), - Node::Code(c) => c.to_html(), + Node::InlineCode(i) => i.to_html(config), + Node::Code(c) => c.to_html(config), Node::Html(h) => h.value.clone(), - Node::Strong(s) => s.to_html(), - Node::Emphasis(e) => e.to_html(), - Node::List(l) => l.to_html(), - Node::ListItem(l) => l.to_html(), + Node::Strong(s) => s.to_html(config), + Node::Emphasis(e) => e.to_html(config), + Node::List(l) => l.to_html(config), + Node::ListItem(l) => l.to_html(config), _ => format!( "
    Not implemented
    {:?}
    ", self diff --git a/src/generator/paragraph.rs b/src/generator/paragraph.rs index fce798f..76a1d2d 100644 --- a/src/generator/paragraph.rs +++ b/src/generator/paragraph.rs @@ -1,13 +1,15 @@ use markdown::mdast::Paragraph; +use crate::config::Config; + use super::Printable; impl Printable for Paragraph { - fn to_html(&self) -> String { + fn to_html(&self, config: &Config) -> String { let mut result = Vec::::new(); for node in &self.children { - result.push(node.to_html()) + result.push(node.to_html(config)) } let text: String = result.into_iter().collect(); diff --git a/src/generator/root.rs b/src/generator/root.rs index e378b2a..b323a69 100644 --- a/src/generator/root.rs +++ b/src/generator/root.rs @@ -1,13 +1,15 @@ use markdown::mdast; +use crate::config::Config; + use super::Printable; impl Printable for mdast::Root { - fn to_html(&self) -> String { + fn to_html(&self, config: &Config) -> String { let mut result = Vec::::new(); for node in &self.children { - result.push(node.to_html()) + result.push(node.to_html(config)) } result.into_iter().collect() diff --git a/src/generator/strong.rs b/src/generator/strong.rs index 287b8a1..84f44b0 100644 --- a/src/generator/strong.rs +++ b/src/generator/strong.rs @@ -1,12 +1,12 @@ use markdown::mdast::Strong; -use crate::utils; +use crate::{utils, config::Config}; use super::Printable; impl Printable for Strong { - fn to_html(&self) -> String { - let text = utils::collect_children_html(&self.children); + fn to_html(&self, config: &Config) -> String { + let text = utils::collect_children_html(config, &self.children); format!("{}", text) } diff --git a/src/generator/text.rs b/src/generator/text.rs index 424a499..d2b32cf 100644 --- a/src/generator/text.rs +++ b/src/generator/text.rs @@ -1,9 +1,11 @@ use markdown::mdast::Text; +use crate::config::{Config}; + use super::Printable; impl Printable for Text { - fn to_html(&self) -> String { + fn to_html(&self, _: &Config) -> String { self.value.clone() } diff --git a/src/pages/md_compiler.rs b/src/pages/md_compiler.rs index 8e8d165..943e3b8 100644 --- a/src/pages/md_compiler.rs +++ b/src/pages/md_compiler.rs @@ -43,7 +43,7 @@ pub fn compile(config: &Config, file: &PathBuf, file_tree_html: &String) { // Compile MD // let md_ast = markdown::to_mdast(&markdown_text, &markdown::ParseOptions::gfm()).unwrap(); - let html_text = md_ast.to_html(); + let html_text = md_ast.to_html(config); let sidebar_html = md_ast.generate_sidebar(); // Read template.html diff --git a/src/utils.rs b/src/utils.rs index 190fd74..286eb69 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -8,11 +8,11 @@ pub fn to_html_fragment(text: &String) -> String { text.clone().replace(" ", "-") } -pub fn collect_children_html(vec: &Vec) -> String { +pub fn collect_children_html(config: &Config, vec: &Vec) -> String { let mut result = Vec::::new(); for node in vec { - result.push(node.to_html()) + result.push(node.to_html(config)) } result.into_iter().collect()