Skip to content

Commit ab94da3

Browse files
committedJul 23, 2024·
fix: ignore empty spans
1 parent ad9a37b commit ab94da3

3 files changed

+21
-0
lines changed
 

‎src/lib/RichTextFieldBuilder.ts

+5
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ export class RichTextFieldBuilder {
110110
}
111111
}
112112

113+
// Ignore empty spans.
114+
if (span.start === span.end) {
115+
return;
116+
}
117+
113118
// Prefer to extend the last span of the same type end
114119
// position if it ends at the start of the new span.
115120
if (this.#last.spans[lastIdenticalSpanIndex]?.end === span.start) {

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

+11
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,17 @@ exports[`transforms HTML to rich text > spans > directly adjacent spans > does n
996996
]
997997
`;
998998

999+
exports[`transforms HTML to rich text > spans > empty spans 1`] = `
1000+
[
1001+
{
1002+
"direction": "ltr",
1003+
"spans": [],
1004+
"text": "lorem ipsum dolor sit amet",
1005+
"type": "paragraph",
1006+
},
1007+
]
1008+
`;
1009+
9991010
exports[`transforms HTML to rich text > spans > hyperlink 1`] = `
10001011
[
10011012
{

‎test/helpers-unstable_htmlAsRichText.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ describe("transforms HTML to rich text", () => {
4646
expectHTMLToMatchInputExactly: false,
4747
});
4848

49+
testHTMLAsRichTextHelper("empty spans", {
50+
input: /* html */ `<p>lorem <strong></strong>ipsum dolor sit amet</p>`,
51+
expectHTMLToMatchInputExactly: false,
52+
});
53+
4954
testHTMLAsRichTextHelper("nested spans", {
5055
input: /* html */ `<p>lorem <strong>ips<em>um <a href="https://prismic.io">dolor</a></em></strong> sit amet</p>`,
5156
});

0 commit comments

Comments
 (0)
Please sign in to comment.