fix(richtext-lexical): newlines in mdx props were stripped, even though objects inside props may expect there to be newlines (#10215)

This commit is contained in:
Alessio Gravili
2024-12-27 21:53:44 -07:00
committed by GitHub
parent da518f53e8
commit 67db04c660
3 changed files with 28 additions and 4 deletions

View File

@@ -159,9 +159,6 @@ export function linesFromStartToContentAndPropsString({
} }
} }
// Replace all \n with spaces
propsString = propsString.replace(/\n/g, ' ').trim()
const afterEndLine = linesCopy[endLineIndex].trim().slice(endlineLastCharIndex) const afterEndLine = linesCopy[endLineIndex].trim().slice(endlineLastCharIndex)
return { return {

View File

@@ -1401,6 +1401,27 @@ Some line [Start of link
}, },
}, },
}, },
{
input: `
<PackageInstallOptions
update
packageId="Line"
someObject={{test: \`Line 1
Line 2\`}}
ignored>
</PackageInstallOptions>
`,
inputAfterConvertFromEditorJSON: `<PackageInstallOptions packageId="Line" update someObject={{"test":"Line 1\\n\\nLine 2"}}/>`,
blockNode: {
fields: {
blockType: 'PackageInstallOptions',
packageId: 'Line',
someObject: { test: 'Line 1\n\nLine 2' },
update: true,
},
},
},
] ]
const INPUT_AND_OUTPUT: Tests = INPUT_AND_OUTPUTBase //.filter((test) => test.debugFlag) const INPUT_AND_OUTPUT: Tests = INPUT_AND_OUTPUTBase //.filter((test) => test.debugFlag)

View File

@@ -10,6 +10,7 @@ export const PackageInstallOptions: Block = {
someNestedObject: props?.someNestedObject, someNestedObject: props?.someNestedObject,
uniqueId: props?.uniqueId, uniqueId: props?.uniqueId,
update: props?.update, update: props?.update,
someObject: props?.someObject,
} }
}, },
export: ({ fields, lexicalToMarkdown }) => { export: ({ fields, lexicalToMarkdown }) => {
@@ -20,6 +21,7 @@ export const PackageInstallOptions: Block = {
someNestedObject: fields?.someNestedObject, someNestedObject: fields?.someNestedObject,
uniqueId: fields?.uniqueId, uniqueId: fields?.uniqueId,
update: fields?.update, update: fields?.update,
someObject: fields?.someObject,
}, },
} }
}, },
@@ -27,12 +29,16 @@ export const PackageInstallOptions: Block = {
fields: [ fields: [
{ {
name: 'packageId', name: 'packageId',
type: 'text', type: 'textarea',
}, },
{ {
name: 'global', name: 'global',
type: 'checkbox', type: 'checkbox',
}, },
{
name: 'someObject',
type: 'json',
},
{ {
name: 'update', name: 'update',
type: 'checkbox', type: 'checkbox',