Skip to content

Commit 0b1ef53

Browse files
committed
pipe_table json writer
1 parent 75fce04 commit 0b1ef53

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn process_pipe_table_cell(
104104
) -> PandocNativeIntermediate {
105105
let mut plain_content: Inlines = Vec::new();
106106
let mut table_cell = Cell {
107-
alignment: Alignment::Left,
107+
alignment: Alignment::Default,
108108
col_span: 1,
109109
row_span: 1,
110110
attr: ("".to_string(), vec![], HashMap::new()),
@@ -125,6 +125,16 @@ pub fn process_pipe_table_cell(
125125
);
126126
}
127127
}
128+
129+
// Trim trailing spaces from cell content to match Pandoc behavior
130+
while let Some(last) = plain_content.last() {
131+
if matches!(last, crate::pandoc::inline::Inline::Space(_)) {
132+
plain_content.pop();
133+
} else {
134+
break;
135+
}
136+
}
137+
128138
table_cell.content.push(Block::Plain(Plain {
129139
content: plain_content,
130140
source_info: node_source_info_with_context(node, context),

crates/quarto-markdown-pandoc/src/writers/json.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ fn write_blockss(blockss: &[Vec<Block>]) -> Value {
215215
fn write_caption(caption: &Caption) -> Value {
216216
json!([
217217
&caption.short.as_ref().map(|s| write_inlines(&s)),
218-
&caption.long.as_ref().map(|l| write_blocks(&l)),
218+
&caption
219+
.long
220+
.as_ref()
221+
.map(|l| write_blocks(&l))
222+
.unwrap_or_else(|| json!([])),
219223
])
220224
}
221225

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| Header 1 | Header 2 |
2+
|----------|----------|
3+
| Cell 1 | Cell 2 |
4+
| Cell 3 | Cell 4 |

0 commit comments

Comments
 (0)