From 5ff39f408f723a253ca0207246b320ca0c9e5ef4 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 07:40:50 -0500 Subject: [PATCH] Write nested style lists through shared IDML model --- Cargo.lock | 22 ++++----- Cargo.toml | 4 +- crates/idml/src/export/text_attrs.rs | 72 +++++++++++++--------------- 3 files changed, 46 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d49aaa55e..bb97b80f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1242,10 +1242,10 @@ dependencies = [ [[package]] name = "craft-idml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=7c6abc70a679334a7407087b88544a49058e9623#7c6abc70a679334a7407087b88544a49058e9623" +source = "git+https://github.com/storytold/craft-libs?rev=b47d3a7915124cd2515f2c992fe45eec203f7511#b47d3a7915124cd2515f2c992fe45eec203f7511" dependencies = [ - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7c6abc70a679334a7407087b88544a49058e9623)", - "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7c6abc70a679334a7407087b88544a49058e9623)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b47d3a7915124cd2515f2c992fe45eec203f7511)", + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b47d3a7915124cd2515f2c992fe45eec203f7511)", "thiserror 2.0.21", ] @@ -1656,7 +1656,7 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=7c6abc70a679334a7407087b88544a49058e9623#7c6abc70a679334a7407087b88544a49058e9623" +source = "git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551" dependencies = [ "quick-xml 0.41.0", "thiserror 2.0.21", @@ -1665,7 +1665,7 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551" +source = "git+https://github.com/storytold/craft-libs?rev=b47d3a7915124cd2515f2c992fe45eec203f7511#b47d3a7915124cd2515f2c992fe45eec203f7511" dependencies = [ "quick-xml 0.41.0", "thiserror 2.0.21", @@ -1730,7 +1730,7 @@ dependencies = [ [[package]] name = "craft-zip" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=7c6abc70a679334a7407087b88544a49058e9623#7c6abc70a679334a7407087b88544a49058e9623" +source = "git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551" dependencies = [ "flate2", "thiserror 2.0.21", @@ -1740,7 +1740,7 @@ dependencies = [ [[package]] name = "craft-zip" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551" +source = "git+https://github.com/storytold/craft-libs?rev=b47d3a7915124cd2515f2c992fe45eec203f7511#b47d3a7915124cd2515f2c992fe45eec203f7511" dependencies = [ "flate2", "thiserror 2.0.21", @@ -2021,7 +2021,7 @@ dependencies = [ "craft-prepress", "craft-print", "craft-svg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cc23ffd4d26f3074808e2187d332564817624f8f)", - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7c6abc70a679334a7407087b88544a49058e9623)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b47d3a7915124cd2515f2c992fe45eec203f7511)", "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f23b0f33f0d00b157476533a43cbbcfd901aa1f1)", "designcraft-color", "designcraft-compose", @@ -2103,9 +2103,9 @@ name = "designcraft-idml" version = "0.20.1" dependencies = [ "craft-file-formats", - "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7c6abc70a679334a7407087b88544a49058e9623)", + "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b47d3a7915124cd2515f2c992fe45eec203f7511)", "craft-svg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cc23ffd4d26f3074808e2187d332564817624f8f)", - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7c6abc70a679334a7407087b88544a49058e9623)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b47d3a7915124cd2515f2c992fe45eec203f7511)", "designcraft-color", "designcraft-compose", "designcraft-doc", @@ -2222,7 +2222,7 @@ version = "0.20.1" dependencies = [ "craft-docx", "craft-file-formats", - "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7c6abc70a679334a7407087b88544a49058e9623)", + "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b47d3a7915124cd2515f2c992fe45eec203f7511)", "craft-rtf", "craft-wordmodel", "craft-xlsx", diff --git a/Cargo.toml b/Cargo.toml index a9d0f8053..2b88399a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,10 +16,10 @@ craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "4052591363 craft-designcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "19692b6190465671e41967c75d0cd4c439d0c84c", version = "=0.1.0" } craft-eps = { git = "https://github.com/storytold/craft-libs", rev = "ba24fe2435adb3c81ad6057faf36365fbba736cf", version = "=0.1.0" } craft-epub = { git = "https://github.com/storytold/craft-libs", rev = "ba24fe2435adb3c81ad6057faf36365fbba736cf", version = "=0.1.0" } -craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "7c6abc70a679334a7407087b88544a49058e9623", version = "=0.1.0" } +craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "b47d3a7915124cd2515f2c992fe45eec203f7511", version = "=0.1.0" } craft-indd = { git = "https://github.com/storytold/craft-libs", rev = "47bf5650b0d503b97bfb5e841746c4957897d11f", version = "=0.1.0" } craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "cc23ffd4d26f3074808e2187d332564817624f8f", version = "=0.1.0", features = ["tree-render", "tree-text"] } -craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "7c6abc70a679334a7407087b88544a49058e9623", version = "=0.1.0" } +craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "b47d3a7915124cd2515f2c992fe45eec203f7511", version = "=0.1.0" } craft-xml-dtd = { package = "craft-xml", git = "https://github.com/storytold/craft-libs", rev = "f23b0f33f0d00b157476533a43cbbcfd901aa1f1", version = "=0.1.0" } craft-rtf = { git = "https://github.com/storytold/craft-libs", rev = "ba24fe2435adb3c81ad6057faf36365fbba736cf", version = "=0.1.0" } craft-xlsx = { git = "https://github.com/storytold/craft-libs", rev = "ba24fe2435adb3c81ad6057faf36365fbba736cf", version = "=0.1.0" } diff --git a/crates/idml/src/export/text_attrs.rs b/crates/idml/src/export/text_attrs.rs index 1c0def755..c02edf8b0 100644 --- a/crates/idml/src/export/text_attrs.rs +++ b/crates/idml/src/export/text_attrs.rs @@ -274,45 +274,39 @@ impl<'a> Ex<'a> { _ => {} } } - if let Some(list) = &list { - let mut l = El::new("AllNestedStyles").attr("type", "list"); - for ns in list { - let (ty, delim) = names::nested_until_out(&ns.until); - l = l.child( - El::new("ListItem") - .attr("type", "record") - .child(p("AppliedCharacterStyle", "object", names::style_self("CharacterStyle", CHAR_BUILTINS, &ns.style))) - .child(p("Delimiter", ty, delim)) - .child(p("Repetition", "long", ns.count.to_string())) - .child(p("Inclusive", "boolean", bool_s(ns.through))), - ); - } - props.push(l); - } - if let Some(list) = &a.nested_line_styles { - let mut l = El::new("AllNestedLineStyles").attr("type", "list"); - for ns in list { - l = l.child( - El::new("ListItem") - .attr("type", "record") - .child(p("AppliedCharacterStyle", "object", names::style_self("CharacterStyle", CHAR_BUILTINS, &ns.style))) - .child(p("LineCount", "long", ns.lines.to_string())), - ); - } - props.push(l); - } - if let Some(list) = &a.grep_styles { - let mut l = El::new("AllGREPStyles").attr("type", "list"); - for g in list { - l = l.child( - El::new("ListItem") - .attr("type", "record") - .child(p("AppliedCharacterStyle", "object", names::style_self("CharacterStyle", CHAR_BUILTINS, &g.style))) - .child(p("GrepExpression", "string", g.pattern.clone())), - ); - } - props.push(l); - } + let values = craft_idml::model::NestedStyleValues { + nested: list.map(|list| { + list.iter() + .map(|style| { + let (delimiter_type, delimiter) = names::nested_until_out(&style.until); + craft_idml::model::NestedStyleValue { + character_style: names::style_self("CharacterStyle", CHAR_BUILTINS, &style.style), + inclusive: style.through, + repetition: style.count, + delimiter_type: delimiter_type.into(), + delimiter, + } + }) + .collect() + }), + lines: a.nested_line_styles.as_ref().map(|list| { + list.iter() + .map(|style| craft_idml::model::NestedLineStyleValue { + character_style: names::style_self("CharacterStyle", CHAR_BUILTINS, &style.style), + line_count: style.lines, + }) + .collect() + }), + grep: a.grep_styles.as_ref().map(|list| { + list.iter() + .map(|style| craft_idml::model::GrepStyleValue { + character_style: names::style_self("CharacterStyle", CHAR_BUILTINS, &style.style), + expression: style.pattern.clone(), + }) + .collect() + }), + }; + props.extend(values.to_els().into_iter().map(crate::xml::from_craft)); } fn para_alignment_attrs(&self, el: &mut El, a: &ParaAttrs, parent: Option<&str>) {