Skip to content

Readable bookmark names for cross-reference targets in docx output #15331

Open

Description

@cderv

Since Pandoc 3.12, the docx writer starts every bookmark name with _ and replaces any id containing a character other than a letter, digit or _ with a SHA-1 hash (jgm/pandoc@d171c5b, from jgm/pandoc#11845). Quarto 1.12 updates the bundled Pandoc to 3.13 (#15320).

All Quarto cross-reference ids contain - (fig-plot, tbl-cars, sec-intro), so every cross-reference target in a .docx is now a hidden bookmark with a name like _fba68d637b950dddd2fa839b49fee024d186089.

source

toBookmarkName :: Text -> Text
toBookmarkName s
  | T.length s < 40
  , T.all (\c -> isAlphaNum c || c == '_') s
    = "_" <> s
  | otherwise = "_" <> T.pack (drop 1 (show (hashWith SHA1 (fromText s))))

Cross-reference links inside the document still work, as link anchors are hashed the same way. What is lost is any reference to a target by its Quarto id from outside the document:

  • a link like report.docx#fig-plot
  • a Word cross-reference added by hand to a Quarto figure or table, which now requires showing hidden bookmarks and finding the right hash
  • post-processing (officer, VBA, python-docx) that looks a bookmark up by name

We decided to accept the Pandoc change for 1.12 and document it in the changelog. This issue is to collect use cases where the readable name matters. If you rely on one of the above, please describe your workflow here.

If there is demand, we could ask upstream for a readable fallback before hashing, for example fig-plot becoming _fig_plot, still hidden but recognisable. Hashing would remain for collisions or long ids.

Related: jgm/pandoc#6078 (Word cross-reference fields instead of hyperlinks in the docx writer)

Activity

  1. added this to the Future milestone on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    crossrefdocxIssues with the docx formatenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions