Skip to content

syntax: bound markdownLinkText start lookahead to a single line - #231

Open
jvoisin wants to merge 1 commit into
tpope:masterfrom
jvoisin:sped
Open

syntax: bound markdownLinkText start lookahead to a single line#231
jvoisin wants to merge 1 commit into
tpope:masterfrom
jvoisin:sped

Conversation

@jvoisin

@jvoisin jvoisin commented Aug 26, 2026

Copy link
Copy Markdown

The markdownLinkText region validates an opening '[' with a lookahead that scans for a matching ']' followed by '[' or '('. Its inner character classes used the multi-line form _[^][], so an unmatched '[' made the lookahead scan forward across the rest of the buffer, both dominating markdownLinkText cost on bracket-heavy files and bleeding link highlighting onto following lines.

Make the three inner classes in the start lookahead single-line ([^][]). The end pattern is already single-line, so this only tightens where a region may begin.

Inline, nested (a [b] c), reference ([text][ref]), and image links classify identically. Multi-line link text (opening '[' and closing ']' on different lines) is no longer highlighted; it is valid CommonMark but uncommon, and this syntax's inline handling is otherwise line-oriented. A stray unclosed '[' no longer bleeds onto later lines.

syntime (markdownLinkText total) on a 6000-line link-heavy corpus: ~0.0805s -> ~0.0617s (-23%).

The markdownLinkText region validates an opening '[' with a lookahead
that scans for a matching ']' followed by '[' or '('. Its inner
character classes used the multi-line form \_[^][], so an unmatched '['
made the lookahead scan forward across the rest of the buffer, both
dominating markdownLinkText cost on bracket-heavy files and bleeding
link highlighting onto following lines.

Make the three inner classes in the start lookahead single-line
([^][]). The end pattern is already single-line, so this only tightens
where a region may begin.

Inline, nested ([a [b] c](url)), reference ([text][ref]), and image
links classify identically. Multi-line link text (opening '[' and
closing ']' on different lines) is no longer highlighted; it is valid
CommonMark but uncommon, and this syntax's inline handling is otherwise
line-oriented. A stray unclosed '[' no longer bleeds onto later lines.

syntime (markdownLinkText total) on a 6000-line link-heavy corpus:
~0.0805s -> ~0.0617s (-23%).
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.

1 participant