diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js
index 0051dd4c..6c7f8e1b 100644
--- a/__tests__/ExpensiMark-HTML-test.js
+++ b/__tests__/ExpensiMark-HTML-test.js
@@ -26,6 +26,12 @@ 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
*not a bold*
This is _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 fc2cf408..554265b2 100644
--- a/lib/ExpensiMark.ts
+++ b/lib/ExpensiMark.ts
@@ -461,8 +461,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',