mirror of
https://github.com/storytold/indd-utils.git
synced 2026-11-19 16:50:48 +01:00
fix: write a colon in a style group's name as \: in its Self and Name
This commit is contained in:
1 parent
971d3a5aff
commit
0bd2db2b96
5 files changed
+39
-30
No files matched your search
@@ -2872,6 +2872,12 @@ top-level group, joined by `:`, as in its `Self`:
|
||||
paragraph style groups, 25 of 25 character style groups and 2 of 2
|
||||
object style groups (three levels at most); top-level groups have `$ID/`
|
||||
and their name (622 of 622).
|
||||
A `:` inside a group's name is written `\:`, as in a style's own name
|
||||
(below): such a group has `Name="$ID/<a>\: <b>"` and
|
||||
`Self="ParagraphStyleGroup/$ID/<a>\%3a <b>"`, and its styles have
|
||||
`Name="<a>\: <b>:<style>"`. No pair of the corpus has such a group; this
|
||||
rests on one privately held sample (1 top-level paragraph style group
|
||||
with 6 paragraph styles, all matching).
|
||||
Cell style groups work the same way: the root cell style group's
|
||||
children (chunk 0x2024E) include groups of class 0xCA8B, and IDML writes
|
||||
each as `<CellStyleGroup Self="CellStyleGroup/$ID/<group>"
|
||||
|
||||
@@ -65,7 +65,6 @@ Status values:
|
||||
| Saving edition rule exceptions | tints, users, endnote and index titles | 9 | not needed | the IDML was exported by another edition than the one that saved the INDD (one trustworthy document, 8 stale pairs) | `objects.md`, saving edition |
|
||||
| `EndnoteSeparatorText` without chunk 0x2261E | `EndnoteOption` | 2 | open: not explained | tab in a Japanese document of code 0x0101, U+3000 in a Korean document of code 0x0100; the code gives the others | `footnotes.md`, endnote options |
|
||||
| `CaptionParagraphCount`, `HeaderColumnCellStyle` | root table style, attributes 0x1047A–0x1047C | 2 | open: never varies | IDML has both on the two root styles that have these IDs, but all three are 0, so which ID is which is not shown; not written | `tables.md`, caption position |
|
||||
| `:` in a style group's name | style groups | 0 | open: no sample | no pair has a style group whose name contains `:`, so how IDML writes such a group's `Self` and `Name` is not shown (a style's own name has `\:`); the converter writes the group's name as stored there, and with `\:` in the names of its styles | `objects.md`, style groups |
|
||||
| `Capitalization="LowerCase"` | text attribute 0x1B11 | 0 | open: no sample | no pair has the value, so its code is not shown; codes other than 0 to 3 are left out | `attributes.md` |
|
||||
| `ColorGroup` `Self` | `ColorGroup` | 2 | open: not examined | 6 extra values: groups whose `Self` differs from the one the DOM version gives | `objects.md`, colour groups |
|
||||
| Order of stories outside the story list | `StoryList` | 2 pairs | open: not explained | IDML lists them in another order than text order | `objects.md`, stories |
|
||||
|
||||
@@ -364,6 +364,17 @@ pub(super) fn variable_name(name: &str) -> String {
|
||||
|
||||
/// Escape a name for use in a `Self` reference (`:` separates style
|
||||
/// groups there).
|
||||
/// Names joined into the IDML name of a style or style group: `:`
|
||||
/// between them, and `\\:` for a `:` inside one (objects.md, style
|
||||
/// groups).
|
||||
pub(super) fn style_path<'a>(names: impl IntoIterator<Item = &'a str>) -> String {
|
||||
names
|
||||
.into_iter()
|
||||
.map(|n| n.replace(':', "\\:"))
|
||||
.collect::<Vec<_>>()
|
||||
.join(":")
|
||||
}
|
||||
|
||||
pub(super) fn self_name(name: &str) -> String {
|
||||
name.replace('%', "%25")
|
||||
.replace(':', "%3a")
|
||||
@@ -427,6 +438,13 @@ impl Writer<'_> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn escapes_a_colon_inside_a_style_or_group_name() {
|
||||
let name = style_path(["a: b", "c"]);
|
||||
assert_eq!(name, "a\\: b:c");
|
||||
assert_eq!(self_name(&name), "a\\%3a b%3ac");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sets_the_baseline_frame_grid_colour() {
|
||||
use crate::model::prefs::FrameGridColor;
|
||||
|
||||
+2
-5
@@ -166,11 +166,8 @@ impl Writer<'_> {
|
||||
/// `$ID/` first for a built-in style. Its `Self` is this name escaped
|
||||
/// with `self_name` (`docs/format/objects.md`, style groups).
|
||||
fn grouped_name(&self, uid: u32, name: &str, builtin: bool) -> String {
|
||||
let mut parts: Vec<String> = self.group_path.get(&uid).map_or(Vec::new(), |p| {
|
||||
p.iter().map(|g| g.replace(':', "\\:")).collect()
|
||||
});
|
||||
parts.push(name.replace(':', "\\:"));
|
||||
let joined = parts.join(":");
|
||||
let groups = self.group_path.get(&uid).map_or(&[][..], Vec::as_slice);
|
||||
let joined = style_path(groups.iter().map(String::as_str).chain([name]));
|
||||
if builtin {
|
||||
builtin_key(&joined)
|
||||
} else {
|
||||
|
||||
+13
-24
@@ -895,19 +895,9 @@ impl Writer<'_> {
|
||||
for &c in &g.children {
|
||||
if let Some(sub) = self.doc.style_groups.get(&c) {
|
||||
let sub_tag = format!("{tag}Group");
|
||||
let path = self.group_path.get(&sub.uid).cloned().unwrap_or_default();
|
||||
// A nested group's name is its full path (objects.md,
|
||||
// style groups).
|
||||
let name = if path.is_empty() {
|
||||
sub.name.clone()
|
||||
} else {
|
||||
path.join(":")
|
||||
};
|
||||
let name = self.group_name(sub);
|
||||
x.start(&sub_tag)
|
||||
.attr(
|
||||
"Self",
|
||||
format!("{sub_tag}/$ID/{}", self_name(&path.join(":"))),
|
||||
)
|
||||
.attr("Self", format!("{sub_tag}/$ID/{}", self_name(&name)))
|
||||
.attr("Name", builtin_key(&name));
|
||||
self.table_style_group_children(x, sub, tag, styles, seen);
|
||||
x.end();
|
||||
@@ -919,6 +909,15 @@ impl Writer<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The IDML name of a style group: the names of the groups on its
|
||||
/// path and its own (objects.md, style groups).
|
||||
fn group_name(&self, g: &StyleGroup) -> String {
|
||||
self.group_path.get(&g.uid).map_or_else(
|
||||
|| style_path([g.name.as_str()]),
|
||||
|p| style_path(p.iter().map(String::as_str)),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn style_group_children(
|
||||
&self,
|
||||
x: &mut Xml,
|
||||
@@ -929,19 +928,9 @@ impl Writer<'_> {
|
||||
) {
|
||||
for &c in &g.children {
|
||||
if let Some(sub) = self.doc.style_groups.get(&c) {
|
||||
let path = self.group_path.get(&sub.uid).cloned().unwrap_or_default();
|
||||
// A nested group's name is its full path (objects.md,
|
||||
// style groups).
|
||||
let name = if path.is_empty() {
|
||||
sub.name.clone()
|
||||
} else {
|
||||
path.join(":")
|
||||
};
|
||||
let name = self.group_name(sub);
|
||||
x.start(sub_tag)
|
||||
.attr(
|
||||
"Self",
|
||||
format!("{sub_tag}/$ID/{}", self_name(&path.join(":"))),
|
||||
)
|
||||
.attr("Self", format!("{sub_tag}/$ID/{}", self_name(&name)))
|
||||
.attr("Name", builtin_key(&name));
|
||||
self.style_group_children(x, sub, tag, sub_tag, written);
|
||||
x.end();
|
||||
|
||||
Reference in new issue
Block a user