Repository navigation
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c8c1a46c0c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| /** Parse Markdown into an HTML String. */ | ||
| export default function parse(md, prevLinks) { | ||
| let tokenizer = /((?:^|\n+)(?:\n---+|\* \*(?: \*)+)\n)|(?:^``` *(\w*)\n([\s\S]*?)\n```$)|((?:(?:^|\n+)(?:\t| {2,}).+)+\n*)|((?:(?:^|\n)([>*+-]|\d+\.)\s+.*)+)|(?:!\[([^\]]*?)\]\(([^)]+?)\))|(\[)|(\](?:\(([^)]+?)\))?)|(?:(?:^|\n+)([^\s].*)\n(-{3,}|={3,})(?:\n+|$))|(?:(?:^|\n+)(#{1,6})\s*(.+)(?:\n+|$))|(?:`([^`].*?)`)|( \n\n*|\n{2,}|__|\*\*|[_*]|~~)/gm, | ||
| let tokenizer = /((?:^|\n+)(?:\n---+|\* \*(?: \*)+)\n)|(?:^```[ \t]*(\w*)[ \t]*\n([\s\S]*?)\n```$)|((?:(?:^|\n+)(?:\t| {2,}).+)+\n*)|((?:(?:^|\n)([>*+-]|\d+\.)\s+.*)+)|(?:!\[([^\]]*?)\]\(([^)]+?)\))|(\[)|(\](?:\(([^)]+?)\))?)|(?:(?:^|\n+)([^\s].*)\n(-{3,}|={3,})(?:\n+|$))|(?:(?:^|\n+)(#{1,6})\s*(.+)(?:\n+|$))|(?:`([^`].*?)`)|( \n\n*|\n{2,}|__|\*\*|[_*]|~~)/gm, |
There was a problem hiding this comment.
Avoid overlapping whitespace matches when the language is absent
For an unclosed fence without a language, the language capture can be empty, allowing both surrounding whitespace repetitions to consume the same characters and causing quadratic backtracking. On Node 24, snarkdown('```' + ' '.repeat(40000) + '\nbody') took about 1.75 seconds at this commit versus 2 ms in its parent. Applications rendering user-supplied Markdown can therefore have their event loop or UI stalled by a small document. Make the nonempty language and its trailing whitespace optional together so that a language-less opener consumes its whitespace only once.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
I checked the whitespace overlap in the diff. I haven’t independently measured the slowdown. Would you be open to a small revision that removes the overlap while preserving support for spaces and tabs around the language name? I'd appreciate your guidance before updating the PR.
Problem
A fenced code block whose info string has spaces around the language name is not recognized at all and passes through literally:
Same for a trailing tab (
js\t`) or spaces on both sides (js). A leading space already worked (^``` (\w)`), the trailing side did not. Reported in #62.Change
One change in the tokenizer in
src/index.js— the fence-opening pattern now allows spaces/tabs on both sides of the language name:Tests
Added a test in
test/index.js(code & quotessuite) covering trailing space, both-side spaces, trailing tab, and a bare fence with a trailing space. Verified it fails on the old code (first assertion: expected literal passthrough to equal the parsed<pre>output). Full suite:npm test(eslint + mocha) — 34 passing, 0 failing.