Skip to content

fix: parse pedantic strong punctuation#3959

Open
lawrence3699 wants to merge 1 commit intomarkedjs:masterfrom
lawrence3699:fix/pedantic-strong-punctuation
Open

fix: parse pedantic strong punctuation#3959
lawrence3699 wants to merge 1 commit intomarkedjs:masterfrom
lawrence3699:fix/pedantic-strong-punctuation

Conversation

@lawrence3699
Copy link
Copy Markdown

Marked version:

18.0.2 / master

Markdown flavor: Markdown.pl / pedantic

Description

Fixes #3938.

In pedantic mode, **foo:**bar was still parsed with CommonMark delimiter rules and rendered as literal asterisks:

<p>**foo:**bar</p>

Markdown.pl renders the same input as:

<p><strong>foo:</strong>bar</p>

This adds a pedantic-only asterisk delimiter rule so punctuation before a closing ** can end strong text when the next character is not whitespace. The normal and GFM delimiter rules are unchanged.

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,
  • no tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places.

Validation:

  • npm run build:esbuild && node --test --test-reporter=spec test/run-spec-tests.js
  • npm run test:lint
  • npm test
  • npm run build:reset

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 27, 2026

@lawrence3699 is attempting to deploy a commit to the MarkedJS Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the emStrongRDelimAstPedantic regex to correctly handle asterisk-based strong delimiters in pedantic mode, specifically addressing cases where punctuation precedes the closing delimiter. While this fixes the issue for asterisks, feedback suggests that a similar rule is required for underscore-based delimiters (__) to ensure consistent behavior and parity with Markdown.pl.

Comment thread src/rules.ts
Comment on lines +314 to +326
const emStrongRDelimAstPedantic = edit(
'^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)' // Skip orphan inside strong
+ '|[^*]+(?=[^*])' // Consume to delim
+ '|(?!\\*)punct(\\*+)(?=[\\s]|$)' // (1) #*** can only be a Right Delimiter
+ '|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)' // (2) a***#, a*** can only be a Right Delimiter
+ '|(?!\\*)[\\s](\\*+)(?=notPunctSpace)' // (3) ***a can only be Left Delimiter
+ '|[\\s](\\*+)(?!\\*)(?=punct)' // (4) ***# can only be Left Delimiter
+ '|(?!\\*)punct(\\*+)(?!\\*)(?=punct)' // (5) #***# can be either Left or Right Delimiter
+ '|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)', 'gu') // (6) #***a and a***a can be either Left or Right Delimiter
.replace(/notPunctSpace/g, _notPunctuationOrSpace)
.replace(/punctSpace/g, _punctuationOrSpace)
.replace(/punct/g, _punctuation)
.getRegex();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The new emStrongRDelimAstPedantic regex correctly addresses the issue for asterisk delimiters, but the same problem exists for underscores (e.g., __foo:__bar) in pedantic mode.

In Markdown.pl, __foo:__bar is rendered as <strong>foo:</strong>bar. However, since inlinePedantic still uses the default emStrongRDelimUnd rule, it will incorrectly treat :_ followed by a non-space character as a left-only delimiter (due to Rule 3 in emStrongRDelimUnd).

Consider adding a corresponding emStrongRDelimUndPedantic rule and updating inlinePedantic to include it, ensuring consistent behavior for both types of strong delimiters in pedantic mode.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you also add a test for __foo:__bar and make that work as well? Those should work the same.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marked-website Ready Ready Preview, Comment Apr 27, 2026 2:58pm

Request Review

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.

Issue with colons inside bold tags

2 participants