feat(richtext-lexical): support escaping markdown characters (#11784)

Fixes https://github.com/payloadcms/payload/issues/10289 and
https://github.com/payloadcms/payload/issues/11772

This adds support for escaping markdown characters. For example,` \*` is
supposed to be imported as `*` and exported back to `\*`.

Equivalent PR in lexical repo:
https://github.com/facebook/lexical/pull/7353
This commit is contained in:
Alessio Gravili
2025-03-20 10:29:45 -06:00
committed by GitHub
parent 7d9d067faf
commit 43cdccdef0
5 changed files with 120 additions and 22 deletions

View File

@@ -137,7 +137,7 @@ export const tableJson = {
format: 0,
mode: 'normal',
style: '',
text: ' ',
text: ' * ',
type: 'text',
version: 1,
},

View File

@@ -376,13 +376,13 @@ there4
input: `
| Option | Default route | Description |
| ----------------- | ----------------------- | ----------------------------------------------- |
| \`account\` | | The user's account page. |
| \`account\` \\* | | The user's account page. |
| \`createFirstUser\` | \`/create-first-user\` | The page to create the first user. |
`,
inputAfterConvertFromEditorJSON: `
| Option | Default route | Description |
|---|---|---|
| \`account\` | | The user's account page. |
| \`account\` \\* | | The user's account page. |
| \`createFirstUser\` | \`/create-first-user\` | The page to create the first user. |
`,
rootChildren: [tableJson],
@@ -400,6 +400,19 @@ there4
},
},
},
{
input: `
<Banner>
Escaped \\*
</Banner>
`,
blockNode: {
fields: {
blockType: 'Banner',
content: textToRichText('Escaped *'),
},
},
},
{
input: `\`inline code\``,
rootChildren: [
@@ -1286,6 +1299,89 @@ Some line [Start of link
},
},
},
{
input: `
<Banner>
Some line [Text **bold** \\*normal\\*](/some/link)
</Banner>
`,
blockNode: {
fields: {
blockType: 'Banner',
content: {
root: {
children: [
{
children: [
{
detail: 0,
format: 0,
mode: 'normal',
style: '',
text: 'Some line ',
type: 'text',
version: 1,
},
{
children: [
{
detail: 0,
format: 0,
mode: 'normal',
style: '',
text: 'Text ',
type: 'text',
version: 1,
},
{
detail: 0,
format: 1,
mode: 'normal',
style: '',
text: 'bold',
type: 'text',
version: 1,
},
{
detail: 0,
format: 0,
mode: 'normal',
style: '',
text: ' *normal*',
type: 'text',
version: 1,
},
],
fields: {
linkType: 'custom',
newTab: false,
url: '/some/link',
},
format: '',
indent: 0,
type: 'link',
version: 3,
},
],
direction: null,
format: '',
indent: 0,
textFormat: 0,
textStyle: '',
type: 'paragraph',
version: 1,
},
],
direction: null,
format: '',
indent: 0,
type: 'root',
version: 1,
},
},
},
},
},
{
inputAfterConvertFromEditorJSON: `
<Banner>