diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js index 2f785e2a..3c0f3dec 100644 --- a/__tests__/ExpensiMark-HTML-test.js +++ b/__tests__/ExpensiMark-HTML-test.js @@ -1698,3 +1698,20 @@ describe('when should keep whitespace flag is enabled', () => { expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString); }); }); + +test('Test code fence within inline code', () => { + let testString = 'Hello world `(```test```)` Hello world'; + expect(parser.replace(testString)).toBe('Hello world `(
test)` Hello world'); + + testString = 'Hello world `(```test\ntest```)` Hello world'; + expect(parser.replace(testString)).toBe('Hello world `(
test)` Hello world'); + + testString = 'Hello world ```(`test`)``` Hello world'; + expect(parser.replace(testString)).toBe('Hello world
test
(`test`)Hello world'); + + testString = 'Hello world `test`space```block``` Hello world'; + expect(parser.replace(testString)).toBe('Hello world
test
spaceblockHello world'); + + testString = 'Hello world ```block```space`test` Hello world'; + expect(parser.replace(testString)).toBe('Hello world
blockspace
test
Hello world');
+});
diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js
index be64ed26..e34bcb7a 100644
--- a/lib/ExpensiMark.js
+++ b/lib/ExpensiMark.js
@@ -47,7 +47,8 @@ export default class ExpensiMark {
// Use the url escaped version of a backtick (`) symbol. Mobile platforms do not support lookbehinds,
// so capture the first and third group and place them in the replacement.
- regex: /(\B|_|)`(.*?\S.*?)`(\B|_|)(?!`|[^<]*<\/pre>)/g,
+ // but we should not replace backtick symbols if they include tags between them. + regex: /(\B|_|)`(?:(?!(?:(?!`).)*?))(.*?\S.*?)`(\B|_|)(?!`|[^<]*<\/pre>)/g, replacement: '$1$2
$3', },