Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,6 @@ exports[`keepLineBreaksPlugin present keeps line between lines with strong text
<br />






<p>
This is the second line
</p>
Expand All @@ -256,17 +252,9 @@ exports[`keepLineBreaksPlugin present keeps line breaks around a blockquote 1`]
<br />






<br />






<blockquote>


Expand All @@ -281,17 +269,9 @@ exports[`keepLineBreaksPlugin present keeps line breaks around a blockquote 1`]
<br />






<br />






<p>
c
</p>
Expand All @@ -308,17 +288,9 @@ exports[`keepLineBreaksPlugin present keeps line breaks around a code block 1`]
<br />






<br />






<p>
<code>
b
Expand All @@ -329,17 +301,9 @@ exports[`keepLineBreaksPlugin present keeps line breaks around a code block 1`]
<br />






<br />






<p>
c
</p>
Expand All @@ -356,33 +320,17 @@ exports[`keepLineBreaksPlugin present keeps line breaks around a horizontal rule
<br />






<br />








<br />






<br />






<p>
b
</p>
Expand All @@ -399,17 +347,9 @@ exports[`keepLineBreaksPlugin present keeps line breaks around a strikethrough 1
<br />






<br />






<p>
~~xxx~~
</p>
Expand All @@ -418,17 +358,9 @@ exports[`keepLineBreaksPlugin present keeps line breaks around a strikethrough 1
<br />






<br />






<p>
b
</p>
Expand All @@ -445,17 +377,9 @@ exports[`keepLineBreaksPlugin present keeps line breaks around a table 1`] = `
<br />






<br />






<p>
| a | b | c | d |
| - | :- | -: | :-: |
Expand All @@ -466,17 +390,9 @@ exports[`keepLineBreaksPlugin present keeps line breaks around a table 1`] = `
<br />






<br />






<p>
c
</p>
Expand All @@ -493,17 +409,9 @@ exports[`keepLineBreaksPlugin present keeps line breaks between paragraphs 1`] =
<br />






<br />






<p>
b
</p>
Expand All @@ -512,17 +420,9 @@ exports[`keepLineBreaksPlugin present keeps line breaks between paragraphs 1`] =
<br />






<br />






<p>
c
</p>
Expand All @@ -548,17 +448,9 @@ exports[`keepLineBreaksPlugin present keeps line breaks between the items in an
<br />






<br />






<li>


Expand All @@ -573,17 +465,9 @@ exports[`keepLineBreaksPlugin present keeps line breaks between the items in an
<br />






<br />






<li>


Expand Down Expand Up @@ -618,17 +502,9 @@ exports[`keepLineBreaksPlugin present keeps line breaks between the items in an
<br />






<br />






<li>


Expand All @@ -643,17 +519,9 @@ exports[`keepLineBreaksPlugin present keeps line breaks between the items in an
<br />






<br />






<li>


Expand All @@ -679,17 +547,9 @@ exports[`keepLineBreaksPlugin present keeps line breaks under a heading 1`] = `
<br />






<br />






<p>
a
</p>
Expand Down
59 changes: 47 additions & 12 deletions src/components/Message/renderText/__tests__/renderText.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
imageToLink,
keepLineBreaksPlugin,
plusPlusToEmphasis,
remarkIgnoreMarkdown,
} from '../remarkPlugins';
import { defaultAllowedTagNames, renderText } from '../renderText';
import '@testing-library/jest-dom';
Expand Down Expand Up @@ -306,19 +307,19 @@ describe(`renderText`, () => {
});
});

describe('keepLineBreaksPlugin', () => {
const lineBreaks = '\n\n\n';
const paragraphText = `a${lineBreaks}b${lineBreaks}c`;
const unorderedListText = `* item 1${lineBreaks}* item 2${lineBreaks}* item 3`;
const orderedListText = `1. item 1${lineBreaks}2. item 2${lineBreaks}3. item 3`;
const headingText = `## Heading${lineBreaks}a`;
const codeBlockText = 'a\n\n\n```b```\n\n\nc';
const horizontalRuleText = `a${lineBreaks}---${lineBreaks}b`;
const blockquoteText = `a${lineBreaks}>b${lineBreaks}c`;
const withStrikeThroughText = `a${lineBreaks}${strikeThroughText}${lineBreaks}b`;
const tableText = `a${lineBreaks}| a | b | c | d |\n| - | :- | -: | :-: |\n| a | b | c | d |${lineBreaks}c`;
const multilineWithStrongText = 'This is **the first** line\n\nThis is the second line';
const lineBreaks = '\n\n\n';
const paragraphText = `a${lineBreaks}b${lineBreaks}c`;
const unorderedListText = `* item 1${lineBreaks}* item 2${lineBreaks}* item 3`;
const orderedListText = `1. item 1${lineBreaks}2. item 2${lineBreaks}3. item 3`;
const headingText = `## Heading${lineBreaks}a`;
const codeBlockText = 'a\n\n\n```b```\n\n\nc';
const horizontalRuleText = `a${lineBreaks}---${lineBreaks}b`;
const blockquoteText = `a${lineBreaks}>b${lineBreaks}c`;
const withStrikeThroughText = `a${lineBreaks}${strikeThroughText}${lineBreaks}b`;
const tableText = `a${lineBreaks}| a | b | c | d |\n| - | :- | -: | :-: |\n| a | b | c | d |${lineBreaks}c`;
const multilineWithStrongText = 'This is **the first** line\n\nThis is the second line';

describe('keepLineBreaksPlugin', () => {
const doRenderText = (text, present) => {
const Markdown = renderText(
text,
Expand Down Expand Up @@ -500,3 +501,37 @@ describe('imageToLink', () => {
).not.toBeInTheDocument();
});
});

describe('remarkIgnoreMarkdown', () => {
const text = [
headingText,
paragraphText,
unorderedListText,
orderedListText,
codeBlockText,
horizontalRuleText,
blockquoteText,
withStrikeThroughText,
tableText,
multilineWithStrongText,
].join('\n');

const renderWithPlugin = (plugins = []) => {
const Markdown = renderText(
text,
{},
{ getRemarkPlugins: () => [...plugins, remarkIgnoreMarkdown] },
);
return render(Markdown).container;
};

it('skips the markdown transformation and keeps the original escaped text and lines', () => {
expect(renderWithPlugin().innerHTML).toBe(`<p>${text.replace(/>/g, '&gt;')}</p>`);
});

it('keeps line without keepLineBreaksPlugin', () => {
expect(renderWithPlugin([keepLineBreaksPlugin]).innerHTML).toBe(
renderWithPlugin().innerHTML,
);
});
});
1 change: 1 addition & 0 deletions src/components/Message/renderText/remarkPlugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './htmlToTextPlugin';
export * from './imageToLink';
export * from './keepLineBreaksPlugin';
export * from './plusPlusToEmphasis';
export * from './remarkIgnoreMarkdown';
Loading
Loading