Skip to content

Commit 11e606f

Browse files
authored
fix: keep line breaks in message text that contains multiple markdown elements (#2429)
1 parent d50b11f commit 11e606f

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

src/components/Message/renderText/__tests__/__snapshots__/renderText.test.js.snap

+24
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,30 @@ Array [
214214
]
215215
`;
216216

217+
exports[`keepLineBreaksPlugin present keeps line between lines with strong text 1`] = `
218+
Array [
219+
<p>
220+
This is
221+
<strong>
222+
the first
223+
</strong>
224+
line
225+
</p>,
226+
"
227+
",
228+
<br />,
229+
"
230+
",
231+
"
232+
",
233+
"
234+
",
235+
<p>
236+
This is the second line
237+
</p>,
238+
]
239+
`;
240+
217241
exports[`keepLineBreaksPlugin present keeps line breaks around a blockquote 1`] = `
218242
Array [
219243
<p>

src/components/Message/renderText/__tests__/renderText.test.js

+5
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ describe('keepLineBreaksPlugin', () => {
277277
const blockquoteText = `a${lineBreaks}>b${lineBreaks}c`;
278278
const withStrikeThroughText = `a${lineBreaks}${strikeThroughText}${lineBreaks}b`;
279279
const tableText = `a${lineBreaks}| a | b | c | d |\n| - | :- | -: | :-: |\n| a | b | c | d |${lineBreaks}c`;
280+
const multilineWithStrongText = 'This is **the first** line\n\nThis is the second line';
280281

281282
const doRenderText = (text, present) => {
282283
const Markdown = renderText(
@@ -365,6 +366,10 @@ describe('keepLineBreaksPlugin', () => {
365366
const tree = doRenderText(tableText, present);
366367
expect(tree).toMatchSnapshot();
367368
});
369+
it(`keeps line between lines with strong text`, () => {
370+
const tree = doRenderText(multilineWithStrongText, present);
371+
expect(tree).toMatchSnapshot();
372+
});
368373
});
369374
});
370375

src/components/Message/renderText/remarkPlugins/keepLineBreaksPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const visitor: Visitor = (node, index, parent) => {
1212
const prevSibling = parent.children.at(index - 1);
1313
if (!prevSibling?.position) return;
1414

15-
if (node.position.start.line === prevSibling.position.start.line) return false;
15+
if (node.position.start.line === prevSibling.position.start.line) return;
1616
const ownStartLine = node.position.start.line;
1717
const prevEndLine = prevSibling.position.end.line;
1818

0 commit comments

Comments
 (0)