From 8aa8134bf9f2d578412a2c8b2826a92f332d41fb Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 05:57:19 -0500 Subject: [PATCH] Map typed IDML story marker nodes --- Cargo.lock | 22 ++++++++-------- Cargo.toml | 4 +-- crates/idml/src/import/document.rs | 6 ++--- crates/idml/src/import/story.rs | 40 +++++++++++++++--------------- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c3fc33245..c847fc1cd 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=a4496eabf#a4496eabf80b753ce4d4e5f6a635628869711f75" +source = "git+https://github.com/storytold/craft-libs?rev=4ab88cfa0#4ab88cfa05835422de4589eee971a01f0160ebf6" dependencies = [ - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a4496eabf)", - "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a4496eabf)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4ab88cfa0)", + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4ab88cfa0)", "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=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551" +source = "git+https://github.com/storytold/craft-libs?rev=4ab88cfa0#4ab88cfa05835422de4589eee971a01f0160ebf6" 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=a4496eabf#a4496eabf80b753ce4d4e5f6a635628869711f75" +source = "git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551" 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=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551" +source = "git+https://github.com/storytold/craft-libs?rev=4ab88cfa0#4ab88cfa05835422de4589eee971a01f0160ebf6" 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=a4496eabf#a4496eabf80b753ce4d4e5f6a635628869711f75" +source = "git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551" 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=a4496eabf)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4ab88cfa0)", "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=a4496eabf)", + "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4ab88cfa0)", "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=a4496eabf)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4ab88cfa0)", "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=a4496eabf)", + "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4ab88cfa0)", "craft-rtf", "craft-wordmodel", "craft-xlsx", diff --git a/Cargo.toml b/Cargo.toml index c5d16c191..2d5bc541b 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 = "a4496eabf", version = "=0.1.0" } +craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "4ab88cfa0", 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 = "a4496eabf", version = "=0.1.0" } +craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "4ab88cfa0", 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/document.rs b/crates/idml/src/import/document.rs index 3b78413ef..2d4e5bb11 100644 --- a/crates/idml/src/import/document.rs +++ b/crates/idml/src/import/document.rs @@ -198,10 +198,10 @@ impl<'r> Importer<'r> { /// A `TextVariableInstance`: the variable's character, or its recorded text when the file /// doesn't define the variable. - pub(super) fn text_variable_instance(&mut self, e: &El) -> String { + pub(super) fn text_variable_instance(&mut self, values: &craft_idml::model::Values) -> String { use designcraft_doc::vars::{VarKind, var_char}; - let result = e.get("ResultText").unwrap_or(""); - let found = e.get("AssociatedTextVariable").and_then(|r| self.text_var_ids.get(r)).copied(); + let result = values.get("ResultText").unwrap_or(""); + let found = values.get("AssociatedTextVariable").and_then(|r| self.text_var_ids.get(r)).copied(); let var = found.and_then(|i| Some((i, self.text_vars.as_mut()?.get_mut(i)?))); match var.and_then(|(i, v)| Some((var_char(i)?, v))) { Some((c, v)) => { diff --git a/crates/idml/src/import/story.rs b/crates/idml/src/import/story.rs index 597f72208..26713a8fc 100644 --- a/crates/idml/src/import/story.rs +++ b/crates/idml/src/import/story.rs @@ -196,6 +196,26 @@ impl<'r> Importer<'r> { b.push_table(t, pf, cf); } } + craft_idml::model::TextNode::Anchor(anchor) => { + b.anchors.push((anchor.self_id().unwrap_or("").to_string(), anchor.label().unwrap_or("Anchor").to_string())); + b.push(&designcraft_doc::ANCHOR_MARK.to_string(), cf); + } + craft_idml::model::TextNode::PageReference(reference) => { + use designcraft_doc::index::IndexRange as R; + let topic = reference.referenced_topic().and_then(|r| self.index_topics.get(r)).cloned().unwrap_or_default(); + let range = match reference.reference_type() { + Some("ToEndOfStory" | "ToEndOfDocument" | "ToEndOfSection") => R::ToEndOfStory, + Some("ForNextNParagraphs") => R::NextParagraphs(reference.limit().unwrap_or(1.0).max(1.0) as u32), + Some("SuppressPageNumbers") => R::SuppressPageRange, + _ => R::CurrentPage, + }; + b.index_refs.push(designcraft_doc::IndexRef { topics: topic.path, sort: topic.sort, range }); + b.push(&designcraft_doc::INDEX_MARK.to_string(), cf); + } + craft_idml::model::TextNode::TextVariable(values) => { + let text = self.text_variable_instance(&values); + b.push(&text, cf); + } _ => match c.local() { // The source wraps the text the link covers: its children are ordinary ranges // and content, so the range is where the text stood before and after (#1446). @@ -206,22 +226,6 @@ impl<'r> Importer<'r> { b.link_srcs.push((c.get("Self").unwrap_or("").to_string(), start, b.text.len())); } } - "HyperlinkTextDestination" | "ParagraphDestination" => { - b.anchors.push((c.get("Self").unwrap_or("").to_string(), c.get("Name").unwrap_or("Anchor").to_string())); - b.push(&designcraft_doc::ANCHOR_MARK.to_string(), cf); - } - "PageReference" => { - use designcraft_doc::index::IndexRange as R; - let topic = c.get("ReferencedTopic").and_then(|r| self.index_topics.get(r)).cloned().unwrap_or_default(); - let range = match c.get("PageReferenceType") { - Some("ToEndOfStory") | Some("ToEndOfDocument") | Some("ToEndOfSection") => R::ToEndOfStory, - Some("ForNextNParagraphs") => R::NextParagraphs(c.num("PageReferenceLimit").unwrap_or(1.0).max(1.0) as u32), - Some("SuppressPageNumbers") => R::SuppressPageRange, - _ => R::CurrentPage, - }; - b.index_refs.push(designcraft_doc::IndexRef { topics: topic.path, sort: topic.sort, range }); - b.push(&designcraft_doc::INDEX_MARK.to_string(), cf); - } "CrossReferenceSource" => { // The generated text is regenerated from the format. let (mut text, mut page) = (String::new(), None); @@ -310,10 +314,6 @@ impl<'r> Importer<'r> { b.push(&designcraft_doc::OBJECT_MARK.to_string(), cf); } } - "TextVariableInstance" => { - let t = self.text_variable_instance(c); - b.push(&t, cf); - } "Change" => { // Tracked changes: deleted text stays in the story, marked, and takes no // room in the layout.