From 3b02f3ee6c9b3d7ce3bddbfd87c4a1436278fa4f Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sun, 15 Nov 2026 22:11:54 +0100 Subject: [PATCH] craft-pptx: test kept 3-D and layout/master extensions in default-namespace parts Extends the default-namespace theme test with an effect style holding scene3d and sp3d, and adds a layout and master case whose unprefixed extLst/ext is written back through ext_children. To be precise about the previous commit: theme effect styles and shape spPr 3-D kept from a part with a default namespace now keep that namespace. Text bodyPr and group spPr 3-D without a prefix are still dropped on save, as before (valid_raw3d requires the a: prefix); that is out of scope here. Co-Authored-By: Claude Opus 5.5 --- crates/pptx/tests/write.rs | 49 +++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/crates/pptx/tests/write.rs b/crates/pptx/tests/write.rs index b6315375a..46f7513e7 100644 --- a/crates/pptx/tests/write.rs +++ b/crates/pptx/tests/write.rs @@ -220,7 +220,7 @@ fn namespaces_of(xml: &str, local: &str) -> Vec { } /// A theme with a custom colour list and a theme family id, with the `a:` prefix. -const PREFIXED_THEME: &str = r#""#; +const PREFIXED_THEME: &str = r#""#; /// The deck with its theme part replaced by `theme`. fn with_theme(theme: &str) -> Vec { @@ -244,6 +244,9 @@ fn a_default_namespace_theme_keeps_its_kept_parts_in_the_drawingml_namespace() { assert!(!ns.is_empty() && ns.iter().all(|n| n == NS_A), "{local}: {ns:?}\n{xml}"); } assert_eq!(namespaces_of(&xml, "themeFamily"), [NS_THM15], "{xml}"); + // The effect style's 3-D is kept as written too. + assert_eq!(namespaces_of(&xml, "scene3d"), [NS_A], "{xml}"); + assert_eq!(namespaces_of(&xml, "sp3d"), [NS_A], "{xml}"); // The second save writes the same kept parts. let kept = |x: &str| x[x.find("").expect("themeElements")..].to_string(); let twice = craft_pptx::export(&craft_pptx::import(&once, &Plain).unwrap(), &Plain).unwrap(); @@ -264,31 +267,55 @@ fn a_prefixed_theme_keeps_its_kept_parts_unchanged() { assert!(xml.contains(&kept), "{xml}"); } -/// A slide written with a default PresentationML namespace: its kept extension list stays in -/// that namespace under the writer's `p:extLst`. -#[test] -fn a_default_namespace_slide_keeps_its_extensions_in_the_presentationml_namespace() { +/// The deck with part `name` (root `root`) given a default PresentationML namespace and an +/// unprefixed extension list, saved again: the part as written. +fn default_namespace_extensions(name: &str, root: &str) -> String { let pptx = craft_pptx::export(&deck(), &Plain).unwrap(); let ext = r#""#; + let (open, close) = (format!("<{root} "), format!("")); let doc = common::rewrite( &pptx, - |name, data| { - if name != "ppt/slides/slide1.xml" { + |n, data| { + if n != name { return Some(data.to_vec()); } let xml = String::from_utf8(data.to_vec()).unwrap(); - assert!(xml.contains("") && !xml.contains("extLst"), "{xml}"); - Some(xml.replacen("", &format!("{ext}")).into_bytes()) + assert!(xml.contains(&open) && xml.contains(&close) && !xml.contains("extLst"), "{xml}"); + Some(xml.replacen(&open, &format!(r#"<{root} xmlns="{NS_P}" "#), 1).replace(&close, &format!("{ext}{close}")).into_bytes()) }, &[], ); let p = craft_pptx::import(&doc, &Plain).unwrap(); - let xml = part(&craft_pptx::export(&p, &Plain).unwrap(), "ppt/slides/slide1.xml"); + part(&craft_pptx::export(&p, &Plain).unwrap(), name) +} + +/// The namespaces of the `ext` elements in `xml` other than DrawingML's `a:ext` (an extent). +fn extension_namespaces(xml: &str) -> Vec { + namespaces_of(xml, "ext").into_iter().filter(|n| n != NS_A).collect() +} + +/// A slide written with a default PresentationML namespace: its kept extension list stays in +/// that namespace under the writer's `p:extLst`. +#[test] +fn a_default_namespace_slide_keeps_its_extensions_in_the_presentationml_namespace() { + let xml = default_namespace_extensions("ppt/slides/slide1.xml", "p:sld"); assert!(xml.contains("{11111111-2222-3333-4444-555555555555}"), "{xml}"); - assert_eq!(namespaces_of(&xml, "ext"), [NS_P], "{xml}"); + assert_eq!(extension_namespaces(&xml), [NS_P], "{xml}"); assert_eq!(namespaces_of(&xml, "data"), ["urn:test"], "{xml}"); } +/// The same for a layout and a master, whose kept extension list is written back through +/// `ext_children`. +#[test] +fn a_default_namespace_layout_and_master_keep_their_extensions_in_the_presentationml_namespace() { + for (name, root) in [("ppt/slideLayouts/slideLayout1.xml", "p:sldLayout"), ("ppt/slideMasters/slideMaster1.xml", "p:sldMaster")] { + let xml = default_namespace_extensions(name, root); + assert!(xml.contains("{11111111-2222-3333-4444-555555555555}"), "{name}: {xml}"); + assert_eq!(extension_namespaces(&xml), [NS_P], "{name}: {xml}"); + assert_eq!(namespaces_of(&xml, "data"), ["urn:test"], "{name}: {xml}"); + } +} + #[test] fn templates_and_shows_differ_in_the_main_content_type() { let p = deck();