Skip to content

fix: require a space after ATX hashes; parse --- after headings and indented code - #120

Open
Ultroncn wants to merge 2 commits into
developit:mainfrom
Ultroncn:fix/heading-space-and-hr-after-blocks
Open

Ultroncn wants to merge 2 commits into
developit:mainfrom
Ultroncn:fix/heading-space-and-hr-after-blocks

Conversation

@Ultroncn

Copy link
Copy Markdown

Fixes #64, #103 and #112.

#64 — #sth is 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 + foo used 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 test passes (36 passing, was 33), including 3 new tests.

…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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T15:34:40.039298Z 4e9312a New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/index.js Outdated
/** 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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/index.js Outdated
/** 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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HR not working after PRE #sth parses as h1 but should be parsed as #sth and # sth should be parsed as h1

1 participant