Skip to content

Commit

Permalink
Revert "Fix bold when underscore ahead of asterisk"
Browse files Browse the repository at this point in the history
This reverts commit cb45b5b.
  • Loading branch information
jp928 committed Jul 12, 2024
1 parent cb45b5b commit 101c468
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
6 changes: 0 additions & 6 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ test('Test bold within code blocks is skipped', () => {
expect(parser.replace(testString)).toBe(replacedString);
});

test('Test _ ahead asterisk still result in bold', () => {
const testString = 'bold\n```\n*not a bold*\n```\nThis is _*bold*';
const replacedString = 'bold<br /><pre>*not&#32;a&#32;bold*<br /></pre>This is _<strong>bold</strong>';
expect(parser.replace(testString)).toBe(replacedString);
});

test('Test heading markdown replacement', () => {
let testString = '# Heading should not have new line after it.\n';
expect(parser.replace(testString)).toBe('<h1>Heading should not have new line after it.</h1>');
Expand Down
10 changes: 2 additions & 8 deletions lib/ExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,14 +461,8 @@ export default class ExpensiMark {
// \B will match everything that \b doesn't, so it works
// for * and ~: https://www.rexegg.com/regex-boundaries.html#notb
name: 'bold',
regex: /(?<!<[^>]*)(\b_|\B)\*(?![^<]*(?:<\/pre>|<\/code>|<\/a>))((?![\s*])[\s\S]*?[^\s*](?<!\s))\*\B(?![^<]*>)(?![^<]*(<\/pre>|<\/code>|<\/a>))/g,
replacement: (_extras, match, g1, g2) => {
if (g1.includes('_')) {
return `${g1}<strong>${g2}</strong>`;
}

return g2.includes('</pre>') || this.containsNonPairTag(g2) ? match : `<strong>${g2}</strong>`;
},
regex: /(?<!<[^>]*)\B\*(?![^<]*(?:<\/pre>|<\/code>|<\/a>))((?![\s*])[\s\S]*?[^\s*](?<!\s))\*\B(?![^<]*>)(?![^<]*(<\/pre>|<\/code>|<\/a>))/g,
replacement: (_extras, match, g1) => (g1.includes('</pre>') || this.containsNonPairTag(g1) ? match : `<strong>${g1}</strong>`),
},
{
name: 'strikethrough',
Expand Down

0 comments on commit 101c468

Please sign in to comment.