From 6aa4215cd51a2816fee3d60a844a7148664205b7 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Sat, 1 Feb 2025 17:48:27 +1300 Subject: Support vertical borders in tables The latest version of the markdown library includes support for a new vertical-border syntax in tables. When a table has a double-thickness pipe border between two columns in the markdown, each and cell in the column on the left side of the border is given the class 'border'. --- src/generate_html.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/generate_html.rs') diff --git a/src/generate_html.rs b/src/generate_html.rs index 8f2ae62..8490379 100644 --- a/src/generate_html.rs +++ b/src/generate_html.rs @@ -223,7 +223,10 @@ pub fn document_to_html(document: &MarkdownDocument, page: &Page, website: &Webs Block::Table(table) => wrap!("div", "class='table'", wrap!("table", { wrap!("thead", wrap!("tr", for column in &table.columns { - tag!("th", column.name); + match column.border_right { + true => tag!("th", column.name, "class='border'"), + false => tag!("th", column.name), + } }) ); for section in &table.sections { @@ -235,19 +238,21 @@ pub fn document_to_html(document: &MarkdownDocument, page: &Page, website: &Webs "No" => "✗", other => other, }; - let align = match text { + 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_raw.as_str()) { + class.push_str(" dim"); }; - let class = match ["No", "--", "0"].contains(&text_raw.as_str()) { - true => format!("{align} dim"), - false => format!("{align}"), - }; - html!("{}", class, text); + if column.border_right { + class.push_str(" border"); + } + html!("{text}"); }) }) }; -- cgit v1.2.3-70-g09d2