Skip to content

Commit

Permalink
Merge pull request #557 from spcheema/fix/21846-heading-after-quote-i…
Browse files Browse the repository at this point in the history
…s-not-rendering

Fix/21846 heading after quote is not rendering
  • Loading branch information
cead22 authored Jul 10, 2023
2 parents e914bd1 + e26fa0b commit 0c685f8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
13 changes: 13 additions & 0 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ test('Test multi-line bold markdown replacement', () => {
expect(parser.replace(testString)).toBe(replacedString);
});

test('Test heading markdown replacement', () => {
let testString = '# Heading should not have new line after it.\n';
expect(parser.replace(testString)).toBe('<h1>Heading should not have new line after it.</h1>');

testString = '# Heading should have only one new line after it.\n\n';
expect(parser.replace(testString)).toBe('<h1>Heading should have only one new line after it.</h1><br />');
});

// Sections starting with > are successfully wrapped with <blockquote></blockquote>
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```';
Expand Down Expand Up @@ -792,6 +800,11 @@ test('Test heading1 markdown replacement with line break before or after the hea
expect(parser.replace(testString)).toBe('test<br /><br /><h1>heading</h1><br />test');
});

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.');
});

// Valid text that should match for user mentions
test('Test for user mention with @username@domain.com', () => {
const testString = '@username@expensify.com';
Expand Down
16 changes: 11 additions & 5 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ export default class ExpensiMark {
return `${g1}<a href="${href}" target="_blank" rel="noreferrer noopener">${g2}</a>${g1}`;
},
},
{
name: 'heading1',
regex: /^# +(?! )((?:(?!<pre>|\n|\r\n).)+)/gm,
replacement: '<h1>$1</h1>',
},
{
name: 'quote',

Expand Down Expand Up @@ -203,11 +208,6 @@ export default class ExpensiMark {
regex: /\B~((?=\S)((~~(?!~)|[^\s~]|\s(?!~))+?))~\B(?![^<]*(<\/pre>|<\/code>|<\/a>))/g,
replacement: (match, g1) => (this.containsNonPairTag(g1) ? match : `<del>${g1}</del>`),
},
{
name: 'heading1',
regex: /^# +(?! )((?:(?!<pre>|\n|\r\n).)+)\n?/gm,
replacement: '<h1>$1</h1>',
},
{
name: 'newline',
regex: /\n/g,
Expand All @@ -225,6 +225,12 @@ export default class ExpensiMark {
regex: /<br\s*[/]?><pre>\s*/gi,
replacement: ' <pre>',
},
{
// We're removing <br /> because when <h1> and <br /> occur together, an extra line is added.
name: 'replaceh1br',
regex: /<\/h1><br\s*[/]?>/gi,
replacement: '</h1>',
},
];

/**
Expand Down

0 comments on commit 0c685f8

Please sign in to comment.