From 3dc8c1116239ea594162791d6bf03cf13e316ddb Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 07:19:59 -0500 Subject: [PATCH] Read nested IDML styles through shared model --- Cargo.lock | 52 ++++++++++++------------ Cargo.toml | 4 +- crates/idml/src/import/text_attrs.rs | 59 ++++++++++++---------------- 3 files changed, 54 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3defc7f13..56707d9c9 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=49e4a1b4a127b168426db02eb62b6cd6436eea46#49e4a1b4a127b168426db02eb62b6cd6436eea46" +source = "git+https://github.com/storytold/craft-libs?rev=cd9e233af94ae8111a4417a00dc8df0ccb40dc54#cd9e233af94ae8111a4417a00dc8df0ccb40dc54" dependencies = [ - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=49e4a1b4a127b168426db02eb62b6cd6436eea46)", - "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=49e4a1b4a127b168426db02eb62b6cd6436eea46)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cd9e233af94ae8111a4417a00dc8df0ccb40dc54)", + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cd9e233af94ae8111a4417a00dc8df0ccb40dc54)", "thiserror 2.0.21", ] @@ -1653,15 +1653,6 @@ dependencies = [ "thiserror 2.0.21", ] -[[package]] -name = "craft-xml" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=49e4a1b4a127b168426db02eb62b6cd6436eea46#49e4a1b4a127b168426db02eb62b6cd6436eea46" -dependencies = [ - "quick-xml 0.41.0", - "thiserror 2.0.21", -] - [[package]] name = "craft-xml" version = "0.1.0" @@ -1689,6 +1680,15 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-xml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=cd9e233af94ae8111a4417a00dc8df0ccb40dc54#cd9e233af94ae8111a4417a00dc8df0ccb40dc54" +dependencies = [ + "quick-xml 0.41.0", + "thiserror 2.0.21", +] + [[package]] name = "craft-xml" version = "0.1.0" @@ -1727,16 +1727,6 @@ dependencies = [ "zip 9.1.1", ] -[[package]] -name = "craft-zip" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=49e4a1b4a127b168426db02eb62b6cd6436eea46#49e4a1b4a127b168426db02eb62b6cd6436eea46" -dependencies = [ - "flate2", - "thiserror 2.0.21", - "zip 9.1.1", -] - [[package]] name = "craft-zip" version = "0.1.0" @@ -1757,6 +1747,16 @@ dependencies = [ "zip 9.1.1", ] +[[package]] +name = "craft-zip" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=cd9e233af94ae8111a4417a00dc8df0ccb40dc54#cd9e233af94ae8111a4417a00dc8df0ccb40dc54" +dependencies = [ + "flate2", + "thiserror 2.0.21", + "zip 9.1.1", +] + [[package]] name = "craft-zip" version = "0.1.0" @@ -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=49e4a1b4a127b168426db02eb62b6cd6436eea46)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cd9e233af94ae8111a4417a00dc8df0ccb40dc54)", "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=49e4a1b4a127b168426db02eb62b6cd6436eea46)", + "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cd9e233af94ae8111a4417a00dc8df0ccb40dc54)", "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=49e4a1b4a127b168426db02eb62b6cd6436eea46)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cd9e233af94ae8111a4417a00dc8df0ccb40dc54)", "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=49e4a1b4a127b168426db02eb62b6cd6436eea46)", + "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cd9e233af94ae8111a4417a00dc8df0ccb40dc54)", "craft-rtf", "craft-wordmodel", "craft-xlsx", diff --git a/Cargo.toml b/Cargo.toml index d353ba4c8..d93c7ec4e 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 = "49e4a1b4a127b168426db02eb62b6cd6436eea46", version = "=0.1.0" } +craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "cd9e233af94ae8111a4417a00dc8df0ccb40dc54", 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 = "49e4a1b4a127b168426db02eb62b6cd6436eea46", version = "=0.1.0" } +craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "cd9e233af94ae8111a4417a00dc8df0ccb40dc54", 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/import/text_attrs.rs b/crates/idml/src/import/text_attrs.rs index 0220da831..07f7fe5ac 100644 --- a/crates/idml/src/import/text_attrs.rs +++ b/crates/idml/src/import/text_attrs.rs @@ -347,18 +347,15 @@ impl<'r> Importer<'r> { } fn read_nested_styles(&self, e: &El, attrs: &mut ParaAttrs) { - if let Some(list) = e.prop_el("AllNestedStyles") { - let styles: Vec = list - .find_all("ListItem") - .map(|item| { - let text = |key: &str| item.find(key).map(|element| element.text_content()).unwrap_or_default(); - let delimiter = item.find("Delimiter"); - designcraft_doc::NestedStyle { - style: self.listed_char_style_ref(&text("AppliedCharacterStyle")), - through: text("Inclusive").trim() != "false", - count: text("Repetition").trim().parse().unwrap_or(1), - until: names::nested_until_in(delimiter.and_then(|element| element.get("type")).unwrap_or("enumeration"), &text("Delimiter")), - } + let lists = craft_idml::model::NestedStyleValues::from_el(&crate::xml::to_craft(e)); + if let Some(values) = lists.nested { + let styles: Vec = values + .into_iter() + .map(|value| designcraft_doc::NestedStyle { + style: self.listed_char_style_ref(&value.character_style), + through: value.inclusive, + count: value.repetition, + until: names::nested_until_in(&value.delimiter_type, &value.delimiter), }) .collect(); // IDML has no drop cap style attribute: the drop cap's character style is the list's @@ -366,28 +363,24 @@ impl<'r> Importer<'r> { attrs.drop_cap_style = styles.first().filter(|style| style.is_drop_cap()).map(|style| style.style.clone()); attrs.nested_styles = Some(styles); } - if let Some(list) = e.prop_el("AllNestedLineStyles") { - let styles = list - .find_all("ListItem") - .map(|item| { - let text = |key: &str| item.find(key).map(|element| element.text_content()).unwrap_or_default(); - designcraft_doc::NestedLineStyle { - style: self.listed_char_style_ref(&text("AppliedCharacterStyle")), - lines: text("LineCount").trim().parse().unwrap_or(1), - } - }) - .collect(); - attrs.nested_line_styles = Some(styles); + if let Some(values) = lists.lines { + attrs.nested_line_styles = Some( + values + .into_iter() + .map(|value| designcraft_doc::NestedLineStyle { + style: self.listed_char_style_ref(&value.character_style), + lines: value.line_count, + }) + .collect(), + ); } - if let Some(list) = e.prop_el("AllGREPStyles") { - let styles = list - .find_all("ListItem") - .map(|item| { - let text = |key: &str| item.find(key).map(|element| element.text_content()).unwrap_or_default(); - designcraft_doc::GrepStyle { style: self.listed_char_style_ref(&text("AppliedCharacterStyle")), pattern: text("GrepExpression") } - }) - .collect(); - attrs.grep_styles = Some(styles); + if let Some(values) = lists.grep { + attrs.grep_styles = Some( + values + .into_iter() + .map(|value| designcraft_doc::GrepStyle { style: self.listed_char_style_ref(&value.character_style), pattern: value.expression }) + .collect(), + ); } }