Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit 732b69d

Browse files
Nicolas Champsavoirfacebook-github-bot
Nicolas Champsavoir
authored andcommitted
Refactor convertFromHTMLtoContentBlocks
Summary: One of the utility helper methods commonly used to manage state with Draft.js is the `convertFromHTMLtoContentBlocks` method, which converts an HTML string into a data structure used by Draft.js for tracking state. This is a helpful utility, but it was written in an overly complex way. This commits adds a new simpler implementation of `convertFromHTMLToContentBlocks`. Reviewed By: flarnie Differential Revision: D7158000 fbshipit-source-id: 3424cdeb03663dc6c5a194da3d317c6ab97507dc
1 parent 6ef6c66 commit 732b69d

6 files changed

+3367
-1
lines changed

src/model/encoding/__tests__/__snapshots__/convertFromHTMLToContentBlocks-test.js.snap

+114
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,120 @@ Array [
660660
]
661661
`;
662662

663+
exports[`Should preserve spacing around inline tags 1`] = `
664+
Array [
665+
Object {
666+
"characterList": Array [
667+
Object {
668+
"entity": null,
669+
"style": Array [],
670+
},
671+
Object {
672+
"entity": null,
673+
"style": Array [],
674+
},
675+
Object {
676+
"entity": null,
677+
"style": Array [],
678+
},
679+
Object {
680+
"entity": null,
681+
"style": Array [],
682+
},
683+
Object {
684+
"entity": null,
685+
"style": Array [],
686+
},
687+
Object {
688+
"entity": null,
689+
"style": Array [
690+
"ITALIC",
691+
],
692+
},
693+
Object {
694+
"entity": null,
695+
"style": Array [
696+
"ITALIC",
697+
],
698+
},
699+
Object {
700+
"entity": null,
701+
"style": Array [
702+
"ITALIC",
703+
],
704+
},
705+
Object {
706+
"entity": null,
707+
"style": Array [
708+
"ITALIC",
709+
],
710+
},
711+
Object {
712+
"entity": null,
713+
"style": Array [
714+
"ITALIC",
715+
],
716+
},
717+
Object {
718+
"entity": null,
719+
"style": Array [
720+
"ITALIC",
721+
],
722+
},
723+
Object {
724+
"entity": null,
725+
"style": Array [
726+
"ITALIC",
727+
],
728+
},
729+
Object {
730+
"entity": null,
731+
"style": Array [
732+
"ITALIC",
733+
],
734+
},
735+
Object {
736+
"entity": null,
737+
"style": Array [],
738+
},
739+
Object {
740+
"entity": null,
741+
"style": Array [
742+
"BOLD",
743+
],
744+
},
745+
Object {
746+
"entity": null,
747+
"style": Array [
748+
"BOLD",
749+
],
750+
},
751+
Object {
752+
"entity": null,
753+
"style": Array [
754+
"BOLD",
755+
],
756+
},
757+
Object {
758+
"entity": null,
759+
"style": Array [
760+
"BOLD",
761+
],
762+
},
763+
],
764+
"children": Array [],
765+
"data": Object {},
766+
"depth": 0,
767+
"key": "key0",
768+
"nextSibling": null,
769+
"parent": undefined,
770+
"prevSibling": null,
771+
"text": "Some stylised text",
772+
"type": "unstyled",
773+
},
774+
]
775+
`;
776+
663777
exports[`converts deeply nested html blocks when experimentalTreeDataSupport is enabled 1`] = `
664778
Array [
665779
Object {

0 commit comments

Comments
 (0)