Skip to content

Commit

Permalink
fix(richtext-lexical): newlines in mdx props were stripped, even thou…
Browse files Browse the repository at this point in the history
…gh objects inside props may expect there to be newlines (#10215)
  • Loading branch information
AlessioGr authored Dec 28, 2024
1 parent da518f5 commit 67db04c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

return {
Expand Down
21 changes: 21 additions & 0 deletions test/lexical-mdx/int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion test/lexical-mdx/mdx/jsxBlocks/packageInstallOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const PackageInstallOptions: Block = {
someNestedObject: props?.someNestedObject,
uniqueId: props?.uniqueId,
update: props?.update,
someObject: props?.someObject,
}
},
export: ({ fields, lexicalToMarkdown }) => {
Expand All @@ -20,19 +21,24 @@ export const PackageInstallOptions: Block = {
someNestedObject: fields?.someNestedObject,
uniqueId: fields?.uniqueId,
update: fields?.update,
someObject: fields?.someObject,
},
}
},
},
fields: [
{
name: 'packageId',
type: 'text',
type: 'textarea',
},
{
name: 'global',
type: 'checkbox',
},
{
name: 'someObject',
type: 'json',
},
{
name: 'update',
type: 'checkbox',
Expand Down

0 comments on commit 67db04c

Please sign in to comment.