Parse hline rows in halign sources

This commit is contained in:
gloamxun committed 2026-10-20 13:12:02 +08:00
1 parent abffe4e7bc
commit 7250f7f5ca
2 files changed
+25 -1

No files matched your search

+24
View File
@@ -222,6 +222,21 @@ impl Unit {
if raw_row.trim().is_empty() {
continue;
}
let mut raw_row = raw_row.trim();
let mut rule = false;
if let Some(rest) = raw_row.strip_prefix(r"\hline") {
rule = true;
raw_row = rest.trim();
}
if rule {
rows.push(HalignRow {
cells: Vec::new(),
rule: true,
});
}
if raw_row.is_empty() {
continue;
}
let mut cells = Vec::new();
for raw_cell in raw_row.split('&') {
let mut text = raw_cell.trim().to_owned();
@@ -1136,6 +1151,15 @@ mod tests {
assert_eq!(halign.cell_box(2, 0), Some((30, 110)));
}
#[test]
fn halign_source_parses_hline_rules() {
let unit = Unit::halign_from_source(1, r"A & B \\ \hline C & D", 2, 10);
let VerticalItem::Halign(halign) = &unit.items[0] else {
panic!("expected halign");
};
assert!(halign.rows.iter().any(|row| row.rule));
assert_eq!(halign.rows.last().unwrap().cells.len(), 2);
}
#[test]
fn halign_source_parses_omit_span_and_multispan() {
let unit = Unit::halign_from_source(1, r"A & B \\ \omit C & \multispan{2} D", 3, 10);
+1 -1
View File
@@ -190,4 +190,4 @@ editing. Three M1 tests cover glue-based line breaking, paragraph indentation an
empty paragraphs.
`Unit::halign_from_source` parses `&` rows, `\\` separators, `\omit`,
`\span` and `\multispan{n}` into `HalignCell.span` values.
`\span`, `\multispan{n}` and `\hline` rule rows.