From df28ecb5a037e02cb792a1c5d204c36baf211b0a Mon Sep 17 00:00:00 2001 From: Robert Kozik Date: Mon, 6 May 2024 22:46:41 +0200 Subject: [PATCH] recognize only blockquotes followed by space --- __tests__/ExpensiMark-HTML-test.js | 58 +++++++++++++++--------------- lib/ExpensiMark.js | 2 +- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js index fab1b0b8..9e8d38fc 100644 --- a/__tests__/ExpensiMark-HTML-test.js +++ b/__tests__/ExpensiMark-HTML-test.js @@ -44,7 +44,7 @@ test('Test heading markdown replacement', () => { // Sections starting with > are successfully wrapped with
test('Test quote markdown replacement', () => { - 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 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.
Here is a >quote that did not
here is a codefenced quote
>it should not be quoted
'; expect(parser.replace(quoteTestStartString)).toBe(quoteTestReplacedString); @@ -1016,7 +1016,7 @@ test('Test autolink replacement to avoid parsing nested links', () => { }); test('Test quotes markdown replacement with text matching inside and outside codefence without spaces', () => { - const testString = 'The next line should be quoted\n>Hello,I’mtext\n```\nThe next line should not be quoted\n>Hello,I’mtext\nsince its inside a codefence```'; + const testString = 'The next line should be quoted\n> Hello,I’mtext\n```\nThe next line should not be quoted\n>Hello,I’mtext\nsince its inside a codefence```'; const resultString = 'The next line should be quoted
Hello,I’mtext
The next line should not be quoted
>Hello,I’mtext
since its inside a codefence
'; @@ -1024,7 +1024,7 @@ test('Test quotes markdown replacement with text matching inside and outside cod }); test('Test quotes markdown replacement with text matching inside and outside codefence at the same line', () => { - const testString = 'The next line should be quoted\n>Hello,I’mtext\nThe next line should not be quoted\n```>Hello,I’mtext```\nsince its inside a codefence'; + const testString = 'The next line should be quoted\n> Hello,I’mtext\nThe next line should not be quoted\n```>Hello,I’mtext```\nsince its inside a codefence'; const resultString = 'The next line should be quoted
Hello,I’mtext
The next line should not be quoted
>Hello,I’mtext
since its inside a codefence'; @@ -1032,7 +1032,7 @@ test('Test quotes markdown replacement with text matching inside and outside cod }); test('Test quotes markdown replacement with text matching inside and outside codefence at the end of the text', () => { - const testString = 'The next line should be quoted\n>Hello,I’mtext\nThe next line should not be quoted\n```>Hello,I’mtext```'; + const testString = 'The next line should be quoted\n> Hello,I’mtext\nThe next line should not be quoted\n```>Hello,I’mtext```'; const resultString = 'The next line should be quoted
Hello,I’mtext
The next line should not be quoted
>Hello,I’mtext
'; @@ -1040,9 +1040,9 @@ test('Test quotes markdown replacement with text matching inside and outside cod }); test('Test quotes markdown replacement with text matching inside and outside codefence with quotes at the end of the text', () => { - const testString = 'The next line should be quoted\n```>Hello,I’mtext```\nThe next line should not be quoted\n>Hello,I’mtext'; + const testString = 'The next line should be quoted\n```> Hello,I’mtext```\nThe next line should not be quoted\n> Hello,I’mtext'; - const resultString = 'The next line should be quoted
>Hello,I’mtext
The next line should not be quoted
Hello,I’mtext
'; + const resultString = 'The next line should be quoted
> Hello,I’mtext
The next line should not be quoted
Hello,I’mtext
'; expect(parser.replace(testString)).toBe(resultString); }); @@ -1068,31 +1068,31 @@ test('Test quotes markdown replacement with text starts with blank quote', () => }); test('Test quotes markdown replacement with quotes starts with blank quote row', () => { - const testString = '> \n>test'; + const testString = '> \n> test'; const resultString = '
test
'; expect(parser.replace(testString)).toBe(resultString); }); test('Test quotes markdown replacement with quotes ends with blank quote rows', () => { - const testString = '>test\n> \n>'; + const testString = '> test\n> \n>'; const resultString = '
test
'; expect(parser.replace(testString)).toBe(resultString); }); test('Test quotes markdown replacement with quotes includes a middle blank quote row', () => { - const testString = '>test\n> \n>test'; + const testString = '> test\n> \n> test'; const resultString = '
test

test
'; expect(parser.replace(testString)).toBe(resultString); }); test('Test quotes markdown replacement with quotes includes multiple middle blank quote rows', () => { - const testString = '>test\n> \n> \n>test\ntest\n>test\n> \n> \n> \n>test'; + const testString = '> test\n> \n> \n> test\ntest\n> test\n> \n> \n> \n> test'; const resultString = '
test


test
test
test



test
'; expect(parser.replace(testString)).toBe(resultString); }); 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 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
'; expect(parser.replace(testString)).toBe(resultString); }); @@ -1687,8 +1687,8 @@ test('Mention', () => { describe('when should keep raw input flag is enabled', () => { test('quote without space', () => { - const quoteTestStartString = '>Hello world'; - const quoteTestReplacedString = '
Hello world
'; + const quoteTestStartString = '> Hello world'; + const quoteTestReplacedString = '
Hello world
'; expect(parser.replace(quoteTestStartString, {shouldKeepRawInput: true})).toBe(quoteTestReplacedString); }); @@ -1708,23 +1708,23 @@ describe('when should keep raw input flag is enabled', () => { }); test('multiple quotes', () => { - const quoteTestStartString = '>Hello my\n>beautiful\n>world\n'; - const quoteTestReplacedString = '
Hello my
\n
beautiful
\n
world
\n'; + const quoteTestStartString = '> Hello my\n> beautiful\n> world\n'; + const quoteTestReplacedString = '
Hello my
\n
beautiful
\n
world
\n'; expect(parser.replace(quoteTestStartString, {shouldKeepRawInput: true})).toBe(quoteTestReplacedString); }); test('separate blockqoutes', () => { - const quoteTestStartString = '>Lorem ipsum\ndolor\n>sit amet'; - const quoteTestReplacedString = '
Lorem ipsum
\ndolor\n
sit amet
'; + const quoteTestStartString = '> Lorem ipsum\ndolor\n> sit amet'; + const quoteTestReplacedString = '
Lorem ipsum
\ndolor\n
sit amet
'; expect(parser.replace(quoteTestStartString, {shouldKeepRawInput: true})).toBe(quoteTestReplacedString); }); describe('nested heading in blockquote', () => { test('without spaces', () => { - const quoteTestStartString = '># Hello world'; - const quoteTestReplacedString = '

Hello world

'; + const quoteTestStartString = '> # Hello world'; + const quoteTestReplacedString = '

Hello world

'; expect(parser.replace(quoteTestStartString, {shouldKeepRawInput: true})).toBe(quoteTestReplacedString); }); @@ -1737,8 +1737,8 @@ describe('when should keep raw input flag is enabled', () => { }); test('with multiple spaces after #', () => { - const quoteTestStartString = '># Hello world'; - const quoteTestReplacedString = '

Hello world

'; + const quoteTestStartString = '> # Hello world'; + const quoteTestReplacedString = '

Hello world

'; expect(parser.replace(quoteTestStartString, {shouldKeepRawInput: true})).toBe(quoteTestReplacedString); }); @@ -1746,30 +1746,30 @@ describe('when should keep raw input flag is enabled', () => { describe('trailing whitespace after blockquote', () => { test('nothing', () => { - const quoteTestStartString = '>Hello world!'; - const quoteTestReplacedString = '
Hello world!
'; + const quoteTestStartString = '> Hello world!'; + const quoteTestReplacedString = '
Hello world!
'; expect(parser.replace(quoteTestStartString, {shouldKeepRawInput: true})).toBe(quoteTestReplacedString); }); test('space', () => { - const quoteTestStartString = '>Hello world '; - const quoteTestReplacedString = '
Hello world
'; + const quoteTestStartString = '> Hello world '; + const quoteTestReplacedString = '
Hello world
'; expect(parser.replace(quoteTestStartString, {shouldKeepRawInput: true})).toBe(quoteTestReplacedString); }); test('newline', () => { - const quoteTestStartString = '>Hello world\n'; - const quoteTestReplacedString = '
Hello world
\n'; + const quoteTestStartString = '> Hello world\n'; + const quoteTestReplacedString = '
Hello world
\n'; expect(parser.replace(quoteTestStartString, {shouldKeepRawInput: true})).toBe(quoteTestReplacedString); }); }); 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
'; + 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
'; expect(parser.replace(quoteTestStartString, {shouldKeepRawInput: true})).toBe(quoteTestReplacedString); }); diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index 5a3d124e..998acf48 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -245,7 +245,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; if (shouldKeepRawInput) { return textToProcess.replace(regex, (g1) => replacement(g1, shouldKeepRawInput)); }