Support multicolumn spans and partial table rules
This commit is contained in:
1 parent
ca5cb0b8af
commit
d4e52dc225
13 files changed
+698
-187
No files matched your search
+25
-5
@@ -441,6 +441,7 @@ fn render_html_document(
|
||||
caption,
|
||||
alignments,
|
||||
rules,
|
||||
cell_styles,
|
||||
..
|
||||
} => {
|
||||
html.push_str(&format!(
|
||||
@@ -453,25 +454,44 @@ fn render_html_document(
|
||||
}
|
||||
html.push_str("<tbody>");
|
||||
for (row_index, row) in rows.iter().enumerate() {
|
||||
let rule_class = if rules.contains(&row_index) {
|
||||
let rule_class = if rules.iter().any(|rule| {
|
||||
rule.row == row_index
|
||||
&& rule.start_column == 0
|
||||
&& rule.end_column == usize::MAX
|
||||
}) {
|
||||
" class=\"rule-before\""
|
||||
} else {
|
||||
""
|
||||
};
|
||||
html.push_str(&format!("<tr{rule_class}>"));
|
||||
for (column_index, cell) in row.iter().enumerate() {
|
||||
let alignment = match alignments.get(column_index).copied() {
|
||||
let mut column_index = 0;
|
||||
for (cell_index, cell) in row.iter().enumerate() {
|
||||
let style = cell_styles
|
||||
.get(row_index)
|
||||
.and_then(|styles| styles.get(cell_index));
|
||||
let colspan = style.map(|style| style.colspan.max(1)).unwrap_or(1);
|
||||
let alignment = match style
|
||||
.and_then(|style| style.alignment)
|
||||
.or_else(|| alignments.get(column_index).copied())
|
||||
{
|
||||
Some(ColumnAlignment::Center) => "center",
|
||||
Some(ColumnAlignment::Right) => "right",
|
||||
_ => "left",
|
||||
};
|
||||
html.push_str(&format!("<td style=\"text-align:{alignment}\">"));
|
||||
html.push_str(&format!(
|
||||
"<td colspan=\"{colspan}\" style=\"text-align:{alignment}\">"
|
||||
));
|
||||
html.push_str(&render_html_runs(cell, math_preview.as_ref(), 10));
|
||||
html.push_str("</td>");
|
||||
column_index += colspan;
|
||||
}
|
||||
html.push_str("</tr>");
|
||||
}
|
||||
if rules.contains(&rows.len()) {
|
||||
if rules.iter().any(|rule| {
|
||||
rule.row == rows.len()
|
||||
&& rule.start_column == 0
|
||||
&& rule.end_column == usize::MAX
|
||||
}) {
|
||||
html.push_str("<tr class=\"rule-after\"><td colspan=\"99\"></td></tr>");
|
||||
}
|
||||
html.push_str("</tbody></table>");
|
||||
|
||||
Reference in new issue
Block a user