summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/generate_html.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/generate_html.rs b/src/generate_html.rs
index c0b26f6..0460cf7 100644
--- a/src/generate_html.rs
+++ b/src/generate_html.rs
@@ -140,16 +140,19 @@ pub fn document_to_html(document: &MarkdownDocument, page: &Page, website: &Webs
for block in &document.blocks {
match block {
Block::Heading { level, line } => {
+ if let Level::Heading1 = level {
+ html!("</article>");
+ html!("<article>");
+ };
let id = make_url_safe(strip_appendix(&line.to_string()));
- match level {
- Level::Heading1 => {
- html!("</article>");
- html!("<article>");
- tag!("h1", line, format!("id='{id}'"))
- }
- Level::Heading2 => tag!("h2", line, format!("id='{id}'")),
- Level::Heading3 => tag!("h3", line, format!("id='{id}'")),
- }
+ let heading_tag = match level {
+ Level::Heading1 => "h1",
+ Level::Heading2 => "h2",
+ Level::Heading3 => "h3",
+ };
+ wrap!(heading_tag, format!("id='{id}'"), {
+ tag!("a", line, format!("href='#{id}'"));
+ });
}
Block::Paragraph(line) => tag!("p", line),
Block::Math(content) => html!("<div class='math'>{}</div>", sanitize_text(content, false)),