diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js index ed4955bb..7854b552 100644 --- a/__tests__/ExpensiMark-HTML-test.js +++ b/__tests__/ExpensiMark-HTML-test.js @@ -484,20 +484,20 @@ test('Test code fencing with ExpensiMark syntax outside', () => { codeFenceExample = '*Test1 ```\ncode\n``` Test2*'; expect(parser.replace(codeFenceExample)).toBe('*Test1
codeTest2*'); - expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('*Test1
code\nTest2*'); + expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('*Test1
\ncode\nTest2*'); codeFenceExample = '_Test1 ```\ncode\n``` Test2_'; expect(parser.replace(codeFenceExample)).toBe('_Test1
codeTest2_'); - expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('_Test1
code\nTest2_'); + expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('_Test1
\ncode\nTest2_'); codeFenceExample = '~Test1 ```\ncode\n``` Test2~'; expect(parser.replace(codeFenceExample)).toBe('~Test1
codeTest2~'); - expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('~Test1
code\nTest2~'); + expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('~Test1
\ncode\nTest2~'); codeFenceExample = '[```\ncode\n```](google.com)'; expect(parser.replace(codeFenceExample)).toBe('[
code](google.com)'); expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe( - '[
code\n](google.com)', + '[
\ncode\n](google.com)', ); }); @@ -1846,14 +1846,14 @@ describe('when should keep raw input flag is enabled', () => { test('quote with other markdowns', () => { const quoteTestStartString = '> This is a *quote* that started on a new line.\nHere is a >quote that did not\n```\nhere is a codefenced quote\n>it should not be quoted\n```'; const quoteTestReplacedString = - '
This is a quote that started on a new line.\nHere is a >quote that did not\n
here is a codefenced quote\n>it should not be quoted\n'; + '
This is a quote that started on a new line.\nHere is a >quote that did not\n
\nhere is a codefenced quote\n>it should not be quoted\n'; expect(parser.replace(quoteTestStartString, {shouldKeepRawInput: true})).toBe(quoteTestReplacedString); }); test('codeBlock with newlines', () => { const quoteTestStartString = '```\nhello world\n```'; - const quoteTestReplacedString = '
hello world\n'; + const quoteTestReplacedString = '
\nhello world\n'; expect(parser.replace(quoteTestStartString, {shouldKeepRawInput: true})).toBe(quoteTestReplacedString); }); diff --git a/lib/ExpensiMark.ts b/lib/ExpensiMark.ts index e3177cb7..311974cb 100644 --- a/lib/ExpensiMark.ts +++ b/lib/ExpensiMark.ts @@ -129,7 +129,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: /(```(\r\n|\n))((?:\s*?(?!(?:\r\n|\n)?```(?!`))[\S])+\s*?(?:\r\n|\n))(```)/g, // We're using a function here to perform an additional replace on the content // inside the backticks because Android is not able to use
tags and does @@ -137,13 +137,13 @@ export default class ExpensiMark { // with the new lines here since they need to be converted into
. And we don't // want to do this anywhere else since that would break HTML. // will create styling issues so use - replacement: (_extras, _match, _g1, textWithinFences) => { + replacement: (_extras, _match, _g1, _g2, textWithinFences) => { const group = textWithinFences.replace(/(?:(?![\n\r])\s)/g, ' '); return `${group}`; }, - rawInputReplacement: (_extras, _match, _g1, textWithinFences) => { + rawInputReplacement: (_extras, _match, _g1, newLineCharacter, textWithinFences) => { const group = textWithinFences.replace(/(?:(?![\n\r])\s)/g, ' ').replace(/|<\/emoji>/g, ''); - return ` ${group}`; + return `${newLineCharacter}${group}`; }, },