Skip to content

Fix links, xrefs and scripts that font-lock got wrong - #91

Merged
bbatsov merged 4 commits into
masterfrom
fix-inline-macros
Oct 7, 2026
Merged

bbatsov merged 4 commits into
masterfrom
fix-inline-macros

Conversation

@bbatsov

@bbatsov bbatsov commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Fixes #66. Links lost their highlighting and click keymap whenever their text held an apostrophe, an ellipsis, an arrow or other inline markup, because the replacement keywords ran before the macros and reserved those characters. Running replacements after the macros was the fix with the fewest side effects: a face comparison over about 210 real docs found no regressions, and with adoc-insert-replacement on, no overlay lands inside a URL or link text anymore.

Also in here, since they're the same kind of regexp slip: adjacent <<xref>>s ran together, and super/subscripts could span whitespace.

The replacement keywords (`'' apostrophes, `...', `->', `(C)', ...) ran
before the inline macros and reserved their text, and the URL, link,
xref, footnote and image macros refuse to match across reserved text.
So `https://example.org[Bob's page]' wasn't a link at all, and the
bare-URL fallback grabbed `https://example.org[Bob' instead.

Replacements now run after the macros and cross-references, as the
macros may contain them. Macro targets are reserved so replacements
and bare URLs leave them alone, and replacements skip attribute lists
(link text and the like), whose face is applied to the list as a whole
later on. Link text may also hold other already highlighted markup
(`[*bold* text]', a code span). A bare URL can't contain brackets, as
in Asciidoctor.
The font-lock `<<id,caption>>' regexp let the id run across `>>' to
find a comma, so `<<foo>>, <<bar>>' became one xref with the id
`foo>>' and the caption ` <<bar'. The id now stops at `>' and `,' (it
may still wrap onto a second line), and may start with `_', `#', `/',
`.', `:', `{' or a non-ASCII letter like Asciidoctor's, so
`<<_installation>>' is an xref too.
They were highlighted as unconstrained quotes, whose text may span
spaces and lines, so the text between two tildes in
`~/.emacs.d/init.el to ~/backup' came out as a subscript. Asciidoctor
only takes non-whitespace (`\S+?') between the marks. A new
`adoc-script' quote type passes that content regexp to
adoc-re-unconstrained-quote.
adoc-facespec-superscript decided whether to raise the text from the
subscript's entry (car) but raised it by the superscript's (cadr), a
copy-paste slip between the two functions. They now share one
adoc-facespec-script.
@bbatsov
bbatsov merged commit d7ecd11 into master Oct 7, 2026
6 of 8 checks passed
@bbatsov
bbatsov deleted the fix-inline-macros branch October 7, 2026 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Apostrophe in link text breaks link recognition

1 participant