diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js index 0051dd4c..df53ba14 100644 --- a/__tests__/ExpensiMark-HTML-test.js +++ b/__tests__/ExpensiMark-HTML-test.js @@ -26,6 +26,24 @@ test('Test bold within code blocks is skipped', () => { expect(parser.replace(testString)).toBe(replacedString); }); +test('Test special character plus _ ahead asterisk still result in bold', () => { + const testString = 'This is a !_*bold*'; + const replacedString = 'This is a !_bold'; + expect(parser.replace(testString)).toBe(replacedString); +}); + +test('Test a word plus _ ahead asterisk not result in bold', () => { + const testString = 'This is not a_*bold*'; + const replacedString = 'This is not a_*bold*'; + expect(parser.replace(testString)).toBe(replacedString); +}); + +test('Test _ ahead asterisk still result in bold', () => { + const testString = 'This is a ~_*bold*'; + const replacedString = 'This is a ~_bold'; + 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('

Heading should not have new line after it.

'); diff --git a/lib/ExpensiMark.ts b/lib/ExpensiMark.ts index 0ffd3758..596af552 100644 --- a/lib/ExpensiMark.ts +++ b/lib/ExpensiMark.ts @@ -468,8 +468,14 @@ 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\*(?![^<]*(?:<\/pre>|<\/code>|<\/a>))((?![\s*])[\s\S]*?[^\s*](?)(?![^<]*(<\/pre>|<\/code>|<\/a>))/g, - replacement: (_extras, match, g1) => (g1.includes('') || this.containsNonPairTag(g1) ? match : `${g1}`), + regex: /(?]*)(\b_|\B)\*(?![^<]*(?:<\/pre>|<\/code>|<\/a>))((?![\s*])[\s\S]*?[^\s*](?)(?![^<]*(<\/pre>|<\/code>|<\/a>))/g, + replacement: (_extras, match, g1, g2) => { + if (g1.includes('_')) { + return `${g1}${g2}`; + } + + return g2.includes('') || this.containsNonPairTag(g2) ? match : `${g2}`; + }, }, { name: 'strikethrough',