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
@@ -5,7 +5,8 @@ use crate::{
|
||||
document::{
|
||||
Block, ColumnAlignment, DocumentModel, EquationNumber, InlineBox, InlineBoxAlign,
|
||||
ListBlock, ListItem, PageMargins, PageSize, PageStyleKind, PageStyleOverride,
|
||||
ParagraphAlignment, ParsedDocument, RuleBox, Run, TitleStyle, UnresolvedReference,
|
||||
ParagraphAlignment, ParsedDocument, RuleBox, Run, TableCellStyle, TableRule, TitleStyle,
|
||||
UnresolvedReference,
|
||||
},
|
||||
expanded,
|
||||
math_expr::*,
|
||||
@@ -47,7 +48,10 @@ struct TableBuilder {
|
||||
cell: Vec<Run>,
|
||||
caption: Option<Vec<Run>>,
|
||||
alignments: Vec<ColumnAlignment>,
|
||||
rules: Vec<usize>,
|
||||
rules: Vec<TableRule>,
|
||||
cell_styles: Vec<Vec<TableCellStyle>>,
|
||||
row_styles: Vec<TableCellStyle>,
|
||||
pending_cell_style: Option<TableCellStyle>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -1115,9 +1119,33 @@ impl Parser {
|
||||
}
|
||||
expanded::FrontendEventKind::ListItem => self.start_list_item(),
|
||||
expanded::FrontendEventKind::TableCell => self.finish_table_cell(),
|
||||
expanded::FrontendEventKind::TableCellSpan { colspan, alignment } => {
|
||||
if let Some(table) = &mut self.table {
|
||||
table.pending_cell_style = Some(TableCellStyle {
|
||||
colspan: (*colspan).max(1),
|
||||
alignment: *alignment,
|
||||
});
|
||||
}
|
||||
}
|
||||
expanded::FrontendEventKind::TableRule => {
|
||||
if let Some(table) = &mut self.table {
|
||||
table.rules.push(table.rows.len());
|
||||
table.rules.push(TableRule::full(table.rows.len()));
|
||||
}
|
||||
}
|
||||
expanded::FrontendEventKind::TableRuleRange {
|
||||
start_column,
|
||||
end_column,
|
||||
trim_left,
|
||||
trim_right,
|
||||
} => {
|
||||
if let Some(table) = &mut self.table {
|
||||
table.rules.push(TableRule {
|
||||
row: table.rows.len(),
|
||||
start_column: *start_column,
|
||||
end_column: *end_column,
|
||||
trim_left: *trim_left,
|
||||
trim_right: *trim_right,
|
||||
});
|
||||
}
|
||||
}
|
||||
expanded::FrontendEventKind::DisplayMath {
|
||||
@@ -2141,6 +2169,8 @@ impl Parser {
|
||||
fn finish_table_cell(&mut self) {
|
||||
if let Some(table) = &mut self.table {
|
||||
trim_run_end(&mut table.cell);
|
||||
let style = table.pending_cell_style.take().unwrap_or_default();
|
||||
table.row_styles.push(style);
|
||||
table.row.push(std::mem::take(&mut table.cell));
|
||||
}
|
||||
}
|
||||
@@ -2151,6 +2181,9 @@ impl Parser {
|
||||
&& !table.row.is_empty()
|
||||
{
|
||||
table.rows.push(std::mem::take(&mut table.row));
|
||||
table
|
||||
.cell_styles
|
||||
.push(std::mem::take(&mut table.row_styles));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2172,6 +2205,7 @@ impl Parser {
|
||||
caption,
|
||||
alignments: table.alignments,
|
||||
rules: table.rules,
|
||||
cell_styles: table.cell_styles,
|
||||
placement: self.table_placement.clone(),
|
||||
});
|
||||
if self.table_active {
|
||||
|
||||
Reference in new issue
Block a user