Skip to content

Commit

Permalink
Merge pull request #785 from tsa321/fixInlineCodeRegexIssue
Browse files Browse the repository at this point in the history
  • Loading branch information
dangrous committed Aug 21, 2024
2 parents c930a76 + 6c7ca24 commit 0ede182
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,24 @@ test('Test for backticks with suffix', () => {
expect(parser.replace(testString)).toBe(resultString);
});

test('Test for backticks with an escaped backtick character inside it', () => {
const testString = 'a `;` abc `:` a';
const resultString = 'a <code>;</code> abc <code>:</code> a';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test for backticks with an escaped backtick character inside it without prefix and suffix', () => {
const testString = '`#` abc `:`';
const resultString = '<code>#</code> abc <code>:</code>';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test for backticks with complete escaped backtick characters inside it', () => {
const testString = 'a `&` b `#` c `x` d `6` e `0` f `;` g `test` h';
const resultString = 'a <code>&amp;</code> b <code>#</code> c <code>x</code> d <code>6</code> e <code>0</code> f <code>;</code> g <code>test</code> h';
expect(parser.replace(testString)).toBe(resultString);
});

// Backticks with no content are not replaced with <code>
test('Test for backticks with no content', () => {
const testString = '` `';
Expand Down
4 changes: 2 additions & 2 deletions lib/ExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,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.
// but we should not replace backtick symbols if they include <pre> tags between them.
regex: /(\B|_|)&#x60;(.*?(?![&#x60;])\S.*?)&#x60;(\B|_|)(?!&#x60;|[^<]*<\/pre>|[^<]*<\/video>)/gm,
replacement: '$1<code>$2</code>$3',
regex: /(\B|_|)&#x60;((?:&#x60;)*)(?!&#x60;)(.*?\S+?.*?)(?<!&#x60;)((?:&#x60;)*)(&#x60;)(\B|_|)(?!&#x60;|[^<]*<\/pre>|[^<]*<\/video>)/gm,
replacement: '$1<code>$2$3$4</code>$6',
},

/**
Expand Down

0 comments on commit 0ede182

Please sign in to comment.