diff --git a/doc-generator/src/generator/emphasis.rs b/doc-generator/src/generator/emphasis.rs new file mode 100644 index 0000000..53c4e9f --- /dev/null +++ b/doc-generator/src/generator/emphasis.rs @@ -0,0 +1,17 @@ +use markdown::mdast::Emphasis; + +use crate::utils; + +use super::Printable; + +impl Printable for Emphasis { + fn to_html(&self) -> String { + let html = utils::collect_children_html(&self.children); + + format!("{}", html) + } + + fn get_text(&self) -> String { + utils::collect_children_text(&self.children) + } +} diff --git a/doc-generator/src/generator/list.rs b/doc-generator/src/generator/list.rs new file mode 100644 index 0000000..97851d9 --- /dev/null +++ b/doc-generator/src/generator/list.rs @@ -0,0 +1,43 @@ +use markdown::mdast::{List, ListItem, Node}; + +use crate::utils; + +use super::Printable; + +impl Printable for List { + fn to_html(&self) -> String { + let mut result = Vec::::new(); + + for node in &self.children { + result.push(format!("
  • {}
  • ", node.to_html())) + } + + let str: String = result.into_iter().collect(); + + format!("
      {}
    ", str) + } + + fn get_text(&self) -> String { + panic!("List cannot return it's raw text") + } +} + +impl Printable for ListItem { + fn to_html(&self) -> String { + let mut result = Vec::::new(); + + for node in &self.children { + let s = match node { + Node::Paragraph(p) => utils::collect_children_html(&p.children), + _ => panic!("A thing other than Paragraph inside ListItem (?)"), + }; + result.push(format!("{}", s)) + } + + result.into_iter().collect() + } + + fn get_text(&self) -> String { + panic!("ListItem cannot return it's raw text") + } +} diff --git a/doc-generator/src/generator/mod.rs b/doc-generator/src/generator/mod.rs index ea80ef2..a07ddc7 100644 --- a/doc-generator/src/generator/mod.rs +++ b/doc-generator/src/generator/mod.rs @@ -1,8 +1,10 @@ use markdown::mdast::Node; mod code; +mod emphasis; mod heading; mod inline_code; +mod list; mod paragraph; mod root; mod strong; @@ -25,7 +27,13 @@ impl Printable for Node { Node::Code(c) => c.to_html(), Node::Html(h) => h.value.clone(), Node::Strong(s) => s.to_html(), - _ => format!("
    Not implemented

    {:?}", self), + Node::Emphasis(e) => e.to_html(), + Node::List(l) => l.to_html(), + Node::ListItem(l) => l.to_html(), + _ => format!( + "
    Not implemented
    {:?}
    ", + self + ), } } @@ -40,7 +48,77 @@ impl Printable for Node { Node::Code(c) => c.get_text(), Node::Html(_) => panic!("Html cannot return its raw text"), Node::Strong(s) => s.get_text(), + Node::Emphasis(e) => e.get_text(), + Node::List(l) => l.get_text(), + Node::ListItem(l) => l.get_text(), _ => String::from(""), } } } + +/* +List { + children: [ + ListItem { + children: [ + Paragraph { + children: [ + InlineCode { + value: "\\\"", position: Some(88:3-88:7 (1728-1732)) } + ], + position: Some(88:3-88:7 (1728-1732)) } + ], + position: Some(88:1-89:1 (1726-1733)), spread: false, checked: None } + , ListItem { + children: [ + Paragraph { + children: [ + InlineCode { + value: "\\\\", position: Some(90:3-90:7 (1736-1740)) } + ], + position: Some(90:3-90:7 (1736-1740)) } + ], + position: Some(90:1-90:7 (1734-1740)), spread: false, checked: None } + , ListItem { + children: [ + Paragraph { + children: [ + InlineCode { + value: "\\n", position: Some(91:3-91:7 (1743-1747)) } + ], + position: Some(91:3-91:7 (1743-1747)) } + ], + position: Some(91:1-91:7 (1741-1747)), spread: false, checked: None } + , ListItem { + children: [ + Paragraph { + children: [ + InlineCode { + value: "\\r", position: Some(92:3-92:7 (1750-1754)) } + ], + position: Some(92:3-92:7 (1750-1754)) } + ], + position: Some(92:1-92:7 (1748-1754)), spread: false, checked: None } + , ListItem { + children: [ + Paragraph { + children: [ + InlineCode { + value: "\\t", position: Some(93:3-93:7 (1757-1761)) } + ], + position: Some(93:3-93:7 (1757-1761)) } + ], + position: Some(93:1-93:7 (1755-1761)), spread: false, checked: None } + , ListItem { + children: [ + Paragraph { + children: [ + InlineCode { + value: "\\b", position: Some(94:3-94:7 (1764-1768)) } + ], + position: Some(94:3-94:7 (1764-1768)) } + ], + position: Some(94:1-95:1 (1762-1769)), spread: false, checked: None } + ], + position: Some(88:1-95:1 (1726-1769)), ordered: false, start: None, spread: true } +*/