Skip to content
Snippets Groups Projects
Unverified Commit 637b7046 authored by Yash Rajpal's avatar Yash Rajpal Committed by GitHub
Browse files

regression: MarkdownText component to parse nested emphasis tokens (#33385)

parent 2e3ad27d
No related branches found
No related tags found
No related merge requests found
...@@ -15,26 +15,30 @@ const markdownText = ` ...@@ -15,26 +15,30 @@ const markdownText = `
**Paragraph text**: *Bold with one asterisk* **Bold with two asterisks** Lorem ipsum dolor sit amet, consectetur adipiscing elit. **Paragraph text**: *Bold with one asterisk* **Bold with two asterisks** Lorem ipsum dolor sit amet, consectetur adipiscing elit.
## Heading 2 ## Heading 2
_Italic Text_: _Italic with one underscore_ __Italic with two underscores__ Lorem ipsum dolor sit amet, consectetur adipiscing elit. _Italic Text_: _Italic with one underscore_ __Italic with two underscores__ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
### Heading 3 ### Heading 3
Lists, Links and elements Lists, Links and elements
**Unordered List** **Unordered List**
- List Item 1 - List Item 1
- List Item 2 - List Item 2
- List Item 3 - List Item 3
- List Item 4 - List Item 4
**Ordered List** **Ordered List**
1. List Item 1 1. List Item 1
2. List Item 2 2. List Item 2
3. List Item 3 3. List Item 3
4. List Item 4 4. List Item 4
**Links:** **Links:**
[Rocket.Chat](rocket.chat) [Rocket.Chat](rocket.chat)
gabriel.engel@rocket.chat gabriel.engel@rocket.chat
+55991999999 +55991999999
\`Inline code\` \`Inline code\`
\`\`\`typescript \`\`\`typescript
const test = 'this is code' const test = 'this is code'
\`\`\` \`\`\`
**Bold text within __Italics__**
*Bold text with single asterik and underscore within _Italics_*
__Italics within **Bold** text__
_Italics within *Bold* text with single underscore and asterik_
`; `;
it('should render html elements as expected using default parser', async () => { it('should render html elements as expected using default parser', async () => {
...@@ -54,13 +58,17 @@ it('should render html elements as expected using default parser', async () => { ...@@ -54,13 +58,17 @@ it('should render html elements as expected using default parser', async () => {
'<em>Italic Text</em>: <em>Italic with one underscore</em> <em>Italic with two underscores</em> Lorem ipsum dolor sit amet', '<em>Italic Text</em>: <em>Italic with one underscore</em> <em>Italic with two underscores</em> Lorem ipsum dolor sit amet',
); );
expect(normalizedHtml).toContain('<h3>Heading 3</h3>'); expect(normalizedHtml).toContain('<h3>Heading 3</h3>');
expect(normalizedHtml).toContain('<ul> <li>List Item 1 </li><li>List Item 2 </li><li>List Item 3 </li><li>List Item 4'); expect(normalizedHtml).toContain('<ul> <li>List Item 1</li><li>List Item 2</li><li>List Item 3</li><li>List Item 4');
expect(normalizedHtml).toContain('<ol> <li>List Item 1</li><li>List Item 2</li><li>List Item 3</li><li>List Item 4'); expect(normalizedHtml).toContain('<ol> <li>List Item 1</li><li>List Item 2</li><li>List Item 3</li><li>List Item 4');
expect(normalizedHtml).toContain('<a title="" rel="nofollow noopener noreferrer" target="_blank">Rocket.Chat</a>'); expect(normalizedHtml).toContain('<a title="" rel="nofollow noopener noreferrer" target="_blank">Rocket.Chat</a>');
expect(normalizedHtml).toContain('gabriel.engel@rocket.chat'); expect(normalizedHtml).toContain('gabriel.engel@rocket.chat');
expect(normalizedHtml).toContain('+55991999999'); expect(normalizedHtml).toContain('+55991999999');
expect(normalizedHtml).toContain('<code>Inline code</code>'); expect(normalizedHtml).toContain('<code>Inline code</code>');
expect(normalizedHtml).toContain('<pre><code class="language-typescript">const test = \'this is code\' </code></pre>'); expect(normalizedHtml).toContain('<pre><code class="language-typescript">const test = \'this is code\' </code></pre>');
expect(normalizedHtml).toContain('<strong>Bold text within <em>Italics</em></strong>');
expect(normalizedHtml).toContain('<strong>Bold text with single asterik and underscore within <em>Italics</em></strong>');
expect(normalizedHtml).toContain('<em>Italics within <strong>Bold</strong> text</em>');
expect(normalizedHtml).toContain('<em>Italics within <strong>Bold</strong> text with single underscore and asterik</em>');
}); });
it('should render html elements as expected using inline parser', async () => { it('should render html elements as expected using inline parser', async () => {
...@@ -89,4 +97,8 @@ it('should render html elements as expected using inline parser', async () => { ...@@ -89,4 +97,8 @@ it('should render html elements as expected using inline parser', async () => {
expect(normalizedHtml).toContain('+55991999999'); expect(normalizedHtml).toContain('+55991999999');
expect(normalizedHtml).toContain('Inline code'); expect(normalizedHtml).toContain('Inline code');
expect(normalizedHtml).toContain(`typescript const test = 'this is code'`); expect(normalizedHtml).toContain(`typescript const test = 'this is code'`);
expect(normalizedHtml).toContain('<strong>Bold text within <em>Italics</em></strong>');
expect(normalizedHtml).toContain('<strong>Bold text with single asterik and underscore within <em>Italics</em></strong>');
expect(normalizedHtml).toContain('<em>Italics within <strong>Bold</strong> text</em>');
expect(normalizedHtml).toContain('<em>Italics within <strong>Bold</strong> text with single underscore and asterik</em>');
}); });
...@@ -23,10 +23,10 @@ const inlineWithoutBreaks = new marked.Renderer(); ...@@ -23,10 +23,10 @@ const inlineWithoutBreaks = new marked.Renderer();
const walkTokens = (token: marked.Token) => { const walkTokens = (token: marked.Token) => {
const boldPattern = /^\*[^*]+\*$|^\*\*[^*]+\*\*$/; const boldPattern = /^\*[^*]+\*$|^\*\*[^*]+\*\*$/;
const italicPattern = /^__(?=\S)([\s\S]*?\S)__(?!_)|^_(?=\S)([\s\S]*?\S)_(?!_)/; const italicPattern = /^__(?=\S)([\s\S]*?\S)__(?!_)|^_(?=\S)([\s\S]*?\S)_(?!_)/;
if (boldPattern.test(token.raw)) { if (boldPattern.test(token.raw) && token.type === 'em') {
token.type = 'strong'; token.type = 'strong' as 'em';
} else if (italicPattern.test(token.raw)) { } else if (italicPattern.test(token.raw) && token.type === 'strong') {
token.type = 'em'; token.type = 'em' as 'strong';
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment