Repository navigation
Validate line highlight ranges in markdown code blocks - #8780
Open
PrashantSingh2618 wants to merge 1 commit into
Open
PrashantSingh2618 wants to merge 1 commit into
PrashantSingh2618 wants to merge 1 commit into
Conversation
Code fence metadata like `{3,7}` can reference lines past the end of the
code block. The site silently ignores those lines, so the line the author
meant to highlight is never highlighted.
Extend lint-markdown-code-blocks to report highlighted lines outside the
code block, using the same pattern as getHighlightLines() in
CodeBlock.tsx, and fix the three existing cases in the cacheSignal
reference and the "Components and Hooks must be pure" page.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Size changesDetails📦 Next.js Bundle Analysis for react-devThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
This branch was successfully 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.
Code fence highlight metadata like
```js {3,7}can reference lines that don't exist in the code block.getHighlightLines()inCodeBlock.tsxsilently ignores those lines, so the line the author meant to highlight is never highlighted. Nothing catches this today. #8645 added validation for inline[[step, line, "text"]]highlights, but not for line ranges.This PR extends
lint-markdown-code-blocksto report highlighted lines outside the code block. It uses the same pattern asgetHighlightLines(). It also fixes the three existing cases, which have been wrong since the blocks were added:cacheSignal{3,7}on a 4-line block{3}{4}on 3-line blocks, so nothing is highlighted{2}, which highlights the "🔴 never mutate" and "✅ make a copy" linesTest plan
out-of-bounds-line-highlight.mdcovers a single line and the end of a range past the code block. Valid ranges, including one ending on the last line, are added tovalid-highlight.md.src/contentand nothing else.yarn ci-checkpasses.The pre-commit hook ran Prettier on
lint-markdown-code-blocks.test.js, which also reformatted a few existing lines in that file.