Skip to content

Commit 4dcb9da

Browse files
committed
Fix issue in converting html with entity
1 parent c8c5557 commit 4dcb9da

File tree

5 files changed

+11
-14
lines changed

5 files changed

+11
-14
lines changed

dist/html-to-draftjs.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-to-draftjs",
3-
"version": "0.1.0-beta8",
3+
"version": "0.1.0-beta9",
44
"main": "dist/html-to-draftjs.js",
55
"repository": {
66
"type": "git",
@@ -15,7 +15,7 @@
1515
"draftjs-to-html": "^0.6.3",
1616
"react": "^15.4.2",
1717
"react-dom": "^15.4.2",
18-
"react-draft-wysiwyg": "^1.7.6",
18+
"react-draft-wysiwyg": "^1.10.7",
1919
"react-scripts": "0.9.5",
2020
"rimraf": "^2.6.1",
2121
"webpack": "^2.2.1"

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Playground extends Component {
1818

1919
constructor(props) {
2020
super(props)
21-
const html = '<p>123</p>'
21+
const html = '<p>123</p><p></p><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSvGBbRtzgNfNaHPP9X28Gj6OQF0l6ZaiqgxJlujX5QsE5g35Or18WijxY3" alt="undefined" style="float:none;height: auto;width: auto"/><p>456</p>'
2222
const contentBlock = htmlToDraft(html);
2323
if (contentBlock) {
2424
const contentState = ContentState.createFromBlockArray(contentBlock.contentBlocks);

src/library/chunkBuilder.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ const getEmptyChunk = (): Object => {
4141
text: '',
4242
inlines: [],
4343
entities: [],
44-
blocks: [{
45-
type: 'unstyled',
46-
depth: 0,
47-
data: new Map({}),
48-
}],
44+
blocks: [],
4945
};
5046
};
5147

src/library/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ function genFragment(
116116
const sibling = child.nextSibling;
117117
child = sibling;
118118
}
119-
120119
return { chunk };
121120
}
122121

@@ -136,9 +135,11 @@ export default function htmlToDraft(html: string): Object {
136135
if (chunkData) {
137136
const { chunk } = chunkData;
138137
let entityMap = new OrderedMap({});
139-
// chunk.entities && chunk.entities.forEach(entity => {
140-
// entityMap = entityMap.set(entity, Entity.get(entity));
141-
// });
138+
chunk.entities && chunk.entities.forEach(entity => {
139+
if (entity) {
140+
entityMap = entityMap.set(entity, Entity.get(entity));
141+
}
142+
});
142143
let start = 0;
143144
return {
144145
contentBlocks: chunk.text.split('\r')

0 commit comments

Comments
 (0)