+test('Test for backticks only tab characters inside it', () => {
+ const testString = '`\u0009`';
+ const resultString = '`\u0009`';
expect(parser.replace(testString)).toBe(resultString);
});
-// Code-fence with no content is not replaced with
-test('Test for codefence with no content', () => {
+// Backticks with only space characters are replaced with
+test('Test for backticks with only space characters as content', () => {
+ const testString = '` `';
+ const resultString = '
';
+ expect(parser.replace(testString)).toBe(resultString);
+});
+
+// Code-fence with spaces as content
+test('Test for inline code block with triple backtick with spaces as content', () => {
const testString = '``` ```';
- const resultString = '``` ```';
+ const resultString = '`` ``
';
expect(parser.replace(testString)).toBe(resultString);
});
diff --git a/lib/ExpensiMark.ts b/lib/ExpensiMark.ts
index 9435a5e3..0a17a763 100644
--- a/lib/ExpensiMark.ts
+++ b/lib/ExpensiMark.ts
@@ -190,8 +190,13 @@ 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 tags between them.
- regex: /(\B|_|)`((?:`)*)(?!`)(.*?\S+?.*?)(?|[^<]*<\/video>)/gm,
- replacement: '$1$2$3$4
$6',
+ // At least one non-whitespace character or a specific whitespace character (" " and "\u00A0")
+ // must be present inside the backticks.
+ regex: /(\B|_|)`((?:`)*(?!`).*?[\S| |\u00A0]+?.*?(?|[^<]*<\/video>)/gm,
+ replacement: (_extras, _match, g1, g2, g3) => {
+ const g2Value = g2.trim() === '' ? g2.replaceAll(' ', ' ') : g2;
+ return `${g1}${g2Value}
${g3}`;
+ },
},
/**