diff options
Diffstat (limited to 'src/generate_html.rs')
-rw-r--r-- | src/generate_html.rs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/generate_html.rs b/src/generate_html.rs index d48e3fe..129e2dd 100644 --- a/src/generate_html.rs +++ b/src/generate_html.rs @@ -124,21 +124,32 @@ pub fn document_to_html(document: &MarkdownDocument, page: &Page, website: &Webs let mut depth = 0; let mut prev = '\0'; let mut output = String::new(); + let mut class = String::new(); for c in line_to_html!(line).chars() { output.push(c); if c == '<' { depth += 1; } else if c == '/' && prev == '<' { - depth -= 2; + depth -= 2; // 2 because prev was a '<' as well. } else if c == ':' && depth == 0 { - output.pop(); output.push_str("<br>"); depth += 99; + output.pop(); output.push_str("<br>"); + class.push_str("extended"); depth += 99; } prev = c; } - match output.contains("<br>") { - true => html!("<li class='extended'>{output}</li>"), - false => html!("<li>{output}</li>"), + // Replace a leading checkbox with a real checkbox. + if let Some(stripped) = output.strip_prefix("<code>[ ]</code>") { + output = format!("<input type='checkbox' disabled>{stripped}"); + class.push_str(" checkbox"); + } else if let Some(stripped) = output.strip_prefix("<code>[x]</code>") { + output = format!("<input type='checkbox' disabled checked>{stripped}"); + class.push_str(" checkbox"); + } else if let Some(stripped) = output.strip_prefix("<code>[X]</code>") { + output = format!("<input type='checkbox' disabled checked>{stripped}"); + class.push_str(" checkbox"); } + let class = class.trim(); + html!("<li class='{class}'>{output}</li>") }), Block::Note(lines) => wrap!("aside", for line in lines { tag!("p", line) }), Block::Embedded { label, path } => match path.rsplit_once('.') { |