Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,20 @@ const emStrongRDelimAst = edit(emStrongRDelimAstCore, 'gu')
.replace(/punct/g, _punctuation)
.getRegex();

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();
Comment on lines +314 to +326
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.


const emStrongRDelimAstGfm = edit(emStrongRDelimAstCore, 'gu')
.replace(/notPunctSpace/g, _notPunctuationOrSpaceGfmStrongEm)
.replace(/punctSpace/g, _punctuationOrSpaceGfmStrongEm)
Expand Down Expand Up @@ -433,6 +447,7 @@ type InlineKeys = keyof typeof inlineNormal;

const inlinePedantic: Record<InlineKeys, RegExp> = {
...inlineNormal,
emStrongRDelimAst: emStrongRDelimAstPedantic,
link: edit(/^!?\[(label)\]\((.*?)\)/)
.replace('label', _inlineLabel)
.getRegex(),
Expand Down
3 changes: 3 additions & 0 deletions test/specs/original/strong_punctuation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p><strong>foo:</strong>bar</p>

<p><strong>foo</strong>bar</p>
7 changes: 7 additions & 0 deletions test/specs/original/strong_punctuation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
pedantic: true
---

**foo:**bar

**foo**bar