mirror of
https://github.com/storytold/designcraft.git
synced 2026-10-25 02:37:00 -06:00
Merge PR #1054: Keep text of inline content controls in DOCX import
crates/textimport/src/docx.rs: keep the branch's page_break_ends_its_paragraph test (already present further down); add the PR's inline content control test.
This commit is contained in:
@@ -368,6 +368,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);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -640,6 +646,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#"<w:document {W}><w:body>
|
||||
<w:p><w:r><w:t xml:space="preserve">Date: </w:t></w:r><w:sdt><w:sdtPr><w:alias w:val="d"/></w:sdtPr><w:sdtContent><w:r><w:t>1 May 2026</w:t></w:r></w:sdtContent></w:sdt><w:r><w:t>.</w:t></w:r></w:p>
|
||||
<w:p><w:sdt><w:sdtContent><w:hyperlink><w:r><w:t>Link</w:t></w:r></w:hyperlink></w:sdtContent></w:sdt></w:p>
|
||||
</w:body></w:document>"#
|
||||
);
|
||||
let st = import(&docx(&document, "", "")).unwrap().story;
|
||||
st.check().unwrap();
|
||||
assert_eq!(st.text, "Date: 1 May 2026.\nLink");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tracked_changes_import_as_accepted_including_moves() {
|
||||
// Regression (#256): text in a tracked move destination (`w:moveTo`) vanished on import.
|
||||
|
||||
Reference in New Issue
Block a user