-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #602 from software-mansion-labs/@Skalakid/allow-tr…
…ailing-whitespace-in-blockquote Enhance ExpensiMark blockquote parsing for Live Markdown Preview
- Loading branch information
Showing
2 changed files
with
125 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -674,7 +674,6 @@ test('Test urls with unmatched closing parentheses autolinks correctly', () => { | |
testString: 'google.com/(toto))titi)', | ||
resultString: '<a href="https://google.com/(toto)" target="_blank" rel="noreferrer noopener">google.com/(toto)</a>)titi)', | ||
}, | ||
|
||
]; | ||
testCases.forEach(testCase => { | ||
expect(parser.replace(testCase.testString)).toBe(testCase.resultString); | ||
|
@@ -1609,3 +1608,93 @@ test('Mention', () => { | |
testString = '@[email protected]'; | ||
expect(parser.replace(testString)).toBe('<mention-user>@[email protected]</mention-user>'); | ||
}); | ||
|
||
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 single space', () => { | ||
const quoteTestStartString = '> Hello world'; | ||
const quoteTestReplacedString = '<blockquote> Hello world</blockquote>'; | ||
|
||
expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString); | ||
}); | ||
|
||
test('quote with multiple spaces', () => { | ||
const quoteTestStartString = '> Hello world'; | ||
const quoteTestReplacedString = '<blockquote> Hello world</blockquote>'; | ||
|
||
expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString); | ||
}); | ||
|
||
test('multiple quotes', () => { | ||
const quoteTestStartString = '>Hello my\n>beautiful\n>world\n'; | ||
const quoteTestReplacedString = '<blockquote>Hello my</blockquote>\n<blockquote>beautiful</blockquote>\n<blockquote>world</blockquote>\n'; | ||
|
||
expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString); | ||
}); | ||
|
||
test('separate blockqoutes', () => { | ||
const quoteTestStartString = '>Lorem ipsum\ndolor\n>sit amet'; | ||
const quoteTestReplacedString = '<blockquote>Lorem ipsum</blockquote>\ndolor\n<blockquote>sit amet</blockquote>'; | ||
|
||
expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString); | ||
}); | ||
|
||
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); | ||
}); | ||
|
||
test('with single space', () => { | ||
const quoteTestStartString = '> # Hello world'; | ||
const quoteTestReplacedString = '<blockquote> <h1>Hello world</h1></blockquote>'; | ||
|
||
expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString); | ||
}); | ||
|
||
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); | ||
}); | ||
}); | ||
|
||
describe('trailing whitespace after blockquote', () => { | ||
test('nothing', () => { | ||
const quoteTestStartString = '>Hello world!'; | ||
const quoteTestReplacedString = '<blockquote>Hello world!</blockquote>'; | ||
|
||
expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString); | ||
}); | ||
|
||
test('space', () => { | ||
const quoteTestStartString = '>Hello world '; | ||
const quoteTestReplacedString = '<blockquote>Hello world </blockquote>'; | ||
|
||
expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString); | ||
}); | ||
|
||
test('newline', () => { | ||
const quoteTestStartString = '>Hello world\n'; | ||
const quoteTestReplacedString = '<blockquote>Hello world</blockquote>\n'; | ||
|
||
expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString); | ||
}); | ||
}); | ||
|
||
test('quote with other markdowns', () => { | ||
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```'; | ||
const quoteTestReplacedString = '<blockquote>This is a <strong>quote</strong> that started on a new line.</blockquote>\nHere is a >quote that did not\n<pre>here is a codefenced quote\n>it should not be quoted\n</pre>'; | ||
|
||
expect(parser.replace(quoteTestStartString, {shouldKeepWhitespace: true})).toBe(quoteTestReplacedString); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters