summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2025-02-01 17:48:27 +1300
committerBen Bridle <ben@derelict.engineering>2025-02-01 17:48:36 +1300
commit6aa4215cd51a2816fee3d60a844a7148664205b7 (patch)
treedfcd02cbf254bddfb33a7ae34d079019b2930e4c /src
parentdfd8d985da474bf4e2c080a1de36499eb6e13abb (diff)
downloadtoaster-6aa4215cd51a2816fee3d60a844a7148664205b7.zip
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 <th> and <td> cell in the column on the left side of the border is given the class 'border'.
Diffstat (limited to 'src')
-rw-r--r--src/generate_html.rs19
1 files changed, 12 insertions, 7 deletions
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!("<td class='{}'>{}</td>", class, text);
+ if column.border_right {
+ class.push_str(" border");
+ }
+ html!("<td class='{class}'>{text}</td>");
})
})
};