diff options
Diffstat (limited to 'code/src/main.rs')
-rw-r--r-- | code/src/main.rs | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/code/src/main.rs b/code/src/main.rs index 09ce3d8..bbc0e89 100644 --- a/code/src/main.rs +++ b/code/src/main.rs @@ -6,7 +6,7 @@ use std::{ use clap::{Parser, Subcommand}; use laby::{html, internal::Buffer, iter, li, raw, ul, Render}; -use markdown::{Block, Span}; +use markdown::{Block, ListItem, Span}; #[derive(Parser)] struct Args { @@ -50,7 +50,10 @@ fn write_output(t: &Option<String>, o: String) { fn scaffold(title: String, body: impl Render) -> impl Render { html!( - head!(title!(title)), + head!( + link!(rel = "stylesheet", href = "./style.css"), + title!(title) + ), body!( nav!(h2!("metamuffin's blog"), a!(href = "./index.html", "index")), article!(body) @@ -97,7 +100,7 @@ fn span_to_html(ss: Vec<Span>) -> String { out += match s { Span::Break => format!("<br/>"), Span::Text(t) => escape(&t), - Span::Code(c) => format!("<pre><code>{}</code></pre>", escape(&c)), + Span::Code(c) => format!("<code>{}</code>", escape(&c)), Span::Link(text, url, _) => { format!("<a href=\"{}\">{}</a>", escape(&url), escape(&text)) } @@ -119,10 +122,36 @@ fn blocks_to_html(blocks: Vec<Block>) -> String { markdown::Block::Paragraph(p) => format!("<p>{}</p>", span_to_html(p)), markdown::Block::Blockquote(q) => format!("<quote>{}</quote>", blocks_to_html(q)), markdown::Block::CodeBlock(_syntax, content) => { - format!("<pre><code>{}</code></pre>", escape(&content)) // TODO syntax highlighting + format!("<code><pre>{}</pre></code>", escape(&content)) // TODO syntax highlighting + } + markdown::Block::OrderedList(els, _) => format!( + "<ol>{}</ol>", + els.into_iter() + .map(|e| format!( + "<li>{}</li>", + match e { + ListItem::Simple(s) => span_to_html(s), + ListItem::Paragraph(b) => blocks_to_html(b), + } + )) + .collect::<Vec<_>>() + .join("") + ), + markdown::Block::UnorderedList(els) => { + format!( + "<ul>{}</ul>", + els.into_iter() + .map(|e| format!( + "<li>{}</li>", + match e { + ListItem::Simple(s) => span_to_html(s), + ListItem::Paragraph(b) => blocks_to_html(b), + } + )) + .collect::<Vec<_>>() + .join("") + ) } - markdown::Block::OrderedList(_, _) => todo!(), - markdown::Block::UnorderedList(_) => todo!(), markdown::Block::Raw(r) => r, markdown::Block::Hr => format!("<hr/>"), } |