From 23b47a7ab4fc0f69822d02189487d02e25c71126 Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Mon, 27 May 2024 11:22:20 +0200 Subject: [PATCH 1/3] change blockquote regex --- lib/ExpensiMark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index 4a6a1fe9..e5a2b571 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -239,7 +239,7 @@ export default class ExpensiMark { // block quotes naturally appear on their own line. Blockquotes should not appear in code fences or // inline code blocks. A single prepending space should be stripped if it exists process: (textToProcess, replacement, shouldKeepRawInput = false) => { - const regex = /^(?:>)+ +(?! )(?![^<]*(?:<\/pre>|<\/code>))([^\v\n\r]+)/gm; + const regex = /^(?:>)+ +(?! )(?![^<]*(?:<\/pre>|<\/code>))([^\v\n\r]*)/gm; const replaceFunction = (g1) => replacement(g1, shouldKeepRawInput); if (shouldKeepRawInput) { return textToProcess.replace(regex, replaceFunction); From 106b78b812981f42984d3b13c734ab9ec6569475 Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Mon, 27 May 2024 11:41:05 +0200 Subject: [PATCH 2/3] update tests --- __tests__/ExpensiMark-HTML-test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js index 1a137162..f0da1504 100644 --- a/__tests__/ExpensiMark-HTML-test.js +++ b/__tests__/ExpensiMark-HTML-test.js @@ -1040,15 +1040,15 @@ test('Test quotes markdown replacement and removing
from
 and  {
+test('Test quotes markdown replacement including blank quotes', () => {
     const testString = '> \n>';
-    const resultString = '> 
>'; + const resultString = '
'; expect(parser.replace(testString)).toBe(resultString); }); test('Test quotes markdown replacement with text starts with blank quote', () => { const testString = '> \ntest'; - const resultString = '>
test'; + const resultString = '
test'; expect(parser.replace(testString)).toBe(resultString); }); @@ -1078,7 +1078,7 @@ test('Test quotes markdown replacement with quotes includes multiple middle blan test('Test quotes markdown replacement with text includes blank quotes', () => { const testString = '> \n> quote1 line a\n> quote1 line b\ntest\n> \ntest\n> quote2 line a\n> \n> \n> quote2 line b with an empty line above'; - const resultString = '
quote1 line a
quote1 line b
test
>
test
quote2 line a


quote2 line b with an empty line above
'; + const resultString = '
quote1 line a
quote1 line b
test
test
quote2 line a


quote2 line b with an empty line above
'; expect(parser.replace(testString)).toBe(resultString); }); From 5131c1b998cb249beda95718dabb02d2f5973154 Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Mon, 27 May 2024 12:51:09 +0200 Subject: [PATCH 3/3] revert tests, add condition for blockquotes --- __tests__/ExpensiMark-HTML-test.js | 8 ++++---- lib/ExpensiMark.js | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js index f0da1504..1a137162 100644 --- a/__tests__/ExpensiMark-HTML-test.js +++ b/__tests__/ExpensiMark-HTML-test.js @@ -1040,15 +1040,15 @@ test('Test quotes markdown replacement and removing
from
 and  {
+test('Test quotes markdown replacement skipping blank quotes', () => {
     const testString = '> \n>';
-    const resultString = '
'; + const resultString = '>
>'; expect(parser.replace(testString)).toBe(resultString); }); test('Test quotes markdown replacement with text starts with blank quote', () => { const testString = '> \ntest'; - const resultString = '
test'; + const resultString = '>
test'; expect(parser.replace(testString)).toBe(resultString); }); @@ -1078,7 +1078,7 @@ test('Test quotes markdown replacement with quotes includes multiple middle blan test('Test quotes markdown replacement with text includes blank quotes', () => { const testString = '> \n> quote1 line a\n> quote1 line b\ntest\n> \ntest\n> quote2 line a\n> \n> \n> quote2 line b with an empty line above'; - const resultString = '
quote1 line a
quote1 line b
test
test
quote2 line a


quote2 line b with an empty line above
'; + const resultString = '
quote1 line a
quote1 line b
test
>
test
quote2 line a


quote2 line b with an empty line above
'; expect(parser.replace(testString)).toBe(resultString); }); diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index e5a2b571..8a1e99ca 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -239,10 +239,11 @@ export default class ExpensiMark { // block quotes naturally appear on their own line. Blockquotes should not appear in code fences or // inline code blocks. A single prepending space should be stripped if it exists process: (textToProcess, replacement, shouldKeepRawInput = false) => { - const regex = /^(?:>)+ +(?! )(?![^<]*(?:<\/pre>|<\/code>))([^\v\n\r]*)/gm; + const regex = /^(?:>)+ +(?! )(?![^<]*(?:<\/pre>|<\/code>))([^\v\n\r]+)/gm; const replaceFunction = (g1) => replacement(g1, shouldKeepRawInput); if (shouldKeepRawInput) { - return textToProcess.replace(regex, replaceFunction); + const rawInputRegex = /^(?:>)+ +(?! )(?![^<]*(?:<\/pre>|<\/code>))([^\v\n\r]*)/gm; + return textToProcess.replace(rawInputRegex, replaceFunction); } return this.modifyTextForQuote(regex, textToProcess, replacement); },