Skip to content

Commit

Permalink
add review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid committed Nov 16, 2023
1 parent 0fd258a commit 9589dd9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
40 changes: 21 additions & 19 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1491,22 +1491,22 @@ test('Mention', () => {
expect(parser.replace(testString)).toBe('<mention-user>@[email protected]</mention-user>');
});

describe('edit mode', () => {
describe('when should keep whitespace flag is enabled', () => {
test('quote without space', () => {
const quoteTestStartString = '>Hello world';
const quoteTestReplacedString = '<blockquote>Hello world</blockquote>';

expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString);
});

test('quote with space', () => {
test('quote with single space', () => {
const quoteTestStartString = '> Hello world';
const quoteTestReplacedString = '<blockquote> Hello world</blockquote>';

expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString);
});

test('quote with a lot of spaces', () => {
test('quote with multiple spaces', () => {
const quoteTestStartString = '> Hello world';
const quoteTestReplacedString = '<blockquote> Hello world</blockquote>';

Expand All @@ -1520,35 +1520,37 @@ describe('edit mode', () => {
expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString);
});

test('mixed blocqoutes', () => {
test('separate blockqoutes', () => {
const quoteTestStartString = '>Lorem ipsum\ndolor\n>sit amet';
const quoteTestReplacedString = '<blockquote>Lorem ipsum</blockquote><br />dolor<br /><blockquote>sit amet</blockquote>';

expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString);
});

test('nested quote and heading', () => {
const quoteTestStartString = '># Hello world';
const quoteTestReplacedString = '<blockquote><h1>Hello world</h1></blockquote>';
describe('nested heading in blockquote', () => {
test('without spaces', () => {
const quoteTestStartString = '># Hello world';
const quoteTestReplacedString = '<blockquote><h1>Hello world</h1></blockquote>';

expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString);
});
expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString);
});

test('nested quote and heading with space between', () => {
const quoteTestStartString = '> # Hello world';
const quoteTestReplacedString = '<blockquote> <h1>Hello world</h1></blockquote>';
test('with single space', () => {
const quoteTestStartString = '> # Hello world';
const quoteTestReplacedString = '<blockquote> <h1>Hello world</h1></blockquote>';

expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString);
});
expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString);
});

test('nested quote and heading with many spaces after #', () => {
const quoteTestStartString = '># Hello world';
const quoteTestReplacedString = '<blockquote><h1> Hello world</h1></blockquote>';
test('with multiple spaces after #', () => {
const quoteTestStartString = '># Hello world';
const quoteTestReplacedString = '<blockquote><h1> Hello world</h1></blockquote>';

expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString);
expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString);
});
});

describe('trailing whitespace', () => {
describe('trailing whitespace after blockquote', () => {
test('nothing', () => {
const quoteTestStartString = '>Hello world!';
const quoteTestReplacedString = '<blockquote>Hello world!</blockquote>';
Expand Down
6 changes: 2 additions & 4 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ export default class ExpensiMark {
{
name: 'heading1',
process: (textToProcess, replacement, shouldKeepWhitespace = false) => {
if (shouldKeepWhitespace) {
return textToProcess.replace(/^# ( *(?! )(?:(?!<pre>|\n|\r\n).)+)/gm, replacement);
}
return textToProcess.replace(/^# +(?! )((?:(?!<pre>|\n|\r\n).)+)/gm, replacement);
const regexp = shouldKeepWhitespace ? /^# ( *(?! )(?:(?!<pre>|\n|\r\n).)+)/gm : /^# +(?! )((?:(?!<pre>|\n|\r\n).)+)/gm;
return textToProcess.replace(regexp, replacement);
},
replacement: '<h1>$1</h1>',
},
Expand Down

0 comments on commit 9589dd9

Please sign in to comment.