diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js index db8893afc..c16cdc4b3 100644 --- a/__tests__/ExpensiMark-HTML-test.js +++ b/__tests__/ExpensiMark-HTML-test.js @@ -1090,6 +1090,12 @@ test('Test quotes markdown replacement with text includes blank quotes', () => { expect(parser.replace(testString)).toBe(resultString); }); +test('Test quotes markdown replacement with text includes multiple spaces', () => { + const quoteTestStartString = '> Indented\n>No indent\n> Indented \n> > Nested indented \n> Indented '; + const quoteTestReplacedString = '
Indented
No indent
Indented
Nested indented
Indented
'; + expect(parser.replace(quoteTestStartString)).toBe(quoteTestReplacedString); +}); + test('Single char matching', () => { const testString = ' *1* char _1_ char ~1~ char'; const resultString = ' 1 char 1 char 1 char'; @@ -1164,7 +1170,7 @@ test('Test heading1 markdown replacement with line break before or after the hea test('Test heading1 markdown replacement when heading appear after the quote', () => { const testString = '> quote \n# heading 1 after the quote.\nHere is a multi-line\ncomment that contains *bold* string.'; - expect(parser.replace(testString)).toBe('
quote

heading 1 after the quote.

Here is a multi-line
comment that contains bold string.'); + expect(parser.replace(testString)).toBe('
quote

heading 1 after the quote.

Here is a multi-line
comment that contains bold string.'); }); // Valid text that should match for user mentions @@ -1862,14 +1868,14 @@ describe('multi-level blockquote', () => { }); test('multi-level blockquote with multiple spaces', () => { const quoteTestStartString = '> > > Hello world'; - const quoteTestReplacedString = '
Hello world
'; + const quoteTestReplacedString = '
Hello world
'; expect(parser.replace(quoteTestStartString)).toBe(quoteTestReplacedString); }); test('multi-level blockquote with mixed spaces', () => { const quoteTestStartString = '> > > Hello world'; - const quoteTestReplacedString = '
Hello world
'; + const quoteTestReplacedString = '
Hello world
'; expect(parser.replace(quoteTestStartString)).toBe(quoteTestReplacedString); }); diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index 03324013d..ffd29bb53 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -870,11 +870,17 @@ export default class ExpensiMark { */ formatTextForQuote(regex, textToCheck, replacement) { if (textToCheck.match(regex)) { - // Remove '>' and trim each line of quote content - let textToFormat = textToCheck.split('\n').map(row => row.substr(4).trim()).join('\n'); + // Remove '>' and trim the spaces between nested quotes + let textToFormat = textToCheck.split('\n').map((row) => { + const quoteContent = row[4] === ' ' ? row.substr(5) : row.substr(4); + if (quoteContent.trimStart().startsWith('>')) { + return quoteContent.trimStart(); + } + return quoteContent; + }).join('\n'); // Remove leading and trailing line breaks - textToFormat = textToFormat.trim(); + textToFormat = textToFormat.replace(/^\n+|\n+$/g, ''); return replacement(textToFormat); } return textToCheck;