Repository navigation
Conversation
…ndented code - developit#64: '#sth' no longer parses as a heading. ATX headings now require a space or tab after the hashes, as in CommonMark, so hashtags and similar text stay literal. A hash run followed by a newline no longer swallows the next line as heading text either. - developit#103, developit#112: a '---' thematic break after an ATX heading or an indented code block now parses as <hr />. Both block types swallow the blank line that follows them, which used to leave the rule without the blank line the HR pattern requires; the HR pattern now also matches a rule at the start of a line when the preceding newlines were already consumed. Setext headings ('foo' + '---') are unaffected, and a rule at the start or end of a document now parses too.
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: d82dca4721
ℹ️ 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|^---+(?:\n|$))|(?:^``` *(\w*)\n([\s\S]*?)\n```$)|((?:(?:^|\n+)(?:\t| {2,}).+)+\n*)|((?:(?:^|\n)([>*+-]|\d+\.)\s+.*)+)|(?:!\[([^\]]*?)\]\(([^)]+?)\))|(\[)|(\](?:\(([^)]+?)\))?)|(?:(?:^|\n+)([^\s].*)\n(-{3,}|={3,})(?:\n+|$))|(?:(?:^|\n+)(#{1,6})[ \t]+(.+)(?:\n+|$))|(?:`([^`].*?)`)|( \n\n*|\n{2,}|__|\*\*|[_*]|~~)/gm, |
There was a problem hiding this comment.
Keep horizontal-rule recognition out of heading content
For a heading whose text consists of dashes, such as # ---, the new HR alternative also matches during the recursive parse() call that renders the heading's contents. Consequently, this input now produces <h1><hr /></h1> instead of the previous <h1>---</h1>, removing the title text and inserting a block element inside the heading. Restrict the new HR recognition to block contexts so that heading contents remain inline text.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
I checked this and the empty-heading finding against the base and PR commits. # --- renders as <h1>---</h1> on the base and <h1><hr /></h1> on this PR. Empty ATX headings followed by a space or tab also render as literal text on the PR.
Would you be open to a small follow-up on this PR covering both cases, with focused regression tests? I'd appreciate your guidance on the scope.
| /** 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|^---+(?:\n|$))|(?:^``` *(\w*)\n([\s\S]*?)\n```$)|((?:(?:^|\n+)(?:\t| {2,}).+)+\n*)|((?:(?:^|\n)([>*+-]|\d+\.)\s+.*)+)|(?:!\[([^\]]*?)\]\(([^)]+?)\))|(\[)|(\](?:\(([^)]+?)\))?)|(?:(?:^|\n+)([^\s].*)\n(-{3,}|={3,})(?:\n+|$))|(?:(?:^|\n+)(#{1,6})[ \t]+(.+)(?:\n+|$))|(?:`([^`].*?)`)|( \n\n*|\n{2,}|__|\*\*|[_*]|~~)/gm, |
There was a problem hiding this comment.
Allow empty ATX text after the required separator
For an empty heading at the end of a document, such as # or ##\t, the required separator consumes the only whitespace and (.+) then cannot match. These inputs were rendered as headings before this change, but now emit literal hash characters, even though they satisfy the new separator requirement and are valid empty ATX headings. Allow the content capture to be empty while retaining the mandatory space or tab.
Useful? React with 👍 / 👎.
Fixes #64, #103 and #112.
#64 —
#sthis not a heading. ATX headings now require a space or tab after the#run, as in CommonMark, so hashtags and similar text stay literal. A hash run followed by a newline no longer swallows the next line as heading text either (#+ newline +fooused to render as<h1>foo</h1>).#103, #112 —
---after a heading or an indented code block. Both block types swallow the blank line that follows them, which left the rule without the blank line the HR pattern requires, so it rendered as literal---text (see the sample document in #112, where the rule after### Horizontal Rule (divider)came out as<p>---</p>). The HR pattern now also matches a rule at the start of a line when the preceding newlines were already consumed. Setext headings (foo+---→<h2>) are unaffected, and a rule at the very start or end of a document now parses too.Verified against the full sample document from #112: before, 1
<hr />and one literal---; after, 2<hr />with no other output change. Tests:npm testpasses (36 passing, was 33), including 3 new tests.