Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

PR-1257: document TOC bookmark ownership across IDML and the createBookmarks default

moppeeer54c369418a46
diff --git a/crates/doc/src/lib.rs b/crates/doc/src/lib.rs
index 00c679ef9..4175776d4 100644
--- a/crates/doc/src/lib.rs
+++ b/crates/doc/src/lib.rs
@@ -807,6 +807,13 @@ pub struct Bookmark {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub children: Vec<Bookmark>,
/// Owned by the document's generated TOC, so updating it preserves manual bookmarks.
+ ///
+ /// Stored only in native files. Bookmarks (and so this flag) are not written to or read
+ /// from IDML yet, so after an IDML round trip the next TOC update builds the outline fresh.
+ /// If IDML bookmark import is added, imported bookmarks arrive with this flag false and the
+ /// next update would keep them as manual and add a second, duplicate outline. That import
+ /// must set this flag on the bookmarks the TOC generated (for example by matching them to
+ /// the TOC entries) when the TOC has `create_bookmarks` on.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub generated_by_toc: bool,
}
diff --git a/crates/engine/src/cmd/toc.rs b/crates/engine/src/cmd/toc.rs
index d3697c677..b69d17e26 100644
--- a/crates/engine/src/cmd/toc.rs
+++ b/crates/engine/src/cmd/toc.rs
@@ -20,7 +20,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Table of Contents…",
["Layout"],
None,
- "{entries: [{style, level?: 1 (1-9), entryStyle?: paragraph style of its entries (default \"TOC Level n\"), pageNumber?: \"after\"|\"before\"|\"none\", separator?: text between entry and number (default a tab), pageNumberStyle?: character style of the page number, separatorStyle?: character style of the separator, sort?: bool (Sort Entries in Alphabetical Order: among their siblings, each with the entries under it)}] | styles: [names] (levels 1, 2, …), title?: \"Contents\", titleStyle?: paragraph style of the title (default \"TOC Title\"), pageNumbers?: true, createBookmarks?: bool (generate PDF bookmarks; keeps the existing setting when omitted), replace?: true (regenerate the existing table of contents in place; false makes a new frame), page?: 1-based page for a new frame (its margins), rect?: [x0,y0,x1,y1] (spread coords)} → {story, entries}",
+ "{entries: [{style, level?: 1 (1-9), entryStyle?: paragraph style of its entries (default \"TOC Level n\"), pageNumber?: \"after\"|\"before\"|\"none\", separator?: text between entry and number (default a tab), pageNumberStyle?: character style of the page number, separatorStyle?: character style of the separator, sort?: bool (Sort Entries in Alphabetical Order: among their siblings, each with the entries under it)}] | styles: [names] (levels 1, 2, …), title?: \"Contents\", titleStyle?: paragraph style of the title (default \"TOC Title\"), pageNumbers?: true, createBookmarks?: bool (generate PDF bookmarks; keeps the existing setting when omitted, which is off for a new table), replace?: true (regenerate the existing table of contents in place; false makes a new frame), page?: 1-based page for a new frame (its margins), rect?: [x0,y0,x1,y1] (spread coords)} → {story, entries}",
has_doc,
generate
),
diff --git a/docs/agents.md b/docs/agents.md
index 532811664..fcfffd933 100644
--- a/docs/agents.md
+++ b/docs/agents.md
@@ -60,8 +60,10 @@ is a PNG of the page; another extension is an error, and nothing runs.
included paragraph styles and their levels. `toc.update` refreshes their titles, hierarchy and
destinations. Refresh keeps the generated outline at its previous position, preserving manual
bookmarks before and after it; disabling the option removes only the generated
-bookmarks. Omitting the parameter keeps the existing TOC setting (false for a new command-created
-TOC). The Table of Contents dialog exposes Create PDF Bookmarks and defaults it on for a new TOC.
+bookmarks. Without `createBookmarks`, `toc.generate` keeps the document's existing TOC setting,
+which is off when there is no TOC yet, so a script that makes a new TOC gets no bookmarks unless
+it passes `createBookmarks: true`. The Table of Contents dialog differs: its Create PDF Bookmarks
+option is on by default for a new TOC, and for an existing one it shows the saved setting.
## Color themes