diff --git a/src/draftConverter.ts b/src/draftConverter.ts index 2249588..8630b42 100644 --- a/src/draftConverter.ts +++ b/src/draftConverter.ts @@ -207,7 +207,8 @@ export class DraftConverter { // Split the text into groups by their range let currentRanges: (RawDraftEntityRange | RawDraftInlineStyleRange)[] = []; let currentText: string = ""; - for (let i = 0; i < options.block.text.length; i++) { + const text = Array.from(options.block.text); + for (let i = 0; i < text.length; i++) { let styles = stylesAtPosition[i] || []; if ( styles.length !== currentRanges.length || @@ -219,7 +220,8 @@ export class DraftConverter { currentText = ""; currentRanges = styles; } - currentText += options.block.text[i]; + + currentText += text[i]; } if (currentText) { diff --git a/test/draft-inputs.test.ts b/test/draft-inputs.test.ts index e33fa11..9cd3557 100644 --- a/test/draft-inputs.test.ts +++ b/test/draft-inputs.test.ts @@ -36,3 +36,101 @@ test("draft-medium-complex", () => { const converter = new DraftConverter(); expect(converter.convert(draftMediumComplex as any)).toMatchSnapshot(); }); + +test("draft-medium-complex", () => { + const converter = new DraftConverter(); + expect( + converter.convert({ + blocks: [ + { + key: "a5rh8", + text: "πŸ•ΊπŸ½ Krewe of Boo hosts a jazz second-line through the French Quarter at 3pm, followed by happy hour at Pat O'Brien's. (Details)", + type: "unstyled", + depth: 0, + inlineStyleRanges: [ + { + style: "BOLD", + length: 12, + offset: 3, + }, + { + style: "ITALIC", + length: 7, + offset: 118, + }, + ], + entityRanges: [ + { + offset: 118, + length: 7, + key: 0, + }, + ], + data: {}, + }, + ], + // @ts-ignore + entityMap: [ + { + type: "LINK", + mutability: "MUTABLE", + data: { + rel: "noreferrer", + url: "https://www.kreweofboo.com/secondline", + href: "https://www.kreweofboo.com/secondline", + target: "_blank", + }, + }, + ], + }) + ).toEqual({ + type: "doc", + content: [ + { + type: "paragraph", + content: [ + { + type: "text", + text: "πŸ•ΊπŸ½ ", + marks: [], + }, + { + type: "text", + text: "Krewe of Boo", + marks: [ + { + type: "bold", + }, + ], + }, + { + type: "text", + text: " hosts a jazz second-line through the French Quarter at 3pm, followed by happy hour at Pat O'Brien's. (", + marks: [], + }, + { + type: "text", + text: "Details", + marks: [ + { + type: "link", + attrs: { + href: "https://www.kreweofboo.com/secondline", + target: "_blank", + }, + }, + { + type: "italic", + }, + ], + }, + { + type: "text", + text: ")", + marks: [], + }, + ], + }, + ], + }); +});