Skip to content

Commit 6d1ce03

Browse files
committedJul 23, 2024·
fix: ignore trimmed empty spans
1 parent 19819cf commit 6d1ce03

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed
 

‎src/lib/hastToRichText.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export const hastToRichText = (
157157
case RichTextNodeType.em:
158158
case RichTextNodeType.label:
159159
case RichTextNodeType.hyperlink: {
160-
const length = toString(node).length;
160+
const length = toString(node).trimEnd().length;
161161

162162
try {
163163
builder.appendSpan(shorthandOrNode, length);
@@ -238,7 +238,7 @@ export const hastToRichText = (
238238
case RichTextNodeType.label:
239239
case RichTextNodeType.hyperlink: {
240240
const span = serializeSpan(node, match);
241-
const length = toString(node).length;
241+
const length = toString(node).trimEnd().length;
242242

243243
try {
244244
builder.appendSpan(span, length);

‎test/__snapshots__/helpers-unstable_htmlAsRichText.test.ts.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ exports[`transforms HTML to rich text > spans > empty spans 1`] = `
10011001
{
10021002
"direction": "ltr",
10031003
"spans": [],
1004-
"text": "lorem ipsum dolor sit amet",
1004+
"text": "lorem ipsum dolorsit amet",
10051005
"type": "paragraph",
10061006
},
10071007
]

‎test/helpers-unstable_htmlAsRichText.test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ describe("transforms HTML to rich text", () => {
4747
});
4848

4949
testHTMLAsRichTextHelper("empty spans", {
50-
input: /* html */ `<p>lorem <strong></strong>ipsum dolor sit amet</p>`,
50+
// It's normal for `dolor` and `sit` to be concatenated here.
51+
// That how the browser would render it.
52+
input: /* html */ `<p>lorem <strong></strong>ipsum dolor<em> </em>sit amet</p>`,
5153
expectHTMLToMatchInputExactly: false,
5254
});
5355

0 commit comments

Comments
 (0)
Please sign in to comment.