-
Notifications
You must be signed in to change notification settings - Fork 147
Update codeblock parsing rule #865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
chiragsalian
merged 3 commits into
Expensify:main
from
software-mansion-labs:@Skalakid/update-codeblock-parsing-rules
Jul 8, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -468,10 +468,10 @@ test('Test code fencing with spaces and new lines', () => { | |
| expect(parser.replace(codeFenceExample)).toBe('<pre># test<br /></pre>'); | ||
|
|
||
| codeFenceExample = '``` \r\n# test\r\n```'; | ||
| expect(parser.replace(codeFenceExample)).toBe('<pre># test<br /></pre>'); | ||
| expect(parser.replace(codeFenceExample)).toBe('``` <br /><h1>test</h1>```'); | ||
|
|
||
| codeFenceExample = '```test\r\n# test\r\n```'; | ||
| expect(parser.replace(codeFenceExample)).toBe('<pre># test<br /></pre>'); | ||
| expect(parser.replace(codeFenceExample)).toBe('```test<br /><h1>test</h1>```'); | ||
|
|
||
| codeFenceExample = '```\r\n\r\n# test\r\n\r\n```'; | ||
| expect(parser.replace(codeFenceExample)).toBe('<pre><br /># test<br /><br /></pre>'); | ||
|
|
@@ -535,24 +535,24 @@ test('Test code fencing with ExpensiMark syntax inside', () => { | |
|
|
||
| test('Test code fencing with ExpensiMark syntax outside', () => { | ||
| let codeFenceExample = '# Test1 ```\ncode\n``` Test2'; | ||
| expect(parser.replace(codeFenceExample)).toBe('<h1>Test1 </h1><pre>code<br /></pre> Test2'); | ||
| expect(parser.replace(codeFenceExample)).toBe('<h1>Test1 ```</h1>code<br />``` Test2'); | ||
|
|
||
| codeFenceExample = '*Test1 ```\ncode\n``` Test2*'; | ||
| expect(parser.replace(codeFenceExample)).toBe('*Test1 <pre>code<br /></pre> Test2*'); | ||
| expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('*Test1 <pre>\ncode\n</pre> Test2*'); | ||
| codeFenceExample = '*Test1\n```\ncode\n```\nTest2*'; | ||
| expect(parser.replace(codeFenceExample)).toBe('*Test1<br /><pre>code<br /></pre>Test2*'); | ||
| expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('*Test1\n<pre>\ncode\n</pre>\nTest2*'); | ||
|
|
||
| codeFenceExample = '_Test1 ```\ncode\n``` Test2_'; | ||
| expect(parser.replace(codeFenceExample)).toBe('_Test1 <pre>code<br /></pre> Test2_'); | ||
| expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('_Test1 <pre>\ncode\n</pre> Test2_'); | ||
| codeFenceExample = '_Test1\n```\ncode\n```\nTest2_'; | ||
| expect(parser.replace(codeFenceExample)).toBe('_Test1<br /><pre>code<br /></pre>Test2_'); | ||
| expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('_Test1\n<pre>\ncode\n</pre>\nTest2_'); | ||
|
|
||
| codeFenceExample = '~Test1 ```\ncode\n``` Test2~'; | ||
| expect(parser.replace(codeFenceExample)).toBe('~Test1 <pre>code<br /></pre> Test2~'); | ||
| expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('~Test1 <pre>\ncode\n</pre> Test2~'); | ||
| codeFenceExample = '~Test1\n```\ncode\n```\nTest2~'; | ||
| expect(parser.replace(codeFenceExample)).toBe('~Test1<br /><pre>code<br /></pre>Test2~'); | ||
| expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe('~Test1\n<pre>\ncode\n</pre>\nTest2~'); | ||
|
|
||
| codeFenceExample = '[```\ncode\n```](google.com)'; | ||
| expect(parser.replace(codeFenceExample)).toBe('[<pre>code<br /></pre>](<a href="https://google.com" target="_blank" rel="noreferrer noopener">google.com</a>)'); | ||
| codeFenceExample = '[\n```\ncode\n```\n](google.com)'; | ||
| expect(parser.replace(codeFenceExample)).toBe('[<br /><pre>code<br /></pre>](<a href="https://google.com" target="_blank" rel="noreferrer noopener">google.com</a>)'); | ||
| expect(parser.replace(codeFenceExample, {shouldKeepRawInput: true})).toBe( | ||
| '[<pre>\ncode\n</pre>](<a href="https://google.com" data-raw-href="google.com" data-link-variant="auto" target="_blank" rel="noreferrer noopener">google.com</a>)', | ||
| '[\n<pre>\ncode\n</pre>\n](<a href="https://google.com" data-raw-href="google.com" data-link-variant="auto" target="_blank" rel="noreferrer noopener">google.com</a>)', | ||
| ); | ||
| }); | ||
|
|
||
|
|
@@ -1753,11 +1753,11 @@ test('Test here mention with @here@here', () => { | |
| }); | ||
|
|
||
| test('Test link with code fence inside the alias text part', () => { | ||
| const testString = '[```\ncode\n```](google.com) ' + '[test ```\ncode\n``` test](google.com)'; | ||
| const testString = '[\n```\ncode\n```](google.com) ' + '[test\n```\ncode\n``` test](google.com)'; | ||
|
|
||
| const resultString = | ||
| '[<pre>code<br /></pre>](<a href="https://google.com" target="_blank" rel="noreferrer noopener">google.com</a>) ' + | ||
| '[test <pre>code<br /></pre> test](<a href="https://google.com" target="_blank" rel="noreferrer noopener">google.com</a>)'; | ||
| '[<br /><pre>code<br /></pre>](<a href="https://google.com" target="_blank" rel="noreferrer noopener">google.com</a>) ' + | ||
| '[test<br /><pre>code<br /></pre> test](<a href="https://google.com" target="_blank" rel="noreferrer noopener">google.com</a>)'; | ||
| expect(parser.replace(testString)).toBe(resultString); | ||
| }); | ||
|
|
||
|
|
@@ -1820,11 +1820,11 @@ test('Linebreak between end of text and start of code block should be remained', | |
| }, | ||
| { | ||
| testString: 'text1```\ncode\n```text2', | ||
| resultString: 'text1<pre>code<br /></pre>text2', | ||
| resultString: 'text1```<br />code<br />```text2', | ||
| }, | ||
| { | ||
| testString: 'text1 ```\n code \n``` text2', | ||
| resultString: 'text1 <pre> code <br /></pre> text2', | ||
| resultString: 'text1 ```<br /> code <br />``` text2', | ||
| }, | ||
| { | ||
| testString: 'text1\n```\ncode\n```\ntext2', | ||
|
|
@@ -1858,26 +1858,26 @@ test('Linebreak between end of text and start of code block should be remained', | |
|
|
||
| test('Test autoEmail with markdown of <pre>, <code>, <a>, <mention-user> and <em> tag', () => { | ||
| const testString = | ||
| '`code`[email protected] ' + | ||
| '```\ncode block\n```[email protected] ' + | ||
| '`code`[email protected]\n' + | ||
| '```\ncode block\n``` [email protected] ' + | ||
| '[Google](https://google.com)[email protected] ' + | ||
| '[email protected]_ ' + | ||
| '_test\n\[email protected]_ ' + | ||
| '`[email protected]` ' + | ||
| '```\[email protected]\n``` ' + | ||
| '`[email protected]`\n' + | ||
| '```\[email protected]\n```\n' + | ||
| '@[email protected] ' + | ||
| '_@[email protected]_ ' + | ||
| '[https://staging.new.expensify.com/details/[email protected]](https://staging.new.expensify.com/details/[email protected]) ' + | ||
| '[test italic style wrap email [email protected]_ inside a link](https://google.com) '; | ||
|
|
||
| const resultString = | ||
| '<code>code</code><a href="mailto:[email protected]">[email protected]</a> ' + | ||
| '<pre>code block<br /></pre><a href="mailto:[email protected]">[email protected]</a> ' + | ||
| '<code>code</code><a href=\"mailto:[email protected]\">[email protected]</a><br />' + | ||
| '<pre>code block<br /></pre> <a href="mailto:[email protected]">[email protected]</a> ' + | ||
| '<a href="https://google.com" target="_blank" rel="noreferrer noopener">Google</a><a href="mailto:[email protected]">[email protected]</a> ' + | ||
| '<em><a href="mailto:[email protected]">[email protected]</a></em> ' + | ||
| '<em>test<br /><br /><a href="mailto:[email protected]">[email protected]</a></em> ' + | ||
| '<code>[email protected]</code> ' + | ||
| '<pre>[email protected]<br /></pre> ' + | ||
| '<code>[email protected]</code><br />' + | ||
| '<pre>[email protected]<br /></pre>' + | ||
| '<mention-user>@[email protected]</mention-user> ' + | ||
| '<em><mention-user>@[email protected]</mention-user></em> ' + | ||
| '<a href="https://staging.new.expensify.com/details/[email protected]" target="_blank" rel="noreferrer noopener">https://staging.new.expensify.com/details/[email protected]</a> ' + | ||
|
|
@@ -2074,19 +2074,22 @@ describe('when should keep raw input flag is enabled', () => { | |
|
|
||
| test('Test code fence within inline code', () => { | ||
| let testString = 'Hello world `(```\ntest\n```)` Hello world'; | ||
| expect(parser.replace(testString)).toBe('Hello world `(<pre>test<br /></pre>)` Hello world'); | ||
| expect(parser.replace(testString)).toBe('Hello world <code>(</code>``<br />test<br />``<code>)</code> Hello world'); | ||
|
|
||
| testString = 'Hello world `(```\ntest\ntest\n```)` Hello world'; | ||
| expect(parser.replace(testString)).toBe('Hello world `(<pre>test<br />test<br /></pre>)` Hello world'); | ||
| expect(parser.replace(testString)).toBe('Hello world <code>(</code>``<br />test<br />test<br />``<code>)</code> Hello world'); | ||
|
|
||
| testString = 'Hello world ```\n(`test`)\n``` Hello world'; | ||
| expect(parser.replace(testString)).toBe('Hello world <pre>(`test`)<br /></pre> Hello world'); | ||
| expect(parser.replace(testString)).toBe('Hello world ```<br />(<code>test</code>)<br />``` Hello world'); | ||
|
|
||
| testString = 'Hello world `test`space```\nblock\n``` Hello world'; | ||
| expect(parser.replace(testString)).toBe('Hello world <code>test</code>space<pre>block<br /></pre> Hello world'); | ||
| expect(parser.replace(testString)).toBe('Hello world <code>test</code>space```<br />block<br />``` Hello world'); | ||
|
|
||
| testString = 'Hello world ```\nblock\n```space`test` Hello world'; | ||
| expect(parser.replace(testString)).toBe('Hello world <pre>block<br /></pre>space<code>test</code> Hello world'); | ||
| expect(parser.replace(testString)).toBe('Hello world ```<br />block<br />``<code>space</code>test` Hello world'); | ||
|
|
||
| testString = 'Hello world `\n```\nblock\n```\n` space`test` Hello world'; | ||
| expect(parser.replace(testString)).toBe('Hello world `<br /><pre>block<br /></pre><code> space</code>test` Hello world'); | ||
| }); | ||
|
|
||
| test('Test italic/bold/strikethrough markdown to keep consistency', () => { | ||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB, or part of this issue, but IMO the tests would benefit from making
a
describeand having test cases astestwith separate descriptionsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think it applies to all other markdown tests. They are heavily mixed, so reorganizing them into
describesections would be beneficial