Skip to content

Commit a77c887

Browse files
fix: Parse new lines in text/plain as line breaks (BLO-1170) (#2712)
* Made single new lines in Markdown get parsed as line breaks * Removed logs * Updated logic & tests for new Markdown to HTML converter * Removed unused snapshot * Reverted lock file
1 parent 677fbbf commit a77c887

7 files changed

Lines changed: 38 additions & 8 deletions

File tree

packages/core/src/api/parsers/markdown/markdownToHtml.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function trySoftBreak(
139139
i: number
140140
): { html: string; end: number } | null {
141141
if (text[i] === "\n") {
142-
return { html: "\n", end: i + 1 };
142+
return { html: "<br>\n", end: i + 1 };
143143
}
144144
return null;
145145
}

tests/src/unit/core/formatConversion/parse/__snapshots__/markdown/blockquoteLazyContinuation.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"content": [
55
{
66
"styles": {},
7-
"text": "This is a quote that continues here and here too",
7+
"text": "This is a quote
8+
that continues here
9+
and here too",
810
"type": "text",
911
},
1012
],

tests/src/unit/core/formatConversion/parse/__snapshots__/markdown/blockquoteMultiline.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"content": [
55
{
66
"styles": {},
7-
"text": "Line one Line two Line three",
7+
"text": "Line one
8+
Line two
9+
Line three",
810
"type": "text",
911
},
1012
],

tests/src/unit/core/formatConversion/parse/__snapshots__/markdown/paragraphContinuation.json renamed to tests/src/unit/core/formatConversion/parse/__snapshots__/markdown/lineBreaks.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"content": [
55
{
66
"styles": {},
7-
"text": "Line one still same paragraph",
7+
"text": "Line one
8+
Line two
9+
Line three",
810
"type": "text",
911
},
1012
],

tests/src/unit/core/formatConversion/parse/__snapshots__/markdown/paragraphLeadingIndent.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"content": [
55
{
66
"styles": {},
7-
"text": "aaa bbb",
7+
"text": "aaa
8+
bbb",
89
"type": "text",
910
},
1011
],
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{
3+
"children": [],
4+
"content": [
5+
{
6+
"styles": {},
7+
"text": "Line 1
8+
Line 2
9+
Line 3
10+
Line 4",
11+
"type": "text",
12+
},
13+
],
14+
"id": "1",
15+
"props": {
16+
"backgroundColor": "default",
17+
"textAlignment": "left",
18+
"textColor": "default",
19+
},
20+
"type": "paragraph",
21+
},
22+
]

tests/src/unit/core/formatConversion/parse/parseTestInstances.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,12 +1689,13 @@ Third paragraph`,
16891689
},
16901690
executeTest: testParseMarkdown,
16911691
},
1692-
// Paragraph continuation (lines without blank line)
1692+
// Line breaks
16931693
{
16941694
testCase: {
1695-
name: "paragraphContinuation",
1695+
name: "lineBreaks",
16961696
content: `Line one
1697-
still same paragraph`,
1697+
Line two
1698+
Line three`,
16981699
},
16991700
executeTest: testParseMarkdown,
17001701
},

0 commit comments

Comments
 (0)