Skip to content

Commit 2a8ccd0

Browse files
committed
Support github flavor
1 parent e9fa45e commit 2a8ccd0

File tree

3 files changed

+71
-71
lines changed

3 files changed

+71
-71
lines changed

__tests__/ExpensiMark-HTML-test.js

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const parser = new ExpensiMark();
55

66
// Words wrapped in * successfully replaced with <strong></strong>
77
test('Test bold markdown replacement', () => {
8-
const boldTestStartString = 'This is a *sentence,* and it has some *punctuation, words, and spaces*. ' + '*test* * testing* test*test*test. * testing * *testing *';
8+
const boldTestStartString = 'This is a **sentence,** and it has some **punctuation, words, and spaces**. ' + '**test** * testing* test*test*test. * testing * *testing *';
99
const boldTestReplacedString =
1010
'This is a <strong>sentence,</strong> and it has some <strong>punctuation, words, and spaces</strong>. ' + '<strong>test</strong> * testing* test*test*test. * testing * *testing *';
1111

@@ -14,32 +14,32 @@ test('Test bold markdown replacement', () => {
1414

1515
// Multi-line text wrapped in * is successfully replaced with <strong></strong>
1616
test('Test multi-line bold markdown replacement', () => {
17-
const testString = '*Here is a multi-line\ncomment that should\nbe bold*';
17+
const testString = '**Here is a multi-line\ncomment that should\nbe bold**';
1818
const replacedString = '<strong>Here is a multi-line<br />comment that should<br />be bold</strong>';
1919

2020
expect(parser.replace(testString)).toBe(replacedString);
2121
});
2222

2323
test('Test bold within code blocks is skipped', () => {
24-
const testString = 'bold\n```\n*not a bold*\n```\nThis is *bold*';
24+
const testString = 'bold\n```\n*not a bold*\n```\nThis is **bold**';
2525
const replacedString = 'bold<br /><pre>*not&#32;a&#32;bold*<br /></pre>This is <strong>bold</strong>';
2626
expect(parser.replace(testString)).toBe(replacedString);
2727
});
2828

2929
test('Test special character plus _ ahead asterisk still result in bold', () => {
30-
const testString = 'This is a !_*bold*';
30+
const testString = 'This is a !_**bold**';
3131
const replacedString = 'This is a !_<strong>bold</strong>';
3232
expect(parser.replace(testString)).toBe(replacedString);
3333
});
3434

3535
test('Test a word plus _ ahead asterisk not result in bold', () => {
36-
const testString = 'This is not a_*bold*';
37-
const replacedString = 'This is not a_*bold*';
36+
const testString = 'This is not a_**bold**';
37+
const replacedString = 'This is not a_**bold**';
3838
expect(parser.replace(testString)).toBe(replacedString);
3939
});
4040

4141
test('Test _ ahead asterisk still result in bold', () => {
42-
const testString = 'This is a ~_*bold*';
42+
const testString = 'This is a ~_**bold**';
4343
const replacedString = 'This is a ~_<strong>bold</strong>';
4444
expect(parser.replace(testString)).toBe(replacedString);
4545
});
@@ -60,15 +60,15 @@ test('Test heading markdown replacement', () => {
6060

6161
// Sections starting with > are successfully wrapped with <blockquote></blockquote>
6262
test('Test quote markdown replacement', () => {
63-
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```';
63+
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```';
6464
const quoteTestReplacedString =
6565
'<blockquote>This is a <strong>quote</strong> that started on a new line.</blockquote>Here is a &gt;quote that did not<br /><pre>here&#32;is&#32;a&#32;codefenced&#32;quote<br />&gt;it&#32;should&#32;not&#32;be&#32;quoted<br /></pre>';
6666

6767
expect(parser.replace(quoteTestStartString)).toBe(quoteTestReplacedString);
6868
});
6969

7070
test('Test quote markdown replacement with shouldEscapeText set as false', () => {
71-
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```';
71+
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```';
7272
const quoteTestReplacedString =
7373
'<blockquote>This is a <strong>quote</strong> that started on a new line.</blockquote>Here is a >quote that did not<br /><pre>here&#32;is&#32;a&#32;codefenced&#32;quote<br />>it&#32;should&#32;not&#32;be&#32;quoted<br /></pre>';
7474

@@ -118,8 +118,8 @@ test('Test quote markdown combined multi-line italic/bold/strikethrough markdown
118118

119119
expect(parser.replace(testString)).toBe(replacedString);
120120

121-
testString = '*test\n> test*';
122-
replacedString = '*test<br /><blockquote>test*</blockquote>';
121+
testString = '**test\n> test**';
122+
replacedString = '**test<br /><blockquote>test**</blockquote>';
123123

124124
expect(parser.replace(testString)).toBe(replacedString);
125125

@@ -159,25 +159,25 @@ test('Test markdown replacement for emails wrapped in bold/strikethrough/italic
159159
let testInput = '~abc@gmail.com~';
160160
expect(parser.replace(testInput)).toBe('<del><a href="mailto:abc@gmail.com">abc@gmail.com</a></del>');
161161

162-
testInput = '*abc@gmail.com*';
162+
testInput = '**abc@gmail.com**';
163163
expect(parser.replace(testInput)).toBe('<strong><a href="mailto:abc@gmail.com">abc@gmail.com</a></strong>');
164164

165165
testInput = '_abc@gmail.com_';
166166
expect(parser.replace(testInput)).toBe('<em><a href="mailto:abc@gmail.com">abc@gmail.com</a></em>');
167167

168-
testInput = '~*_abc@gmail.com_*~';
168+
testInput = '~**_abc@gmail.com_**~';
169169
expect(parser.replace(testInput)).toBe('<del><strong><em><a href="mailto:abc@gmail.com">abc@gmail.com</a></em></strong></del>');
170170

171171
testInput = '[text](~abc@gmail.com~)';
172172
expect(parser.replace(testInput)).toBe('[text](<del><a href="mailto:abc@gmail.com">abc@gmail.com</a></del>)');
173173

174-
testInput = '[text](*abc@gmail.com*)';
174+
testInput = '[text](**abc@gmail.com**)';
175175
expect(parser.replace(testInput)).toBe('[text](<strong><a href="mailto:abc@gmail.com">abc@gmail.com</a></strong>)');
176176

177177
testInput = '[text](_abc@gmail.com_)';
178178
expect(parser.replace(testInput)).toBe('[text](<em><a href="mailto:abc@gmail.com">abc@gmail.com</a></em>)');
179179

180-
testInput = '[text](~*_abc@gmail.com_*~)';
180+
testInput = '[text](~**_abc@gmail.com_**~)';
181181
expect(parser.replace(testInput)).toBe('[text](<del><strong><em><a href="mailto:abc@gmail.com">abc@gmail.com</a></em></strong></del>)');
182182
});
183183

@@ -187,15 +187,15 @@ test('Test markdown replacement for emails wrapped in bold/strikethrough/italic
187187
let result = '<del><a href="mailto:abc@gmail.com">abc@gmail.com</a><br />' + '<a href="mailto:def@gmail.com">def@gmail.com</a></del>';
188188
expect(parser.replace(testInput)).toBe(result);
189189

190-
testInput = '*abc@gmail.com\ndef@gmail.com*';
190+
testInput = '**abc@gmail.com\ndef@gmail.com**';
191191
result = '<strong><a href="mailto:abc@gmail.com">abc@gmail.com</a><br />' + '<a href="mailto:def@gmail.com">def@gmail.com</a></strong>';
192192
expect(parser.replace(testInput)).toBe(result);
193193

194194
testInput = '_abc@gmail.com\ndef@gmail.com_';
195195
result = '<em><a href="mailto:abc@gmail.com">abc@gmail.com</a><br />' + '<a href="mailto:def@gmail.com">def@gmail.com</a></em>';
196196
expect(parser.replace(testInput)).toBe(result);
197197

198-
testInput = '~*_abc@gmail.com\ndef@gmail.com_*~';
198+
testInput = '~**_abc@gmail.com\ndef@gmail.com_**~';
199199
result = '<del><strong><em><a href="mailto:abc@gmail.com">abc@gmail.com</a><br />' + '<a href="mailto:def@gmail.com">def@gmail.com</a></em></strong></del>';
200200
expect(parser.replace(testInput)).toBe(result);
201201

@@ -377,9 +377,9 @@ test('Test markdown style links', () => {
377377
test('Test critical markdown style links', () => {
378378
const testString =
379379
'Testing ' +
380-
'[~strikethrough~ *bold* _italic_](expensify.com) ' +
381-
'[~strikethrough~ *bold* _italic_ test.com](expensify.com) ' +
382-
'[~strikethrough~ *bold* _italic_ https://test.com](https://expensify.com) ' +
380+
'[~strikethrough~ **bold** _italic_](expensify.com) ' +
381+
'[~strikethrough~ **bold** _italic_ test.com](expensify.com) ' +
382+
'[~strikethrough~ **bold** _italic_ https://test.com](https://expensify.com) ' +
383383
'[https://www.text.com/_root_folder/1](https://www.text.com/_root_folder/1) ' +
384384
'[first](https://www.expensify.com/_devportal/tools/logSearch/#query=request_id:(%22Ufjjim%22)+AND+timestamp:[2021-01-08T03:48:10.389Z+TO+2021-01-08T05:48:10.389Z]&index=logs_expensify-008878) ' +
385385
'[first no https://](www.expensify.com/_devportal/tools/logSearch/#query=request_id:(%22Ufjjim%22)+AND+timestamp:[2021-01-08T03:48:10.389Z+TO+2021-01-08T05:48:10.389Z]&index=logs_expensify-008878) ' +
@@ -555,9 +555,9 @@ test('Test code fencing with ExpensiMark syntax outside', () => {
555555
let codeFenceExample = '# Test1 ```\ncode\n``` Test2';
556556
expect(parser.replace(codeFenceExample)).toBe('<h1>Test1 &#x60;&#x60;&#x60;</h1>code<br />&#x60;&#x60;&#x60; Test2');
557557

558-
codeFenceExample = '*Test1\n```\ncode\n```\nTest2*';
559-
expect(parser.replace(codeFenceExample)).toBe('*Test1<br /><pre>code<br /></pre>Test2*');
560-
expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('*Test1\n<pre>\ncode\n</pre>\nTest2*');
558+
codeFenceExample = '**Test1\n```\ncode\n```\nTest2**';
559+
expect(parser.replace(codeFenceExample)).toBe('**Test1<br /><pre>code<br /></pre>Test2**');
560+
expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('**Test1\n<pre>\ncode\n</pre>\nTest2**');
561561

562562
codeFenceExample = '_Test1\n```\ncode\n```\nTest2_';
563563
expect(parser.replace(codeFenceExample)).toBe('_Test1<br /><pre>code<br /></pre>Test2_');
@@ -598,15 +598,15 @@ test('Test code fencing with additional backticks inside', () => {
598598

599599
test('Test combination replacements', () => {
600600
const urlTestStartString =
601-
'<em>Here</em> is a _combination test_ that <marquee>sees</marquee> if ~https://www.example.com~ https://otherexample.com links get rendered first followed by *other markup* or if _*two work together*_ as well. This sentence also has a newline \n Yep just had one.';
601+
'<em>Here</em> is a _combination test_ that <marquee>sees</marquee> if ~https://www.example.com~ https://otherexample.com links get rendered first followed by **other markup** or if _**two work together**_ as well. This sentence also has a newline \n Yep just had one.';
602602
const urlTestReplacedString =
603603
'&lt;em&gt;Here&lt;/em&gt; is a <em>combination test</em> that &lt;marquee&gt;sees&lt;/marquee&gt; if <del><a href="https://www.example.com" target="_blank" rel="noreferrer noopener">https://www.example.com</a></del> <a href="https://otherexample.com"' +
604604
' target="_blank" rel="noreferrer noopener">https://otherexample.com</a> links get rendered first followed by <strong>other markup</strong> or if <em><strong>two work together</strong></em> as well. This sentence also has a newline <br /> Yep just had one.';
605605
expect(parser.replace(urlTestStartString)).toBe(urlTestReplacedString);
606606
});
607607

608608
test('Test wrapped URLs', () => {
609-
const wrappedUrlTestStartString = '~https://www.example.com~ _http://www.test.com_ *http://www.asdf.com/_test*';
609+
const wrappedUrlTestStartString = '~https://www.example.com~ _http://www.test.com_ **http://www.asdf.com/_test**';
610610
const wrappedUrlTestReplacedString =
611611
'<del><a href="https://www.example.com" target="_blank" rel="noreferrer noopener">https://www.example.com</a></del> <em><a href="http://www.test.com" target="_blank" rel="noreferrer noopener">http://www.test.com</a></em>' +
612612
' <strong><a href="http://www.asdf.com/_test" target="_blank" rel="noreferrer noopener">http://www.asdf.com/_test</a></strong>';
@@ -735,7 +735,7 @@ test('Test markdown style link with various styles', () => {
735735
const testString =
736736
'Go to ~[Expensify](https://www.expensify.com)~ ' +
737737
'_[Expensify](https://www.expensify.com)_ ' +
738-
'*[Expensify](https://www.expensify.com)* ' +
738+
'**[Expensify](https://www.expensify.com)** ' +
739739
'[Expensify!](https://www.expensify.com) ' +
740740
'[Expensify?](https://www.expensify.com) ' +
741741
'[Expensify](https://www.expensify-test.com) ' +
@@ -982,7 +982,7 @@ test('Test markdown style email link with various styles', () => {
982982
const testString =
983983
'Go to ~[Expensify](concierge@expensify.com)~ ' +
984984
'_[Expensify](concierge@expensify.com)_ ' +
985-
'*[Expensify](concierge@expensify.com)* ' +
985+
'**[Expensify](concierge@expensify.com)** ' +
986986
'[Expensify!](no-concierge1@expensify.com) ' +
987987
'[Applause](applausetester+qaabecciv@applause.expensifail.com) ' +
988988
'[](concierge@expensify.com)' + // only parse autoEmail in ()
@@ -1099,15 +1099,15 @@ test('Test link: Keep spaces at both end for shouldKeepRawInput=true', () => {
10991099

11001100
test('Test autolink replacement to avoid parsing nested links', () => {
11011101
const testString =
1102-
'[click google.com *here*](google.com) ' +
1102+
'[click google.com **here**](google.com) ' +
11031103
'[click google.com ~here~](google.com) ' +
11041104
'[click google.com _here_](google.com) ' +
11051105
'[click google.com `here`](google.com) ' +
1106-
'[*click* google.com here](google.com) ' +
1106+
'[**click** google.com here](google.com) ' +
11071107
'[~click~ google.com here](google.com) ' +
11081108
'[_click_ google.com here](google.com) ' +
11091109
'[`click` google.com here](google.com) ' +
1110-
'[`click` google.com *here*](google.com)';
1110+
'[`click` google.com **here**](google.com)';
11111111

11121112
const resultString =
11131113
'<a href="https://google.com" target="_blank" rel="noreferrer noopener">click google.com <strong>here</strong></a> ' +
@@ -1354,7 +1354,7 @@ test('Test heading1 markdown replacement with line break before or after the hea
13541354
});
13551355

13561356
test('Test heading1 markdown replacement when heading appear after the quote', () => {
1357-
const testString = '> quote \n# heading 1 after the quote.\nHere is a multi-line\ncomment that contains *bold* string.';
1357+
const testString = '> quote \n# heading 1 after the quote.\nHere is a multi-line\ncomment that contains **bold** string.';
13581358
expect(parser.replace(testString)).toBe(
13591359
'<blockquote>quote </blockquote><h1>heading 1 after the quote.</h1>Here is a multi-line<br />comment that contains <strong>bold</strong> string.',
13601360
);
@@ -1380,7 +1380,7 @@ test('Test for user mention with @phoneNumber', () => {
13801380
});
13811381

13821382
test('Test for user mention with bold style', () => {
1383-
const testString = '*@username@expensify.com*';
1383+
const testString = '**@username@expensify.com**';
13841384
const resultString = '<strong><mention-user>@username@expensify.com</mention-user></strong>';
13851385
expect(parser.replace(testString)).toBe(resultString);
13861386
});
@@ -1562,7 +1562,7 @@ test('Test for @here mention with italic, bold and strikethrough styles', () =>
15621562
const testString =
15631563
'@here' +
15641564
' _@here_' +
1565-
' *@here*' +
1565+
' **@here**' +
15661566
' ~@here~' +
15671567
' [@here](google.com)' +
15681568
' @here_123' +
@@ -1709,17 +1709,17 @@ test('Test for mention inside link and email markdown', () => {
17091709
});
17101710

17111711
test('Skip rendering invalid markdown', () => {
1712-
let testString = '_*test_*';
1713-
expect(parser.replace(testString)).toBe('<em>*test</em>*');
1712+
let testString = '_**test_**';
1713+
expect(parser.replace(testString)).toBe('<em>**test</em>**');
17141714

1715-
testString = '*_test*_';
1716-
expect(parser.replace(testString)).toBe('*<em>test*</em>');
1715+
testString = '**_test**_';
1716+
expect(parser.replace(testString)).toBe('**<em>test**</em>');
17171717

1718-
testString = '~*test~*';
1718+
testString = '~**test~**';
17191719
expect(parser.replace(testString)).toBe('~<strong>test~</strong>');
17201720

1721-
testString = '> *This is multiline\nbold text*';
1722-
expect(parser.replace(testString)).toBe('<blockquote>*This is multiline</blockquote>bold text*');
1721+
testString = '> **This is multiline\nbold text**';
1722+
expect(parser.replace(testString)).toBe('<blockquote>**This is multiline</blockquote>bold text**');
17231723
});
17241724

17251725
test('Test for email with test+1@gmail.com@gmail.com', () => {
@@ -2003,7 +2003,7 @@ describe('when should keep raw input flag is enabled', () => {
20032003
});
20042004

20052005
test('quote with other markdowns', () => {
2006-
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```';
2006+
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```';
20072007
const quoteTestReplacedString =
20082008
'<blockquote> This is a <strong>quote</strong> that started on a new line.</blockquote>\nHere is a &gt;quote that did not\n<pre>\nhere&#32;is&#32;a&#32;codefenced&#32;quote\n&gt;it&#32;should&#32;not&#32;be&#32;quoted\n</pre>';
20092009

@@ -2045,7 +2045,7 @@ describe('when should keep raw input flag is enabled', () => {
20452045
});
20462046

20472047
test('labeled mail with styled label', () => {
2048-
const testString = '[*mail*](mailto:mail@mail.com)';
2048+
const testString = '[**mail**](mailto:mail@mail.com)';
20492049
const resultString = '<a href="mailto:mail@mail.com" data-raw-href="mailto:mail@mail.com" data-link-variant="labeled"><strong>mail</strong></a>';
20502050
expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString);
20512051
});
@@ -2117,7 +2117,7 @@ test('Test italic/bold/strikethrough markdown to keep consistency', () => {
21172117
let resultString = '<em>This_is_italic_test</em>';
21182118
expect(parser.replace(testString)).toBe(resultString);
21192119

2120-
testString = '*This*is*bold*test*';
2120+
testString = '**This*is*bold*test**';
21212121
resultString = '<strong>This*is*bold*test</strong>';
21222122
expect(parser.replace(testString)).toBe(resultString);
21232123

@@ -2129,16 +2129,16 @@ test('Test italic/bold/strikethrough markdown to keep consistency', () => {
21292129
resultString = '<em>This_is_italic_test</em>___';
21302130
expect(parser.replace(testString)).toBe(resultString);
21312131

2132-
testString = '*This*is*bold*test****';
2132+
testString = '**This*is*bold*test*****';
21332133
resultString = '<strong>This*is*bold*test</strong>***';
21342134
expect(parser.replace(testString)).toBe(resultString);
21352135

21362136
testString = '~This~is~strikethrough~test~~~~';
21372137
resultString = '<del>This~is~strikethrough~test</del>~~~';
21382138
expect(parser.replace(testString)).toBe(resultString);
21392139

2140-
testString = '_**bold**_*bold*';
2141-
resultString = '<em>*<strong>bold</strong>*</em><strong>bold</strong>';
2140+
testString = '_**bold**_**bold**';
2141+
resultString = '<em><strong>bold</strong></em><strong>bold</strong>';
21422142
expect(parser.replace(testString)).toBe(resultString);
21432143
});
21442144

@@ -2170,7 +2170,7 @@ describe('multi-level blockquote', () => {
21702170
});
21712171

21722172
test('multi-level blockquote with diffrent syntax', () => {
2173-
const quoteTestStartString = '>> _Hello_ *world*';
2173+
const quoteTestStartString = '>> _Hello_ **world**';
21742174
const quoteTestReplacedString = '<blockquote><blockquote><em>Hello</em> <strong>world</strong></blockquote></blockquote>';
21752175

21762176
expect(parser.replace(quoteTestStartString)).toBe(quoteTestReplacedString);
@@ -2416,7 +2416,7 @@ describe('room mentions', () => {
24162416
});
24172417

24182418
test("room mention shouldn't be parsed when rule is disabled", () => {
2419-
const testString = '*hello* @user@mail.com in #room!';
2419+
const testString = '**hello** @user@mail.com in #room!';
24202420
const resultString = '<strong>hello</strong> <mention-user>@user@mail.com</mention-user> in #room!';
24212421
const disabledRules = ['reportMentions'];
24222422
expect(parser.replace(testString, {disabledRules})).toBe(resultString);
@@ -2426,7 +2426,7 @@ describe('room mentions', () => {
24262426
const testString =
24272427
'#room' +
24282428
' _#room_' +
2429-
' *#room*' +
2429+
' **#room**' +
24302430
' ~#room~' +
24312431
' [#room](google.com)' +
24322432
' #room abc' +

0 commit comments

Comments
 (0)