Skip to content

Commit 67db04c

Browse files
authored
fix(richtext-lexical): newlines in mdx props were stripped, even though objects inside props may expect there to be newlines (#10215)
1 parent da518f5 commit 67db04c

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

packages/richtext-lexical/src/features/blocks/server/linesFromMatchToContentAndPropsString.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,6 @@ export function linesFromStartToContentAndPropsString({
159159
}
160160
}
161161

162-
// Replace all \n with spaces
163-
propsString = propsString.replace(/\n/g, ' ').trim()
164-
165162
const afterEndLine = linesCopy[endLineIndex].trim().slice(endlineLastCharIndex)
166163

167164
return {

test/lexical-mdx/int.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,27 @@ Some line [Start of link
14011401
},
14021402
},
14031403
},
1404+
{
1405+
input: `
1406+
<PackageInstallOptions
1407+
update
1408+
packageId="Line"
1409+
someObject={{test: \`Line 1
1410+
1411+
Line 2\`}}
1412+
ignored>
1413+
</PackageInstallOptions>
1414+
`,
1415+
inputAfterConvertFromEditorJSON: `<PackageInstallOptions packageId="Line" update someObject={{"test":"Line 1\\n\\nLine 2"}}/>`,
1416+
blockNode: {
1417+
fields: {
1418+
blockType: 'PackageInstallOptions',
1419+
packageId: 'Line',
1420+
someObject: { test: 'Line 1\n\nLine 2' },
1421+
update: true,
1422+
},
1423+
},
1424+
},
14041425
]
14051426

14061427
const INPUT_AND_OUTPUT: Tests = INPUT_AND_OUTPUTBase //.filter((test) => test.debugFlag)

test/lexical-mdx/mdx/jsxBlocks/packageInstallOptions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const PackageInstallOptions: Block = {
1010
someNestedObject: props?.someNestedObject,
1111
uniqueId: props?.uniqueId,
1212
update: props?.update,
13+
someObject: props?.someObject,
1314
}
1415
},
1516
export: ({ fields, lexicalToMarkdown }) => {
@@ -20,19 +21,24 @@ export const PackageInstallOptions: Block = {
2021
someNestedObject: fields?.someNestedObject,
2122
uniqueId: fields?.uniqueId,
2223
update: fields?.update,
24+
someObject: fields?.someObject,
2325
},
2426
}
2527
},
2628
},
2729
fields: [
2830
{
2931
name: 'packageId',
30-
type: 'text',
32+
type: 'textarea',
3133
},
3234
{
3335
name: 'global',
3436
type: 'checkbox',
3537
},
38+
{
39+
name: 'someObject',
40+
type: 'json',
41+
},
3642
{
3743
name: 'update',
3844
type: 'checkbox',

0 commit comments

Comments
 (0)