Skip to content

Commit aee53ce

Browse files
authored
Merge branch 'master' into master
2 parents 92cc19e + 65cef66 commit aee53ce

File tree

8 files changed

+1032
-1129
lines changed

8 files changed

+1032
-1129
lines changed

dist/html-to-draftjs.js

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-to-draftjs",
3-
"version": "0.1.0-beta7",
3+
"version": "0.1.0-beta11",
44
"main": "dist/html-to-draftjs.js",
55
"repository": {
66
"type": "git",
@@ -12,10 +12,10 @@
1212
"babel-preset-stage-0": "^6.22.0",
1313
"chai": "^3.5.0",
1414
"draft-js": "^0.10.0",
15-
"draftjs-to-html": "^0.6.3",
15+
"draftjs-to-html": "^0.7.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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ 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) {
24-
const contentState = ContentState.createFromBlockArray(contentBlock.contentBlocks);
24+
const contentState = ContentState.createFromBlockArray(contentBlock.contentBlocks, contentBlock.entityMap);
2525
const inputEditorState = EditorState.createWithContent(contentState);
2626
this.state = {
2727
inputEditorState,

src/library/__tests__/mainTest.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ describe('htmlToDraft test suite', () => {
99
contentBlocks = htmlToDraft('<p>test</p>');
1010
console.log('contentBlocks', contentBlocks);
1111

12+
contentBlocks = htmlToDraft('<div>test</div>');
13+
console.log('contentBlocks', contentBlocks);
14+
1215
contentBlocks = htmlToDraft('<h1>test</h1>');
1316
console.log('contentBlocks', contentBlocks);
1417

src/library/getBlockTypeForTag.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const blockRenderMap = new Map({
3535
},
3636
unstyled: {
3737
element: 'p',
38+
aliasedElements: ['div']
3839
},
3940
});
4041

@@ -47,7 +48,8 @@ export default function getBlockTypeForTag(
4748
return (
4849
(draftBlock.element === tag &&
4950
(!draftBlock.wrapper || draftBlock.wrapper === lastList)) ||
50-
draftBlock.wrapper === tag
51+
draftBlock.wrapper === tag ||
52+
(draftBlock.aliasedElements && draftBlock.aliasedElements.indexOf(tag) > -1)
5153
)})
5254
.keySeq()
5355
.toSet()

src/library/getEntityId.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ const getEntityId = (node) => {
1010
entityConfig.url = node.href;
1111
entityConfig.text = node.innerHTML;
1212
entityConfig.value = node.dataset.value;
13-
entityId = Entity.create(
13+
entityId = Entity.__create(
1414
'MENTION',
1515
'IMMUTABLE',
1616
entityConfig,
1717
);
1818
} else {
19-
entityConfig.url = node.href;
19+
entityConfig.url = node.getAttribute('href') || node.href;
2020
entityConfig.title = node.innerHTML;
21-
entityId = Entity.create(
21+
entityConfig.target = node.target;
22+
entityId = Entity.__create(
2223
'LINK',
2324
'MUTABLE',
2425
entityConfig,

src/library/index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@ function genFragment(
4545
) {
4646
const entityConfig = {};
4747
entityConfig.src = node.getAttribute ? node.getAttribute('src') || node.src : node.src;
48+
entityConfig.alt = node.alt;
4849
entityConfig.height = node.style.height;
4950
entityConfig.width = node.style.width;
50-
const entityId = Entity.create(
51+
if (node.style.float) {
52+
entityConfig.alignment = node.style.float;
53+
}
54+
const entityId = Entity.__create(
5155
'IMAGE',
5256
'MUTABLE',
5357
entityConfig,
@@ -63,7 +67,7 @@ function genFragment(
6367
entityConfig.src = node.src;
6468
entityConfig.height = node.height;
6569
entityConfig.width = node.width;
66-
const entityId = Entity.create(
70+
const entityId = Entity.__create(
6771
'EMBEDDED_LINK',
6872
'MUTABLE',
6973
entityConfig,
@@ -115,7 +119,6 @@ function genFragment(
115119
const sibling = child.nextSibling;
116120
child = sibling;
117121
}
118-
119122
return { chunk };
120123
}
121124

@@ -135,9 +138,11 @@ export default function htmlToDraft(html: string): Object {
135138
if (chunkData) {
136139
const { chunk } = chunkData;
137140
let entityMap = new OrderedMap({});
138-
// chunk.entities && chunk.entities.forEach(entity => {
139-
// entityMap = entityMap.set(entity, Entity.get(entity));
140-
// });
141+
chunk.entities && chunk.entities.forEach(entity => {
142+
if (entity) {
143+
entityMap = entityMap.set(entity, Entity.__get(entity));
144+
}
145+
});
141146
let start = 0;
142147
return {
143148
contentBlocks: chunk.text.split('\r')

0 commit comments

Comments
 (0)