Skip to content

Commit

Permalink
fix: keep line breaks in message text that contains multiple markdown…
Browse files Browse the repository at this point in the history
… elements (#2429)
  • Loading branch information
MartinCupela committed Jun 19, 2024
1 parent d50b11f commit 11e606f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,30 @@ Array [
]
`;

exports[`keepLineBreaksPlugin present keeps line between lines with strong text 1`] = `
Array [
<p>
This is
<strong>
the first
</strong>
line
</p>,
"
",
<br />,
"
",
"
",
"
",
<p>
This is the second line
</p>,
]
`;

exports[`keepLineBreaksPlugin present keeps line breaks around a blockquote 1`] = `
Array [
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ describe('keepLineBreaksPlugin', () => {
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 doRenderText = (text, present) => {
const Markdown = renderText(
Expand Down Expand Up @@ -365,6 +366,10 @@ describe('keepLineBreaksPlugin', () => {
const tree = doRenderText(tableText, present);
expect(tree).toMatchSnapshot();
});
it(`keeps line between lines with strong text`, () => {
const tree = doRenderText(multilineWithStrongText, present);
expect(tree).toMatchSnapshot();
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const visitor: Visitor = (node, index, parent) => {
const prevSibling = parent.children.at(index - 1);
if (!prevSibling?.position) return;

if (node.position.start.line === prevSibling.position.start.line) return false;
if (node.position.start.line === prevSibling.position.start.line) return;
const ownStartLine = node.position.start.line;
const prevEndLine = prevSibling.position.end.line;

Expand Down

0 comments on commit 11e606f

Please sign in to comment.