feat: map code block source ranges - #72
Merged
Merged
Conversation
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.
Closes #67.
What changed
Add source mappings for fenced and indented block-code
valuefields.Support
MarkdownSourceMap.getSourceRange()withMarkdownCodeNode.Exclude syntax that does not belong to
code.value, including:Preserve LF, CR, CRLF, blank lines, trailing-line behavior, tab indentation, and per-code-unit mappings.
Support fenced and indented code nested inside blockquotes, lists, and blockquote-list combinations.
Map empty fenced-code values to an accurate content insertion point.
Detect post-parse mutations of mapped
code.valuefields and throwSourceMapConsistencyError.Validate reconstructed source content against the parsed value before accepting a mapping, avoiding fabricated source ranges.
Update the public API report, README, CHANGELOG, and package type-contract tests.
Implementation notes
Code-block mappings are reconstructed from each node’s original source position and parsed value.
The implementation removes container prefixes, fences, and parser-stripped indentation on a line-by-line basis. A mapping is accepted only when the reconstructed source content exactly matches
node.value; otherwise, source mapping remains unavailable rather than returning an incorrect range.Internal source-map segment types remain private.
Test coverage
Added coverage for:
code.valueconsistency errors;parseMd()andparseMdWithSourceMap().Validation
pnpm run lintpnpm run buildpnpm run test