Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<blockquote> Indented<br />No indent<br /> Indented <br /><blockquote> Nested indented </blockquote> Indented </blockquote>';
expect(parser.replace(quoteTestStartString)).toBe(quoteTestReplacedString);
});

test('Single char matching', () => {
const testString = ' *1* char _1_ char ~1~ char';
const resultString = ' <strong>1</strong> char <em>1</em> char <del>1</del> char';
Expand Down Expand Up @@ -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('<blockquote>quote</blockquote><h1>heading 1 after the quote.</h1>Here is a multi-line<br />comment that contains <strong>bold</strong> string.');
expect(parser.replace(testString)).toBe('<blockquote>quote </blockquote><h1>heading 1 after the quote.</h1>Here is a multi-line<br />comment that contains <strong>bold</strong> string.');
Comment thread
Julesssss marked this conversation as resolved.
});

// Valid text that should match for user mentions
Expand Down Expand Up @@ -1862,14 +1868,14 @@ describe('multi-level blockquote', () => {
});
test('multi-level blockquote with multiple spaces', () => {
const quoteTestStartString = '> > > Hello world';
const quoteTestReplacedString = '<blockquote><blockquote><blockquote>Hello world</blockquote></blockquote></blockquote>';
const quoteTestReplacedString = '<blockquote><blockquote><blockquote> Hello world</blockquote></blockquote></blockquote>';

expect(parser.replace(quoteTestStartString)).toBe(quoteTestReplacedString);
});

test('multi-level blockquote with mixed spaces', () => {
const quoteTestStartString = '> > > Hello world';
const quoteTestReplacedString = '<blockquote><blockquote><blockquote>Hello world</blockquote></blockquote></blockquote>';
const quoteTestReplacedString = '<blockquote><blockquote><blockquote> Hello world</blockquote></blockquote></blockquote>';

expect(parser.replace(quoteTestStartString)).toBe(quoteTestReplacedString);
});
Expand Down
12 changes: 9 additions & 3 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -870,11 +870,17 @@ export default class ExpensiMark {
*/
formatTextForQuote(regex, textToCheck, replacement) {
if (textToCheck.match(regex)) {
// Remove '&gt;' and trim each line of quote content
let textToFormat = textToCheck.split('\n').map(row => row.substr(4).trim()).join('\n');
// Remove '&gt;' 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('&gt;')) {
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;
Expand Down