From 108427e216c14f5f3bfdf003d3589b89f40aabb0 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Thu, 15 Oct 2026 15:24:11 +0000 Subject: [PATCH] Keep text of inline content controls in DOCX import Found while testing crates/textimport/src/docx.rs:354 Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/textimport/src/docx.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/textimport/src/docx.rs b/crates/textimport/src/docx.rs index 20101f82..6d3d05d5 100644 --- a/crates/textimport/src/docx.rs +++ b/crates/textimport/src/docx.rs @@ -352,6 +352,12 @@ impl Ctx { // Tracked changes import as accepted: insertions and move destinations are kept, // deletions (`del`) and move sources (`moveFrom`) are dropped. "hyperlink" | "smartTag" | "ins" | "moveTo" | "fldSimple" | "customXml" => self.inline(e, st, allow_notes), + // A content control (date picker, drop-down, plain text) keeps its runs in `sdtContent`. + "sdt" => { + if let Some(c) = e.child("sdtContent") { + self.inline(c, st, allow_notes); + } + } _ => {} } } @@ -620,6 +626,20 @@ mod tests { assert_eq!(i.char_styles[0].chars.font_style.as_deref(), Some("Italic")); } + /// A content control inside a paragraph (`w:sdt`) keeps its text, also around a hyperlink. + #[test] + fn inline_content_control_text_is_kept() { + let document = format!( + r#" + Date: 1 May 2026. + Link + "# + ); + let st = import(&docx(&document, "", "")).unwrap().story; + st.check().unwrap(); + assert_eq!(st.text, "Date: 1 May 2026.\nLink"); + } + /// A page break ends its paragraph: the text after it is a paragraph of its own (same style). #[test] fn page_break_ends_its_paragraph() {