World's first open-source enterprise world model.
Rust agent-memorybitemporalgraphragknowledge-baseknowledge-graphllmontologypgvectorpostgresqlragrustself-hostedsemantic-searchtemporal-knowledge-graphworld-model
Read PPTX merge attributes from table cells to preserve merged content (#1077)
Daniel17ce57432fd1
diff --git a/crates/utopia-ingest/src/parsers.rs b/crates/utopia-ingest/src/parsers.rsindex d715634e..4a508127 100644--- a/crates/utopia-ingest/src/parsers.rs+++ b/crates/utopia-ingest/src/parsers.rs@@ -1089,20 +1089,16 @@ fn pptx_xml_to_text(xml: &str) -> anyhow::Result<String> {}"a:tr" if table_depth == 1 => row.clear(),"a:tc" if table_depth == 1 => {+ // DrawingML 的合并属性属于 a:tc,后面的 a:tcPr 只描述样式。cell = Some(TableCell {- span: 1,+ span: attr(&e, "gridSpan")+ .and_then(|v| v.parse().ok())+ .unwrap_or(1),+ horizontal_merge: truthy(&e, "hMerge"),+ vertical_merge: truthy(&e, "vMerge"),..TableCell::default()});}- "a:tcPr" if table_depth == 1 => {- if let Some(c) = cell.as_mut() {- if let Some(span) = attr(&e, "gridSpan").and_then(|v| v.parse().ok()) {- c.span = span;- }- c.horizontal_merge = truthy(&e, "hMerge");- c.vertical_merge = truthy(&e, "vMerge");- }- }"a:t" => {if cell.is_some() || table_depth == 0 {in_text = true;@@ -1119,15 +1115,6 @@ fn pptx_xml_to_text(xml: &str) -> anyhow::Result<String> {"a:tblPr" if table_depth == 1 => {first_is_header = truthy(&e, "firstRow");}- "a:tcPr" if table_depth == 1 => {- if let Some(c) = cell.as_mut() {- if let Some(span) = attr(&e, "gridSpan").and_then(|v| v.parse().ok()) {- c.span = span;- }- c.horizontal_merge = truthy(&e, "hMerge");- c.vertical_merge = truthy(&e, "vMerge");- }- }"a:br" => match cell.as_mut() {Some(c) => c.text.push(' '),None if table_depth == 0 => out.push('\n'),diff --git a/crates/utopia-ingest/tests/pptx_tables.rs b/crates/utopia-ingest/tests/pptx_tables.rsindex a4c81662..d4f94ce8 100644--- a/crates/utopia-ingest/tests/pptx_tables.rs+++ b/crates/utopia-ingest/tests/pptx_tables.rs@@ -31,12 +31,12 @@ fn text_box(text: &str) -> String {}fn cell(text: &str) -> String {- cell_with_props(text, "")+ cell_with_attrs(text, "")}-fn cell_with_props(text: &str, props: &str) -> String {+fn cell_with_attrs(text: &str, attrs: &str) -> String {format!(- r#"<a:tc><a:txBody><a:bodyPr/><a:lstStyle/><a:p><a:r><a:t>{text}</a:t></a:r></a:p></a:txBody><a:tcPr {props}/></a:tc>"#+ r#"<a:tc {attrs}><a:txBody><a:bodyPr/><a:lstStyle/><a:p><a:r><a:t>{text}</a:t></a:r></a:p></a:txBody><a:tcPr/></a:tc>"#)}@@ -48,8 +48,8 @@ fn cell_with_paragraphs(paragraphs: &[&str]) -> String {format!(r#"<a:tc><a:txBody><a:bodyPr/><a:lstStyle/>{paragraphs}</a:txBody><a:tcPr/></a:tc>"#)}-fn empty_cell(props: &str) -> String {- format!(r#"<a:tc><a:txBody><a:bodyPr/><a:lstStyle/><a:p/></a:txBody><a:tcPr {props}/></a:tc>"#)+fn empty_cell(attrs: &str) -> String {+ format!(r#"<a:tc {attrs}><a:txBody><a:bodyPr/><a:lstStyle/><a:p/></a:txBody><a:tcPr/></a:tc>"#)}fn row(cells: &[String]) -> String {@@ -135,7 +135,7 @@ fn a_slide_table_that_is_not_a_grid_of_data_keeps_its_words() {let text = parse_slide(&table(first_row,&[row(&[- cell_with_props("Notice for the board", r#"gridSpan="2""#),+ cell_with_attrs("Notice for the board", r#"gridSpan="2""#),empty_cell(r#"hMerge="1""#),])],));@@ -186,43 +186,60 @@ fn a_title_and_text_around_a_slide_table_keep_their_lines() {#[test]fn grid_span_and_horizontal_merge_keep_the_grid_shape() {- let text = parse_slide(&table(+ let body = table(true,&[row(&[- cell_with_props("Summary", r#"gridSpan="2""#),- cell_with_props("COVERED", r#"hMerge="1""#),+ cell_with_attrs("Summary", r#"gridSpan="2""#),+ cell_with_attrs("HORIZONTAL-COVERED", r#"hMerge="1""#),cell("Total"),]),row(&[cell("Q1"), cell("1,200"), cell("1,350")]),],- ));-- assert!(- text.contains("| | Summary | Total |\n| --- | --- | --- |\n| Q1 | 1,200 | 1,350 |"),- "{text}");- assert!(!text.contains("COVERED"), "{text}");++ // Both XML event forms must leave the merge attributes read from a:tc intact.+ for properties in ["<a:tcPr/>", "<a:tcPr></a:tcPr>"] {+ let text = parse_slide(&body.replace("<a:tcPr/>", properties));+ assert!(!text.contains("HORIZONTAL-COVERED"), "{properties}: {text}");+ assert!(+ text.contains("| | Summary | Total |\n| --- | --- | --- |\n| Q1 | 1,200 | 1,350 |"),+ "{properties}: {text}"+ );+ }}#[test]fn a_vertical_merge_continuation_stays_an_empty_cell() {- let text = parse_slide(&table(+ let body = table(true,&[row(&[cell("Quarter"), cell("Revenue"), cell("YoY")]),- row(&[cell("Q1"), cell("1,200"), cell("+12%")]),- row(&[cell("Q2"), cell("1,350"), empty_cell(r#"vMerge="1""#)]),+ row(&[+ cell("Q1"),+ cell("1,200"),+ cell_with_attrs("+12%", r#"rowSpan="2""#),+ ]),+ row(&[+ cell("Q2"),+ cell("1,350"),+ cell_with_attrs("VERTICAL-COVERED", r#"vMerge="1""#),+ ]),row(&[cell("Q3"), cell("1,410"), cell("+7%")]),],- ));-- assert!(- text.contains(- "| Quarter | Revenue | YoY |\n| --- | --- | --- |\n| Q1 | 1,200 | +12% |\n| Q2 | 1,350 | |\n| Q3 | 1,410 | +7% |"- ),- "{text}");++ // An already empty continuation would pass even if vMerge were ignored.+ for properties in ["<a:tcPr/>", "<a:tcPr></a:tcPr>"] {+ let text = parse_slide(&body.replace("<a:tcPr/>", properties));+ assert!(!text.contains("VERTICAL-COVERED"), "{properties}: {text}");+ assert!(+ text.contains(+ "| Quarter | Revenue | YoY |\n| --- | --- | --- |\n| Q1 | 1,200 | +12% |\n| Q2 | 1,350 | |\n| Q3 | 1,410 | +7% |"+ ),+ "{properties}: {text}"+ );+ }}#[test]