Skip to content

Commit a95859f

Browse files
fix: add more lenient parsing for code blocks, to accept newlines #2105 (#2108)
Co-authored-by: Matthew Lipski <[email protected]>
1 parent 9a502b6 commit a95859f

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

packages/core/src/blocks/Code/block.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export const createCodeBlockSpec = createBlockSpec(
102102
const code = el.firstElementChild!;
103103

104104
return parser.parse(code, {
105+
preserveWhitespace: "full",
105106
topNode: schema.nodes["codeBlock"].create(),
106107
}).content;
107108
},
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[
2+
{
3+
"children": [],
4+
"content": [
5+
{
6+
"styles": {},
7+
"text": "console.log("First Line")
8+
console.log("Second Line")
9+
console.log("Third Line")",
10+
"type": "text",
11+
},
12+
],
13+
"id": "1",
14+
"props": {
15+
"language": "text",
16+
},
17+
"type": "codeBlock",
18+
},
19+
]

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,15 @@ With Hard Break</p>
814814
},
815815
executeTest: testParseHTML,
816816
},
817+
{
818+
testCase: {
819+
name: "codeBlocksMultiLine",
820+
content: `<pre><code>console.log("First Line")
821+
console.log("Second Line")
822+
console.log("Third Line")</code></pre>`,
823+
},
824+
executeTest: testParseHTML,
825+
},
817826
{
818827
testCase: {
819828
name: "basicBlockquote",

0 commit comments

Comments
 (0)