From bde6205cd1b268094460c90ccfb7610e52be5dc1 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 29 Aug 2022 17:26:42 +0200 Subject: test --- code/src/main.rs | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'code/src') 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, 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) -> String { out += match s { Span::Break => format!("
"), Span::Text(t) => escape(&t), - Span::Code(c) => format!("
{}
", escape(&c)), + Span::Code(c) => format!("{}", escape(&c)), Span::Link(text, url, _) => { format!("{}", escape(&url), escape(&text)) } @@ -119,10 +122,36 @@ fn blocks_to_html(blocks: Vec) -> String { markdown::Block::Paragraph(p) => format!("

{}

", span_to_html(p)), markdown::Block::Blockquote(q) => format!("{}", blocks_to_html(q)), markdown::Block::CodeBlock(_syntax, content) => { - format!("
{}
", escape(&content)) // TODO syntax highlighting + format!("
{}
", escape(&content)) // TODO syntax highlighting + } + markdown::Block::OrderedList(els, _) => format!( + "
    {}
", + els.into_iter() + .map(|e| format!( + "
  • {}
  • ", + match e { + ListItem::Simple(s) => span_to_html(s), + ListItem::Paragraph(b) => blocks_to_html(b), + } + )) + .collect::>() + .join("") + ), + markdown::Block::UnorderedList(els) => { + format!( + "
      {}
    ", + els.into_iter() + .map(|e| format!( + "
  • {}
  • ", + match e { + ListItem::Simple(s) => span_to_html(s), + ListItem::Paragraph(b) => blocks_to_html(b), + } + )) + .collect::>() + .join("") + ) } - markdown::Block::OrderedList(_, _) => todo!(), - markdown::Block::UnorderedList(_) => todo!(), markdown::Block::Raw(r) => r, markdown::Block::Hr => format!("
    "), } -- cgit v1.2.3-70-g09d2