Skip to content

Commit

Permalink
Fix single backtick code block is rendered within a triple backtick c…
Browse files Browse the repository at this point in the history
…ode block when followed by an emoji
  • Loading branch information
ra-md committed Sep 26, 2024
1 parent 7586959 commit bd05025
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,9 @@ test('Test code fencing with additional backticks inside', () => {
expect(parser.replace(nestedBackticks)).toBe(
'<pre>&#x60;This&#32;is&#32;how&#32;you&#32;can&#32;write&#32;~strikethrough~,&#32;*bold*,&#32;_italics_,&#32;and&#32;[links](https://www.expensify.com)&#x60;<br /></pre>',
);

nestedBackticks = '```\n`test`👋\n```';
expect(parser.replace(nestedBackticks)).toBe('<pre>&#x60;test&#x60;<emoji>👋</emoji><br /></pre>');
});

test('Test combination replacements', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/ExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export default class ExpensiMark {
// but we should not replace backtick symbols if they include <pre> tags between them.
// At least one non-whitespace character or a specific whitespace character (" " and "\u00A0")
// must be present inside the backticks.
regex: /(\B|_|)&#x60;((?:&#x60;)*(?!&#x60;).*?[\S| |\u00A0]+?.*?(?<!&#x60;)(?:&#x60;)*)&#x60;(\B|_|)(?!&#x60;|[^<]*<\/pre>|[^<]*<\/video>)/gm,
regex: /(\B|_|)&#x60;((?:&#x60;)*(?!&#x60;).*?[\S| |\u00A0]+?.*?(?<!&#x60;)(?:&#x60;)*)&#x60;(\B|_|)(?!&#x60;|(?!<pre>)[^<]*(?:<(?!pre>)[^<]*)*<\/pre>|[^<]*<\/video>)/gm,
replacement: (_extras, _match, g1, g2, g3) => {
const g2Value = g2.trim() === '' ? g2.replaceAll(' ', '&nbsp;') : g2;
return `${g1}<code>${g2Value}</code>${g3}`;
Expand Down

0 comments on commit bd05025

Please sign in to comment.