Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Rocket.Chat
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RocketChat
Rocket.Chat
Commits
637b7046
Unverified
Commit
637b7046
authored
5 months ago
by
Yash Rajpal
Committed by
GitHub
5 months ago
Browse files
Options
Downloads
Patches
Plain Diff
regression: MarkdownText component to parse nested emphasis tokens (#33385)
parent
2e3ad27d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/meteor/client/components/MarkdownText.spec.tsx
+23
-11
23 additions, 11 deletions
apps/meteor/client/components/MarkdownText.spec.tsx
apps/meteor/client/components/MarkdownText.tsx
+4
-4
4 additions, 4 deletions
apps/meteor/client/components/MarkdownText.tsx
with
27 additions
and
15 deletions
apps/meteor/client/components/MarkdownText.spec.tsx
+
23
−
11
View file @
637b7046
...
@@ -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>
'
);
});
});
This diff is collapsed.
Click to expand it.
apps/meteor/client/components/MarkdownText.tsx
+
4
−
4
View file @
637b7046
...
@@ -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
'
;
}
}
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment