Skip to content

[markdown] Track offset/length for inline code spans - #2529

Closed
FMorschel wants to merge 5 commits into
dart-lang:mainfrom
FMorschel:code-parsing
Closed

FMorschel wants to merge 5 commits into
dart-lang:mainfrom
FMorschel:code-parsing

Conversation

@FMorschel

@FMorschel FMorschel commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Replaced by: #2530

Fixes part of #1287.

This is the initial work that covers tracking the offset/length of inline code spans.


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

Note: The Dart team is trialing Gemini Code Assist. Don't take its comments as final Dart team feedback. Use the suggestions if they're helpful; otherwise, wait for a human reviewer.

@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 introduces source offset and length tracking for inline code spans in the markdown package, and improves error recovery for list entries missing the - prefix in the yaml package. Feedback on the changes highlights a critical bug in code_syntax.dart where accessing match.match will cause an error, suggesting match[0]!.length instead. Additionally, the reviewer notes that the yaml package updates are out of scope for this pull request and recommends moving them to a separate PR.

final offsetMapper = parser.offsetMapper;
if (offsetMapper != null) {
final matchStart = parser.pos;
final matchEnd = matchStart + match.match.length;

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.

critical

The match variable is an instance of Match from dart:core, which does not have a match property. Accessing match.match will result in a compile-time error or a runtime NoSuchMethodError. It should be replaced with match[0]!.length to get the length of the matched string.

Suggested change
final matchEnd = matchStart + match.match.length;
final matchEnd = matchStart + match[0]!.length;

Comment on lines +386 to +390
if (token.type == TokenType.key) {
_scanner.scan();
_states.add(_State.BLOCK_SEQUENCE_ENTRY);
return _parseNode(block: true);
}

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.

medium

This change in the yaml package is out of scope for this pull request, which is focused on tracking offset/length for inline code spans in the markdown package. Per the general rules, please avoid addressing out-of-scope issues in the same PR and move these changes to a separate pull request.

References
  1. Avoid addressing pre-existing, out-of-scope issues within a pull request. Keep the changes focused on the PR's primary objective and address pre-existing issues in separate pull requests.

Comment on lines +141 to +143
final _indentLevels = <({int column, TokenType? type})>[
(column: -1, type: null),
];

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.

medium

This change in the yaml package is out of scope for this pull request, which is focused on tracking offset/length for inline code spans in the markdown package. Per the general rules, please avoid addressing out-of-scope issues in the same PR and move these changes to a separate pull request.

References
  1. Avoid addressing pre-existing, out-of-scope issues within a pull request. Keep the changes focused on the PR's primary objective and address pre-existing issues in separate pull requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant