diff --git a/src/lib/hastToRichText.ts b/src/lib/hastToRichText.ts index 6aff86a7..4c84b0fb 100644 --- a/src/lib/hastToRichText.ts +++ b/src/lib/hastToRichText.ts @@ -157,7 +157,7 @@ export const hastToRichText = ( case RichTextNodeType.em: case RichTextNodeType.label: case RichTextNodeType.hyperlink: { - const length = toString(node).length; + const length = toString(node).trimEnd().length; try { builder.appendSpan(shorthandOrNode, length); @@ -238,7 +238,7 @@ export const hastToRichText = ( case RichTextNodeType.label: case RichTextNodeType.hyperlink: { const span = serializeSpan(node, match); - const length = toString(node).length; + const length = toString(node).trimEnd().length; try { builder.appendSpan(span, length); diff --git a/test/__snapshots__/helpers-unstable_htmlAsRichText.test.ts.snap b/test/__snapshots__/helpers-unstable_htmlAsRichText.test.ts.snap index 3478057c..41c9e43b 100644 --- a/test/__snapshots__/helpers-unstable_htmlAsRichText.test.ts.snap +++ b/test/__snapshots__/helpers-unstable_htmlAsRichText.test.ts.snap @@ -1001,7 +1001,7 @@ exports[`transforms HTML to rich text > spans > empty spans 1`] = ` { "direction": "ltr", "spans": [], - "text": "lorem ipsum dolor sit amet", + "text": "lorem ipsum dolorsit amet", "type": "paragraph", }, ] diff --git a/test/helpers-unstable_htmlAsRichText.test.ts b/test/helpers-unstable_htmlAsRichText.test.ts index b3e2c2eb..d12b456b 100644 --- a/test/helpers-unstable_htmlAsRichText.test.ts +++ b/test/helpers-unstable_htmlAsRichText.test.ts @@ -47,7 +47,9 @@ describe("transforms HTML to rich text", () => { }); testHTMLAsRichTextHelper("empty spans", { - input: /* html */ `

lorem ipsum dolor sit amet

`, + // It's normal for `dolor` and `sit` to be concatenated here. + // That how the browser would render it. + input: /* html */ `

lorem ipsum dolor sit amet

`, expectHTMLToMatchInputExactly: false, });