DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Fix spurious empty paragraph after tables in DOCX import
NetterSilver6a78e8f354c7
diff --git a/crates/textimport/src/docx.rs b/crates/textimport/src/docx.rsindex faa086435..346e9601e 100644--- a/crates/textimport/src/docx.rs+++ b/crates/textimport/src/docx.rs@@ -304,7 +304,7 @@ impl Ctx {let t = Table::from_strings(self.next_table, &rows, 300.0, &ParaFormat::default(), &CharFormat::default());let len = st.len();st.insert_table(len, t);- first = false;+ first = st.text.ends_with('\n');}"sdt" => {if let Some(c) = e.child("sdtContent") {@@ -603,6 +603,23 @@ mod tests {assert!(parse(&nested(100_000)).is_err());}+ #[test]+ fn table_adds_no_empty_paragraph() {+ let document = format!(+ r#"<w:document {W}><w:body>+ <w:p><w:r><w:t>Before</w:t></w:r></w:p>+ <w:tbl><w:tr><w:tc><w:p><w:r><w:t>A</w:t></w:r></w:p></w:tc></w:tr></w:tbl>+ <w:p><w:r><w:t>After</w:t></w:r></w:p>+ </w:body></w:document>"#+ );+ let st = import(&docx(&document, "", "")).unwrap().story;+ st.check().unwrap();+ let paras: Vec<&str> = st.para_ranges().into_iter().map(|r| &st.text[r]).collect();+ assert_eq!(paras.len(), 3, "{paras:?}");+ assert_eq!(paras[0], "Before");+ assert_eq!(paras[2], "After");+ }+pub(crate) fn docx(document: &str, styles: &str, footnotes: &str) -> Vec<u8> {docx_parts(&[("word/document.xml", document), ("word/styles.xml", styles), ("word/footnotes.xml", footnotes)])}