Conversation
This was referenced Sep 24, 2026
DanTup
marked this pull request as ready for review
September 24, 2026 10:40
Contributor
There was a problem hiding this comment.
Code Review
This pull request improves syntax highlighting for fenced code blocks in Dart doc comments that use more than three backticks by updating the Dart syntax definition and modifying the multiline matcher to resolve backreferences in the closing regex. A critical issue was identified in span_parser.dart where accessing beginMatch.group(groupIndex) without checking the group count could throw a RangeError, and a guard condition was suggested to prevent this.
It won't happen here, but if the grammar somehow referenced a match that didn't exist
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: This is largely a copy of the same changes in dart-lang/dart-syntax-highlight#98. The grammar file lives over there but is copied into here to be used by the debugger syntax highlighting, and the grammar parser lives here but is copied over there to be used for tests. If you are reviewing one of these PRs, it might make sense to also review the other :-)
Code blocks can use more than three backticks in markdown so that triple-backticks can appear inside the content. They can also be closed with any number of backticks as long as it is more than the number that opened it.
I've committed this in two parts to make reviewing the diff easier. The first commit adds some additional tests and captures their golden output, the second commit has the fix and updated golden output. By reviewing them individually, it may be clearer what changed.
I also had to update the Dart implementation of the grammar parser to support using the
\\1reference inendto read the number of backticks frombegin. This is consistent with the behaviour in VS Code (as can be seen in the screenshots below, which are rendered using VS Code's grammar parser - ours here is used only for tests here, but also for the highlighting in DevTools).Before (the orange areas should all be a single code block):
After:
Related PRs: