diff --git a/crates/formats/src/markdown.rs b/crates/formats/src/markdown.rs index 45c805202..0410c56ba 100644 --- a/crates/formats/src/markdown.rs +++ b/crates/formats/src/markdown.rs @@ -215,6 +215,7 @@ fn delimiter_row(l: &str) -> Option>> { out.push(match (left, right) { (true, true) => Some(Align::Center), (false, true) => Some(Align::Right), + (true, false) => Some(Align::Left), _ => None, }); } @@ -1280,6 +1281,7 @@ fn table_md(t: &FTable, out: &mut Vec) { .map(|a| match a { Some(Align::Center) => ":---:", Some(Align::Right) => "---:", + Some(Align::Left) => ":---", _ => "---", }) .collect(); @@ -1680,4 +1682,22 @@ mod tests { assert_eq!(back_table2.rows[1][0].text(), "a`b|c"); assert_eq!(back_table2.rows[1][1].text(), "CRITICAL_DISTINCTIVE_INFO"); } + + #[test] + fn table_column_alignments_import_and_export() { + let md = "| Left | Center | Right | Default |\n| :--- | :---: | ---: | --- |\n| 1 | 2 | 3 | 4 |\n"; + let flow = parse(md); + let FBlock::Table(t) = &flow.blocks[0] else { panic!("expected table") }; + assert_eq!(t.rows.len(), 2); + let aligns: Vec> = t.rows[0] + .iter() + .map(|c| c.blocks.iter().find_map(|b| if let FBlock::Para(p) = b { Some(p.align) } else { None }).flatten()) + .collect(); + assert_eq!(aligns, vec![Some(Align::Left), Some(Align::Center), Some(Align::Right), None]); + + let mut out = Vec::new(); + table_md(t, &mut out); + let exported = out.join("\n"); + assert!(exported.contains("| :--- | :---: | ---: | --- |"), "Exported: {exported}"); + } }