Skip to content

fix: parse *** and ___ as nested bold+italic - #124

Open
Ultroncn wants to merge 4 commits into
developit:mainfrom
Ultroncn:fix/triple-emphasis
Open

Ultroncn wants to merge 4 commits into
developit:mainfrom
Ultroncn:fix/triple-emphasis

Conversation

@Ultroncn

Copy link
Copy Markdown

Fixes #113.

***text*** currently renders as <strong><em>text<strong><em></em></strong></em></strong>: the tokenizer splits the run into ** + *, and the closing run cannot unwind the stack in that order, so the closers are emitted as openers.

This matches ***/___ as a single token (before **/__) and handles it in tag() as one combined <em><strong> pair, so ***text*** now renders as <em><strong>text</strong></em> (and likewise for ___). Plain **/__/*/_ parsing is untouched.

Tests: 2 new tests in test/index.js. Verified by control experiment: both fail on unpatched code; full suite passes after the fix (35 passing, was 33), and eslint src test is clean.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 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-18T20:07:12.782438Z b3906f1 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: f33d2fd730

ℹ️ 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
Comment on lines +37 to +39
let end = context[context.length-1] == token;
if (end) context.pop();
else context.push(token);

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 Preserve existing emphasis contexts when consuming triple delimiters

For valid nested emphasis such as *italic **bold*** normal (and the underscore equivalent), the stack contains '*' and '**' when the closing triple run arrives. Neither entry equals '***', so this branch opens another pair instead of closing the existing tags, incorrectly keeping normal bold and italic until the end of the input. The parent renders this correctly. Triple runs need to interact with existing single/double contexts rather than act as indivisible markers; the reverse case, ***bold* italic** normal, also regresses because its separate closing markers cannot close the combined context.

Useful? React with 👍 / 👎.

@Ultroncn

Copy link
Copy Markdown
Author

Thanks for catching this — you were right, both cases regressed: *italic **bold*** normal and ***bold* italic** normal kept normal inside the bold+italic tags, while the parent rendered them correctly.

Fixed in e1c57f1:

  • A triple run (***/___) now closes an already-open single+double pair instead of opening another pair.
  • A single/double run now closes just its half of an open triple pair when it cannot open a nested run (followed by whitespace or end of input).
  • Added two regression tests for both cases; npm test is 37/37 green, including the PR's original ***/___ tests.

@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: e1c57f119b

ℹ️ 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
Comment on lines +55 to +56
context.push(token);
return '<em><strong>';

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 Split triple runs that join bold and italic spans

For adjacent formatting such as **bold***italic* normal, the stack contains only ** when the triple run arrives. The new pair-closing checks require two stacked markers, so this fallback opens another <em><strong> pair instead of closing bold and starting italics. The parent returns <strong>bold</strong><em>italic</em> normal, while this version leaves the original <strong> open through normal. Handle the close-then-open split against a lone existing delimiter before opening a combined pair.

Useful? React with 👍 / 👎.

Comment thread src/index.js Outdated
let top = context[context.length-1];
if ((top === '***' || top === '___') && token[0] === top[0]) {
let next = md[tokenizer.lastIndex];
if (next === undefined || /\s/.test(next)) {

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 Recognize partial triple closers before punctuation

The new whitespace-only guard rejects a valid partial closer followed by punctuation, such as the * in ***bold*, italic** normal. Because the next character is a comma, the closer falls through and opens another <em> instead. The parent closes both spans before normal, but this version keeps normal bold and italic until flush(). Recognize valid closing boundaries rather than treating every non-whitespace successor as evidence of an opening delimiter.

Useful? React with 👍 / 👎.

@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: 599d887b7b

ℹ️ 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
/** 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)|(?:^``` *(\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,

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 Preserve double-delimiter boundaries in longer runs

For previously supported input such as **first****second** plain, the new alternative consumes the four-character boundary as *** + * rather than ** + **. The output changes from <strong>first</strong><strong>second</strong> plain to <strong>first</strong><em></em>second<strong> plain</strong>: second loses bold and the unformatted suffix becomes bold. The underscore equivalent regresses too. Account for longer delimiter runs before treating a three-character prefix as a combined emphasis token.

Useful? React with 👍 / 👎.

@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: b3906f1d72

ℹ️ 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
let top = context[context.length-1];
if ((top === '***' || top === '___') && token[0] === top[0]) {
let before = md.charAt(last-token.length-1), next = md.charAt(last);
if (!next || /\s/.test(next) || (/\S/.test(before) && /[!-/:-@[-`{-~]/.test(next))) {

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 partial asterisk closers within words

For valid intraword asterisk emphasis such as ***bold*ness** normal, the single * must close italics even though the next character is n. The updated boundary guard rejects this alphanumeric-successor case and opens another <em> instead, leaving normal bold and italic until flush(). The parent correctly renders <strong><em>bold</em>ness</strong> normal. Recognize right-flanking asterisk closers within words rather than requiring whitespace or punctuation after them.

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.

The output for nested italic and bold is incorrect.

1 participant