Read nested IDML styles through shared model

This commit is contained in:
Dylan M. Taylor committed 2026-11-13 07:19:59 -05:00
1 parent a928e8805c
commit 3dc8c11162
3 files changed
+54 -61

No files matched your search

Generated
+26 -26
View File
@@ -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",
+2 -2
View File
@@ -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" }
+26 -33
View File
@@ -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<designcraft_doc::NestedStyle> = 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<designcraft_doc::NestedStyle> = 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(),
);
}
}