From 36531c018c1a269607a536922b107d810a026268 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 24 May 2021 19:51:45 +0800 Subject: [PATCH 1/5] Allow code fences without newline chars --- lib/ExpensiMark.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index fc3e36b4..712feef7 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -24,16 +24,15 @@ 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: /```\n((?:(?!```)[\s\S])+)\n```/g, - + regex: /(```[\n]?)((?:(?![\n]?```)[\s\S])+)([\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
                 // not respect whitespace characters at all like HTML does. We do not want to mess
                 // 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: (match, firstCapturedGroup) => { - const group = firstCapturedGroup.replace(/(?:(?![\n\r])\s)/g, ' '); + replacement: (match, _, secondCapturedGroup) => { + const group = secondCapturedGroup.replace(/(?:(?![\n\r])\s)/g, ' '); return `
${group}
`; }, }, From aa2d6aac501452790463b304f29e36d193ca7b7c Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 24 May 2021 19:51:53 +0800 Subject: [PATCH 2/5] Tests --- __tests__/ExpensiMark-test.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/__tests__/ExpensiMark-test.js b/__tests__/ExpensiMark-test.js index 4de8eb1f..a2eeffaf 100644 --- a/__tests__/ExpensiMark-test.js +++ b/__tests__/ExpensiMark-test.js @@ -92,12 +92,24 @@ test('Test period replacements', () => { }); test('Test code fencing', () => { - const codeFenceExampleMarkdown = '```\nconst javaScript = \'javaScript\'\n```'; + let codeFenceExampleMarkdown = '```\nconst javaScript = \'javaScript\'\n```'; + expect(parser.replace(codeFenceExampleMarkdown)).toBe('
const javaScript = 'javaScript'
'); + + codeFenceExampleMarkdown = '```const javaScript = \'javaScript\'\n```'; + expect(parser.replace(codeFenceExampleMarkdown)).toBe('
const javaScript = 'javaScript'
'); + + codeFenceExampleMarkdown = '```\nconst javaScript = \'javaScript\'```'; expect(parser.replace(codeFenceExampleMarkdown)).toBe('
const javaScript = 'javaScript'
'); }); test('Test code fencing with spaces and new lines', () => { - const codeFenceExample = '```\nconst javaScript = \'javaScript\'\n const php = \'php\'\n```'; + let codeFenceExample = '```\nconst javaScript = \'javaScript\'\n const php = \'php\'\n```'; + expect(parser.replace(codeFenceExample)).toBe('
const javaScript = 'javaScript'
const php = 'php'
'); + + codeFenceExample = '```const javaScript = \'javaScript\'\n const php = \'php\'\n```'; + expect(parser.replace(codeFenceExample)).toBe('
const javaScript = 'javaScript'
const php = 'php'
'); + + codeFenceExample = '```\nconst javaScript = \'javaScript\'\n const php = \'php\'```'; expect(parser.replace(codeFenceExample)).toBe('
const javaScript = 'javaScript'
const php = 'php'
'); }); @@ -122,7 +134,13 @@ test('Test inline code blocks inside ExpensiMark', () => { }); test('Test code fencing with ExpensiMark syntax inside', () => { - const codeFenceExample = '```\nThis is how you can write ~strikethrough~, *bold*, _italics_, and [links](https://www.expensify.com)\n```'; + let codeFenceExample = '```\nThis is how you can write ~strikethrough~, *bold*, _italics_, and [links](https://www.expensify.com)\n```'; + expect(parser.replace(codeFenceExample)).toBe('
This is how you can write ~strikethrough~, *bold*, _italics_, and [links](https://www.expensify.com)
'); + + codeFenceExample = '```This is how you can write ~strikethrough~, *bold*, _italics_, and [links](https://www.expensify.com)\n```'; + expect(parser.replace(codeFenceExample)).toBe('
This is how you can write ~strikethrough~, *bold*, _italics_, and [links](https://www.expensify.com)
'); + + codeFenceExample = '```\nThis is how you can write ~strikethrough~, *bold*, _italics_, and [links](https://www.expensify.com)```'; expect(parser.replace(codeFenceExample)).toBe('
This is how you can write ~strikethrough~, *bold*, _italics_, and [links](https://www.expensify.com)
'); }); From 8a70b4a2bf03992b914f6a3deeb60729f4b216b2 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 24 May 2021 19:56:53 +0800 Subject: [PATCH 3/5] Tests --- __tests__/ExpensiMark-test.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/__tests__/ExpensiMark-test.js b/__tests__/ExpensiMark-test.js index a2eeffaf..e4bffea3 100644 --- a/__tests__/ExpensiMark-test.js +++ b/__tests__/ExpensiMark-test.js @@ -100,6 +100,9 @@ test('Test code fencing', () => { codeFenceExampleMarkdown = '```\nconst javaScript = \'javaScript\'```'; expect(parser.replace(codeFenceExampleMarkdown)).toBe('
const javaScript = 'javaScript'
'); + + codeFenceExampleMarkdown = '```const javaScript = \'javaScript\'```'; + expect(parser.replace(codeFenceExampleMarkdown)).toBe('
const javaScript = 'javaScript'
'); }); test('Test code fencing with spaces and new lines', () => { @@ -111,6 +114,9 @@ test('Test code fencing with spaces and new lines', () => { codeFenceExample = '```\nconst javaScript = \'javaScript\'\n const php = \'php\'```'; expect(parser.replace(codeFenceExample)).toBe('
const javaScript = 'javaScript'
const php = 'php'
'); + + codeFenceExample = '```const javaScript = \'javaScript\'\n const php = \'php\'```'; + expect(parser.replace(codeFenceExample)).toBe('
const javaScript = 'javaScript'
const php = 'php'
'); }); test('Test inline code blocks', () => { @@ -142,6 +148,9 @@ test('Test code fencing with ExpensiMark syntax inside', () => { codeFenceExample = '```\nThis is how you can write ~strikethrough~, *bold*, _italics_, and [links](https://www.expensify.com)```'; expect(parser.replace(codeFenceExample)).toBe('
This is how you can write ~strikethrough~, *bold*, _italics_, and [links](https://www.expensify.com)
'); + + codeFenceExample = '```This is how you can write ~strikethrough~, *bold*, _italics_, and [links](https://www.expensify.com)```'; + expect(parser.replace(codeFenceExample)).toBe('
This is how you can write ~strikethrough~, *bold*, _italics_, and [links](https://www.expensify.com)
'); }); test('Test combination replacements', () => { From ff532ebaba22c6dea42def400e37b70c9d73fc25 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 24 May 2021 20:02:01 +0800 Subject: [PATCH 4/5] style --- lib/ExpensiMark.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index 712feef7..624df745 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -25,6 +25,7 @@ export default class ExpensiMark { // < is a backtick symbol we are matching on three of them before then after a new line character regex: /(```[\n]?)((?:(?![\n]?```)[\s\S])+)([\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
                 // not respect whitespace characters at all like HTML does. We do not want to mess

From 49dab320ab89e72615f7406f41beddc2d035b3a1 Mon Sep 17 00:00:00 2001
From: Jasper Huang 
Date: Mon, 24 May 2021 20:04:40 +0800
Subject: [PATCH 5/5] rename variable

---
 lib/ExpensiMark.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js
index 624df745..78d1ff7c 100644
--- a/lib/ExpensiMark.js
+++ b/lib/ExpensiMark.js
@@ -32,8 +32,8 @@ 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: (match, _, secondCapturedGroup) => { - const group = secondCapturedGroup.replace(/(?:(?![\n\r])\s)/g, ' '); + replacement: (match, _, textWithinFences) => { + const group = textWithinFences.replace(/(?:(?![\n\r])\s)/g, ' '); return `
${group}
`; }, },