Skip to content

Commit c230005

Browse files
fix(richtext-lexical): remove unexpected spaces in link html converter (#13924)
<!-- Thank you for the PR! Please go through the checklist below and make sure you've completed all the steps. Please review the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository if you haven't already. The following items will ensure that your PR is handled as smoothly as possible: - PR Title must follow conventional commits format. For example, `feat: my new feature`, `fix(plugin-seo): my fix`. - Minimal description explained as if explained to someone not immediately familiar with the code. - Provide before/after screenshots or code diffs if applicable. - Link any related issues/discussions from GitHub or Discord. - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Fixes # --> ### What? Fixes a bug that inserted unexpected spaces before and after link text when converting Lexical links to HTML. The extra spaces came from indentation in the template literal used to build the anchor markup. ### Why? The whitespace was largely unnoticed in space-delimited languages like English but produced visible, incorrect gaps in languages without inter-word spacing such as Japanese. ### How? Remove the line breaks and indentations from the link-to-HTML conversion so the anchor markup is constructed without surrounding spaces.
1 parent f868ed9 commit c230005

File tree

2 files changed

+4
-12
lines changed
  • packages/richtext-lexical/src/features/converters/lexicalToHtml

2 files changed

+4
-12
lines changed

packages/richtext-lexical/src/features/converters/lexicalToHtml/async/converters/link.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ export const LinkHTMLConverterAsync: (args: {
1616
})
1717
).join('')
1818

19-
return `<a${providedStyleTag} href="${node.fields.url}"${node.fields.newTab ? ' rel="noopener noreferrer" target="_blank"' : ''}>
20-
${children}
21-
</a>`
19+
return `<a${providedStyleTag} href="${node.fields.url}"${node.fields.newTab ? ' rel="noopener noreferrer" target="_blank"' : ''}>${children}</a>`
2220
},
2321
link: async ({ node, nodesToHTML, populate, providedStyleTag }) => {
2422
const children = (
@@ -39,8 +37,6 @@ export const LinkHTMLConverterAsync: (args: {
3937
}
4038
}
4139

42-
return `<a${providedStyleTag} href="${href}"${node.fields.newTab ? ' rel="noopener noreferrer" target="_blank"' : ''}>
43-
${children}
44-
</a>`
40+
return `<a${providedStyleTag} href="${href}"${node.fields.newTab ? ' rel="noopener noreferrer" target="_blank"' : ''}>${children}</a>`
4541
},
4642
})

packages/richtext-lexical/src/features/converters/lexicalToHtml/sync/converters/link.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ export const LinkHTMLConverter: (args: {
99
nodes: node.children,
1010
}).join('')
1111

12-
return `<a${providedStyleTag} href="${node.fields.url}"${node.fields.newTab ? ' rel="noopener noreferrer" target="_blank"' : ''}>
13-
${children}
14-
</a>`
12+
return `<a${providedStyleTag} href="${node.fields.url}"${node.fields.newTab ? ' rel="noopener noreferrer" target="_blank"' : ''}>${children}</a>`
1513
},
1614
link: ({ node, nodesToHTML, providedStyleTag }) => {
1715
const children = nodesToHTML({
@@ -30,8 +28,6 @@ export const LinkHTMLConverter: (args: {
3028
}
3129
}
3230

33-
return `<a${providedStyleTag} href="${href}"${node.fields.newTab ? ' rel="noopener noreferrer" target="_blank"' : ''}>
34-
${children}
35-
</a>`
31+
return `<a${providedStyleTag} href="${href}"${node.fields.newTab ? ' rel="noopener noreferrer" target="_blank"' : ''}>${children}</a>`
3632
},
3733
})

0 commit comments

Comments
 (0)