diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js index 705eaac6..d2d0d2a5 100644 --- a/__tests__/ExpensiMark-HTML-test.js +++ b/__tests__/ExpensiMark-HTML-test.js @@ -468,10 +468,10 @@ test('Test code fencing with spaces and new lines', () => { expect(parser.replace(codeFenceExample)).toBe('
# test'); codeFenceExample = '``` \r\n# test\r\n```'; - expect(parser.replace(codeFenceExample)).toBe('
# test'); + expect(parser.replace(codeFenceExample)).toBe('```
# test'); + expect(parser.replace(codeFenceExample)).toBe('```test
'); @@ -535,24 +535,24 @@ test('Test code fencing with ExpensiMark syntax inside', () => { test('Test code fencing with ExpensiMark syntax outside', () => { let codeFenceExample = '# Test1 ```\ncode\n``` Test2'; - expect(parser.replace(codeFenceExample)).toBe('
# test
codeTest2'); + expect(parser.replace(codeFenceExample)).toBe('
codeTest2*'); - expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('*Test1
\ncode\nTest2*'); + codeFenceExample = '*Test1\n```\ncode\n```\nTest2*'; + expect(parser.replace(codeFenceExample)).toBe('*Test1
codeTest2*'); + expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('*Test1\n
\ncode\n\nTest2*'); - codeFenceExample = '_Test1 ```\ncode\n``` Test2_'; - expect(parser.replace(codeFenceExample)).toBe('_Test1
codeTest2_'); - expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('_Test1
\ncode\nTest2_'); + codeFenceExample = '_Test1\n```\ncode\n```\nTest2_'; + expect(parser.replace(codeFenceExample)).toBe('_Test1
codeTest2_'); + expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('_Test1\n
\ncode\n\nTest2_'); - codeFenceExample = '~Test1 ```\ncode\n``` Test2~'; - expect(parser.replace(codeFenceExample)).toBe('~Test1
codeTest2~'); - expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('~Test1
\ncode\nTest2~'); + codeFenceExample = '~Test1\n```\ncode\n```\nTest2~'; + expect(parser.replace(codeFenceExample)).toBe('~Test1
codeTest2~'); + expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('~Test1\n
\ncode\n\nTest2~'); - codeFenceExample = '[```\ncode\n```](google.com)'; - expect(parser.replace(codeFenceExample)).toBe('[
code](google.com)'); + codeFenceExample = '[\n```\ncode\n```\n](google.com)'; + expect(parser.replace(codeFenceExample)).toBe('[
code](google.com)'); expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe( - '[
\ncode\n](google.com)', + '[\n
\ncode\n\n](google.com)', ); }); @@ -1753,11 +1753,11 @@ test('Test here mention with @here@here', () => { }); test('Test link with code fence inside the alias text part', () => { - const testString = '[```\ncode\n```](google.com) ' + '[test ```\ncode\n``` test](google.com)'; + const testString = '[\n```\ncode\n```](google.com) ' + '[test\n```\ncode\n``` test](google.com)'; const resultString = - '[
code](google.com) ' + - '[test
codetest](google.com)'; + '[
code](google.com) ' + + '[test
codetest](google.com)'; expect(parser.replace(testString)).toBe(resultString); }); @@ -1820,11 +1820,11 @@ test('Linebreak between end of text and start of code block should be remained', }, { testString: 'text1```\ncode\n```text2', - resultString: 'text1
codetext2', + resultString: 'text1```
codetext2', + resultString: 'text1 ```
, , , and tag', () => {
const testString =
- '`code`test@gmail.com ' +
- '```\ncode block\n```test@gmail.com ' +
+ '`code`test@gmail.com\n' +
+ '```\ncode block\n``` test@gmail.com ' +
'[Google](https://google.com)test@gmail.com ' +
'_test@gmail.com_ ' +
'_test\n\ntest@gmail.com_ ' +
- '`test@expensify.com` ' +
- '```\ntest@expensify.com\n``` ' +
+ '`test@expensify.com`\n' +
+ '```\ntest@expensify.com\n```\n' +
'@test@expensify.com ' +
'_@username@expensify.com_ ' +
'[https://staging.new.expensify.com/details/test@expensify.com](https://staging.new.expensify.com/details/test@expensify.com) ' +
'[test italic style wrap email _test@gmail.com_ inside a link](https://google.com) ';
const resultString =
- 'codetest@gmail.com ' +
- 'code block
test@gmail.com ' +
+ 'codetest@gmail.com
' +
+ 'code block
test@gmail.com ' +
'Googletest@gmail.com ' +
'test@gmail.com ' +
'test
test@gmail.com ' +
- 'test@expensify.com ' +
- 'test@expensify.com
' +
+ 'test@expensify.com
' +
+ 'test@expensify.com
' +
'@test@expensify.com ' +
'@username@expensify.com ' +
'https://staging.new.expensify.com/details/test@expensify.com ' +
@@ -2074,19 +2074,22 @@ describe('when should keep raw input flag is enabled', () => {
test('Test code fence within inline code', () => {
let testString = 'Hello world `(```\ntest\n```)` Hello world';
- expect(parser.replace(testString)).toBe('Hello world `(test
)` Hello world');
+ expect(parser.replace(testString)).toBe('Hello world (``
test
``) Hello world');
testString = 'Hello world `(```\ntest\ntest\n```)` Hello world';
- expect(parser.replace(testString)).toBe('Hello world `(test
test
)` Hello world');
+ expect(parser.replace(testString)).toBe('Hello world (``
test
test
``) Hello world');
testString = 'Hello world ```\n(`test`)\n``` Hello world';
- expect(parser.replace(testString)).toBe('Hello world (`test`)
Hello world');
+ expect(parser.replace(testString)).toBe('Hello world ```
(test)
``` Hello world');
testString = 'Hello world `test`space```\nblock\n``` Hello world';
- expect(parser.replace(testString)).toBe('Hello world testspaceblock
Hello world');
+ expect(parser.replace(testString)).toBe('Hello world testspace```
block
``` Hello world');
testString = 'Hello world ```\nblock\n```space`test` Hello world';
- expect(parser.replace(testString)).toBe('Hello world block
spacetest Hello world');
+ expect(parser.replace(testString)).toBe('Hello world ```
block
``spacetest` Hello world');
+
+ testString = 'Hello world `\n```\nblock\n```\n` space`test` Hello world';
+ expect(parser.replace(testString)).toBe('Hello world `
block
spacetest` Hello world');
});
test('Test italic/bold/strikethrough markdown to keep consistency', () => {
diff --git a/lib/ExpensiMark.ts b/lib/ExpensiMark.ts
index bb392659..5ec04af6 100644
--- a/lib/ExpensiMark.ts
+++ b/lib/ExpensiMark.ts
@@ -171,7 +171,7 @@ export default class ExpensiMark {
name: 'codeFence',
// ` is a backtick symbol we are matching on three of them before then after a new line character
- regex: /(```.*?(\r\n|\n))((?:\s*?(?!(?:\r\n|\n)?```(?!`))[\S])+\s*?(?:\r\n|\n))(```)/g,
+ regex: /(? tags and does