Skip to content

Commit

Permalink
modify quote regex
Browse files Browse the repository at this point in the history
  • Loading branch information
robertKozik committed May 8, 2024
1 parent 831e205 commit f4b1253
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
29 changes: 29 additions & 0 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,35 @@ test('Test quotes markdown replacement with text includes multiple spaces', () =
expect(parser.replace(quoteTestStartString)).toBe(quoteTestReplacedString);
});

test('Test markdown quotes without spaces after > should not be parsed', () => {
const testString = '>test';
const resultString = '>test';
expect(parser.replace(testString)).toBe(resultString);
});
test('Test markdown quotes without spaces after > should not be parsed', () => {
const testString = '>>>test';
const resultString = '>>>test';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test markdown quotes without spaces after > should not be parsed', () => {
const testString = '> >>test';
const resultString = '<blockquote>&gt;&gt;test</blockquote>';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test markdown quotes without spaces after > should not be parsed', () => {
const testString = '> > > test';
const resultString = '<blockquote><blockquote><blockquote>test</blockquote></blockquote></blockquote>';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test markdown quotes without spaces after > should not be parsed', () => {
const testString = '>>> test';
const resultString = '<blockquote><blockquote><blockquote>test</blockquote></blockquote></blockquote>';
expect(parser.replace(testString)).toBe(resultString);
});

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
4 changes: 2 additions & 2 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,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 = /^&gt;[ &gt;]+(?! )(?![^<]*(?:<\/pre>|<\/code>))([^\v\n\r]+)/gm;
const regex = /^(?:&gt;)+ +(?! )(?![^<]*(?:<\/pre>|<\/code>))([^\v\n\r]+)/gm;
const replaceFunction = (g1) => replacement(g1, shouldKeepRawInput);
if (shouldKeepRawInput) {
return textToProcess.replace(regex, replaceFunction);
Expand All @@ -268,7 +268,7 @@ export default class ExpensiMark {
const filterRules = ['heading1'];

// if we don't reach the max quote depth we allow the recursive call to process possible quote
if (this.currentQuoteDepth < this.maxQuoteDepth - 1) {
if (this.currentQuoteDepth < this.maxQuoteDepth - 1 || isStartingWithSpace) {
filterRules.push('quote');
this.currentQuoteDepth++;
}
Expand Down

0 comments on commit f4b1253

Please sign in to comment.