Skip to content

Commit fb948be

Browse files
committed
fix table writing inconsistency with empty headers
1 parent 0b1ef53 commit fb948be

File tree

2 files changed

+26
-2
lines changed
  • crates/quarto-markdown-pandoc

2 files changed

+26
-2
lines changed

crates/quarto-markdown-pandoc/src/pandoc/treesitter_utils/pipe_table.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,27 @@ pub fn process_pipe_table(
180180
panic!("Unexpected node in pipe_table: {}", node);
181181
}
182182
}
183+
184+
// Check if header row has all empty cells
185+
let header_is_empty = header.as_ref().map_or(false, |h| {
186+
h.cells.iter().all(|cell| {
187+
cell.content.iter().all(|block| {
188+
if let Block::Plain(plain) = block {
189+
plain.content.is_empty()
190+
} else {
191+
false
192+
}
193+
})
194+
})
195+
});
196+
197+
// If header is empty, discard it and use empty thead
198+
let (thead_rows, body_rows) = if header_is_empty {
199+
(vec![], rows)
200+
} else {
201+
(vec![header.unwrap()], rows)
202+
};
203+
183204
PandocNativeIntermediate::IntermediateBlock(Block::Table(Table {
184205
attr,
185206
caption: Caption {
@@ -189,13 +210,13 @@ pub fn process_pipe_table(
189210
colspec,
190211
head: TableHead {
191212
attr: empty_attr(),
192-
rows: vec![header.unwrap()],
213+
rows: thead_rows,
193214
},
194215
bodies: vec![TableBody {
195216
attr: empty_attr(),
196217
rowhead_columns: 0,
197218
head: vec![],
198-
body: rows,
219+
body: body_rows,
199220
}],
200221
foot: TableFoot {
201222
attr: empty_attr(),
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| | |
2+
|-|-|
3+
|a|b|

0 commit comments

Comments
 (0)