Skip to main content

Module mark_options

Module mark_options 

Source
Expand description

Named marks a writer anchors into its output as bookmarks — the third export payload, beside comments and images.

§What this is for

A host that exports a document for someone else to edit, and later reads the edited file back, needs to know which part of the returned file corresponds to which part of its own model. Nothing in DOCX or ODF carries that natively, and the obvious answer — a private attribute on the host’s own elements — does not survive: both Word and LibreOffice discard unknown-namespace attributes when they save. Measured, not assumed: a file this crate wrote with a skrb:uid on every <office:annotation> came back from LibreOffice 25.8 with the attribute gone and its namespace declaration gone with it.

A bookmark does survive, because it is not an extension. text:bookmark and w:bookmarkStart are first-class in ODF and OOXML respectively, position-tracked as the editor moves text around, invisible in both readers, and preserved by every writer that claims to support either format. So identity travels as a bookmark, and this is the payload that carries it.

§Point marks and range marks

A mark with start == end is a point: it names a position and nothing else, and is written as a single self-closing element. A mark with start < end is a range, written as a start/end pair bracketing exactly those characters. Both are useful and the difference is not cosmetic — a point mark survives the text around it being rewritten wholesale, while a range mark tells the reader precisely which characters it covered.

§Names are the payload

The name is the only thing that comes back, so it is where the host’s identity has to live. DocumentMark::validate enforces the intersection of what the two formats accept, which is really just what Word accepts — 40 characters, ASCII alphanumerics and underscore, leading letter. ODF is far more permissive, but a name legal in only one of the two would produce a file that round-trips through one editor and loses its identity in the other, which is worse than refusing it.

Structs§

DocumentMark
One named position or range in the document’s addressable character space.
DocumentMarks
Every mark supplied to one export, keyed by name.

Constants§

MAX_BOOKMARK_NAME_LEN
Word’s cap on the length of a bookmark name. Names longer than this are truncated or dropped by Word without a diagnostic, which is exactly the failure this payload exists to avoid.
RESERVED_BOOKMARK_NAMES
Bookmark names Word reserves for itself.