Skip to content

Handle code blocks that use > 3 backticks in syntax highlighting - #10021

Open
DanTup wants to merge 4 commits into
flutter:masterfrom
DanTup:handle-more-backticks
Open

DanTup wants to merge 4 commits into
flutter:masterfrom
DanTup:handle-more-backticks

Conversation

@DanTup

@DanTup DanTup commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

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 \\1 reference in end to read the number of backticks from begin. 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):

Screenshot 2026-09-24 110319

After:

Screenshot 2026-09-24 110404

Related PRs:

@DanTup DanTup changed the title Handle more backticks Handle code blocks that use > 3 backticks- #98 Sep 24, 2026
@DanTup DanTup changed the title Handle code blocks that use > 3 backticks- #98 Handle code blocks that use > 3 backticks in syntax highlighting Sep 24, 2026
@DanTup
DanTup marked this pull request as ready for review September 24, 2026 10:40
@DanTup
DanTup requested review from a team and srawlins as code owners September 24, 2026 10:40

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/devtools_app/lib/src/screens/debugger/span_parser.dart Outdated
It won't happen here, but if the grammar somehow referenced a match that didn't exist

This branch has not been deployed

No deployments
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