From c3f2aa27e2c72e0e53451e3aa8046a1558265a63 Mon Sep 17 00:00:00 2001 From: Araozu Date: Thu, 30 Mar 2023 16:19:48 -0500 Subject: [PATCH] [Web] Generation of h1-5, p, hr --- doc-generator/src/generator/heading.rs | 2 +- doc-generator/src/generator/mod.rs | 5 +++++ doc-generator/src/generator/paragraph.rs | 21 +++++++++++++++++++++ doc-generator/static/styles/global.css | 17 +++++++++++++---- doc-generator/static/template.html | 2 +- 5 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 doc-generator/src/generator/paragraph.rs diff --git a/doc-generator/src/generator/heading.rs b/doc-generator/src/generator/heading.rs index 81c62f1..aacda2f 100644 --- a/doc-generator/src/generator/heading.rs +++ b/doc-generator/src/generator/heading.rs @@ -18,7 +18,7 @@ impl Printable for Heading { let html_fragment_text = utils::to_html_fragment(&self.get_text()); format!( - "{}", + "{}", self.depth, html_fragment_text, html_fragment_text, text, self.depth ) } else { diff --git a/doc-generator/src/generator/mod.rs b/doc-generator/src/generator/mod.rs index 16f9c52..2dc9be3 100644 --- a/doc-generator/src/generator/mod.rs +++ b/doc-generator/src/generator/mod.rs @@ -3,6 +3,7 @@ use markdown::mdast::Node; mod heading; mod root; mod text; +mod paragraph; pub trait Printable { fn to_html(&self) -> String; @@ -15,6 +16,8 @@ impl Printable for Node { 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::ThematicBreak(_) => String::from("
"), _ => format!("Not implemented
{:?}", self), } } @@ -24,6 +27,8 @@ impl Printable for Node { Node::Root(root) => root.get_text(), Node::Heading(heading) => heading.get_text(), Node::Text(text) => text.get_text(), + Node::Paragraph(p) => p.get_text(), + Node::ThematicBreak(_) => panic!("
cannot return its raw text"), _ => String::from(""), } } diff --git a/doc-generator/src/generator/paragraph.rs b/doc-generator/src/generator/paragraph.rs new file mode 100644 index 0000000..49d744d --- /dev/null +++ b/doc-generator/src/generator/paragraph.rs @@ -0,0 +1,21 @@ +use markdown::mdast::Paragraph; + +use super::Printable; + +impl Printable for Paragraph { + fn to_html(&self) -> String { + let mut result = Vec::::new(); + + for node in &self.children { + result.push(node.to_html()) + } + + let text: String = result.into_iter().collect(); + + format!("

{}

", text) + } + + fn get_text(&self) -> String { + panic!("Paragraph cannot return its raw text") + } +} \ No newline at end of file diff --git a/doc-generator/static/styles/global.css b/doc-generator/static/styles/global.css index 1ebb250..a416abf 100644 --- a/doc-generator/static/styles/global.css +++ b/doc-generator/static/styles/global.css @@ -185,10 +185,6 @@ code, pre { margin-bottom: 1.5rem; } -.marked h2:target { - text-decoration: underline; - text-decoration-color: var(--c5); -} .marked h3 { font-size: 1.75rem; @@ -197,9 +193,11 @@ code, pre { margin-bottom: 1.25rem; text-decoration: underline; + /* position: sticky; top: 0; background-color: var(--bg-color); + */ } .marked h4 { @@ -302,3 +300,14 @@ code, pre { transform: scale(1); } } + +/* Used by headers generated at src/generator/heading.rs */ +.heading-linked :hover::after{ + color: var(--c1); + content: "#"; + display: inline-block; + font-size: 0.7em; + line-height: 1; + margin-left: 4px; + text-decoration: none; +} diff --git a/doc-generator/static/template.html b/doc-generator/static/template.html index f724acd..9469006 100644 --- a/doc-generator/static/template.html +++ b/doc-generator/static/template.html @@ -16,7 +16,7 @@ -
+
{{markdown}}