Skip to content

fix(docs): restore code spans by position in heading slugs (#1361) - #1404

Merged
devsuitup merged 5 commits into
mainfrom
fix/1361-doc-refs-slug
Nov 29, 2026
Merged

devsuitup merged 5 commits into
mainfrom
fix/1361-doc-refs-slug

Conversation

@devsuitup

@devsuitup devsuitup commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Closes #1361

Summary

githubSlug sets code spans aside with the private-use markers U+E000 and U+E001 and restores them with a regex. A heading that wrote those characters as entities (Use 0) decoded into a fake marker pair, so the slug came out as use-undefined instead of use-0.

The algorithm is unchanged. The two marker characters are now chosen by trial. Candidates are pairs of private-use characters in U+E000-U+F8FF that pass a cheap pre-filter (absent from the raw heading, its entity-decoded form, and the heading without code spans after renderPlain). Each pair is tried against the real rendering and accepted only if every marker in the output belongs to a well-formed marker, index, marker match whose index is below the span count and used once, with no stray marker left. The function throws if no pair qualifies. Emphasis, link and HTML handling is byte-identical to before for every heading that does not contain the old markers.

Tests

New test in test/check-doc-refs.test.js: the issue's heading gives use-0; through checkDocRefs, #use-0-bar passes and #use-undefined-bar fails. Pinned to the previous outputs: `x`_y_ and _x_`y` give xy, Use [link](`target`) `shown` gives use-link-shown, Use <span title="`hidden`">label</span> `shown` gives use-label-shown; headings where link or tag stripping reassembles (use-x-labela0 for the tag case), &#xE002;0&#xE003; gives use-x-0; plus literal private-use characters, plain digits and an entity next to a code span.

RED on the previous code:

not ok 7 - githubSlug picks markers absent from the decoded heading and keeps the old emphasis, link and tag behaviour
    + actual - expected
  expected: 'use-0'
  actual: 'use-undefined'

(The reassembly case, Use [x](&#xE000;&#xE001;) &#xE[002](a);0&#xE[003](b); expecting use-x-0, was also RED on the previous commit: use-x-undefined.)

GREEN with the fix: check-doc-refs 17/17, check-docs 147/147.

Docs

no docs: docs/changelog.md describes the slug rules (unchanged), not the marker mechanism. No CHANGELOG entry (developer tooling).

Residual

A reassembled marker that reuses the index of a span whose own marker was dropped (for example a span inside a removed link destination) would still pass the consistency check. The previous code had the same residual. No heading triggering it was constructed.

githubSlug swapped code spans for their index as digits and restored every digit run afterwards, so a heading holding its own digits or entity-decoded characters got the wrong text back (use-undefined for 'Use &#xE000;0&#xE001;'). The spans are now marked with a character absent from the heading, syntax is stripped, and the text is split on that mark; entities are decoded per piece and each code span is put back by position.
@devsuitup devsuitup added no-changelog The PR changes nothing a user sees; the CHANGELOG.md check is waived no-docs PR changes code but no user or agent doc needs an update labels Nov 29, 2026
…e decoded heading (#1361)

Back to the original code-span markers and restore regex. The two private-use marker characters are now the first pair that appears neither in the heading nor in its entity-decoded form, so a heading written with &#xE000;0&#xE001; no longer collides. Emphasis, link and tag handling is unchanged.
)

A marker pair is now also rejected when it can appear in the heading's text outside code spans after stripping and entity decoding, so entities split by a link no longer decode into the chosen markers.
…s it consistently (#1361)

Each candidate pair is tried against the real rendering and kept only when every marker in the output belongs to a well-formed marker, index pair with a known span used once. The pre-filter on the heading text stays as a cheap first test.
@devsuitup
devsuitup merged commit ef38df0 into main Nov 29, 2026
15 checks passed
@devsuitup
devsuitup deleted the fix/1361-doc-refs-slug branch November 29, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog The PR changes nothing a user sees; the CHANGELOG.md check is waived no-docs PR changes code but no user or agent doc needs an update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(docs): doc-refs slug placeholders collide with private-use characters written as entities

1 participant