{}
", sanitize_text(content, false)),
Block::List(lines) => wrap!("ul", for line in lines {
// Insert a tag directly after the first untagged colon. 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; // 2 because prev was a '<' as well. } else if c == ' ' && prev == ':' && depth == 0 { output.pop(); output.pop(); output.push_str("
"); class.push_str("extended"); depth += 99; } prev = c; } // Replace a leading checkbox with a real checkbox. if let Some(stripped) = output.strip_prefix("
[ ]") {
output = format!("{stripped}");
class.push_str(" checkbox");
} else if let Some(stripped) = output.strip_prefix("[x]") {
output = format!("{stripped}");
class.push_str(" checkbox");
} else if let Some(stripped) = output.strip_prefix("[X]") {
output = format!("{stripped}");
class.push_str(" checkbox");
}else if let Some(stripped) = output.strip_prefix("[ ]") {
output = format!("{stripped}");
class.push_str(" checkbox");
} else if let Some(stripped) = output.strip_prefix("[x]") {
output = format!("{stripped}");
class.push_str(" checkbox");
} else if let Some(stripped) = output.strip_prefix("[X]") {
output = format!("{stripped}");
class.push_str(" checkbox");
}
let class = class.trim();
match class.is_empty() {
true => html!("{content}
")
},
"embed-html" => html!("{content}"),
"embed-css" => wrap!("style", html!("{content}")),
"embed-javascript"|"embed-js" => wrap!("script", html!("{content}")),
"embed-html-head"|"override-html-head"|"override-title" => (),
"hidden"|"todo" => (),
"poem" => wrap!("div", "class='poem'", for line in content.lines() {
let line = line.trim_end();
match line.is_empty() {
true => html!(""), false => html!("
{}
", sanitize_text(line, true)), } }), "recipe" => { let recipe = Recipe::parse(content); html!("- ");
for ingredient in recipe.ingredients { html!("
- {ingredient} ") } html!("
"); for paragraph in recipe.process { html!("
{paragraph}
") } html!("{label}
") } else { warn!("Gallery on page {from:?} references nonexistent image {file_name:?}"); warn!("Gallery-nav on page {from:?} references nonexistent image {file_name:?}"); } } else { warn!("Gallery-nav on page {from:?} has line without a '::' separator"); } }), _ => wrap!("pre", format!("class='{language}'"), { if let Some(i) = website.config.languages.get(language) { let mut source = String::new(); let highlighter = &website.config.highlighters[*i]; for span in highlighter.highlight(content) { if span.tag.is_empty() { source.push_str(&sanitize_text(&span.text, false)); } else { source.push_str(&format!("", span.tag.to_lowercase())); source.push_str(&sanitize_text(&span.text, false)); source.push_str(""); } } html!("{source}"); } else { html!("{}", sanitize_text(content, false)) } }) } } Block::Break => html!(""), Block::Table(table) => wrap!("div", "class='table'", wrap!("table", { wrap!("thead", wrap!("tr", for column in &table.columns { match column.border_right { true => tag!("th", column.name, "class='border'"), false => tag!("th", column.name), } }) ); for section in &table.sections { wrap!("tbody", for row in section { wrap!("tr", for (column, cell) in std::iter::zip(&table.columns, row) { let text_raw = line_to_html!(cell).trim().to_string(); let text_cmp = text_raw.to_lowercase().to_string(); let text = match text_cmp.as_str() { "yes" => "✓", "no" => "✗", _ => &text_raw, }; let mut class = match text { "--" => "c", _ => match column.alignment { Alignment::Left => "l", Alignment::Center => "c", Alignment::Right => "r", }, }.to_string(); if ["no", "--", "0"].contains(&text_cmp.as_str()) { class.push_str(" dim"); }; if column.border_right { class.push_str(" border"); } html!("
{text}")) }
Token::Math(text) => {
let text = &sanitize_text(text, false); html.push_str(&format!("{text}")) }
Token::InternalLink{ label: link_label, path } => {
let ParsedLink { path, class, mut label } = parse_internal_link(path, page, website, prefix);
if !link_label.is_empty() {
label = link_label.to_string();
}
html.push_str(&format!("{label}"))
}
Token::ExternalLink { label, path } => {
let ParsedLink { path, class, label } = parse_external_link(label, path, page, website);
html.push_str(&format!("{label}"));
}
}
}
return html;
}
struct ParsedLink {
pub path: String,
pub label: String,
pub class: &'static str,
}
fn parse_internal_link(name: &str, page: &Page, website: &Website, prefix: &Option