|
1 | 1 | /* @flow */
|
2 | 2 |
|
3 | 3 | import { CharacterMetadata, ContentBlock, genKey, Entity } from 'draft-js';
|
4 |
| -import { List, OrderedMap, OrderedSet } from 'immutable'; |
| 4 | +import { Map, List, OrderedMap, OrderedSet } from 'immutable'; |
5 | 5 | import getSafeBodyFromHTML from './getSafeBodyFromHTML';
|
6 | 6 | import {
|
7 | 7 | createTextChunk,
|
@@ -146,34 +146,33 @@ export default function htmlToDraft(html: string): Object {
|
146 | 146 | let start = 0;
|
147 | 147 | return {
|
148 | 148 | contentBlocks: chunk.text.split('\r')
|
149 |
| - .map( |
150 |
| - (textBlock, ii) => { |
151 |
| - const end = start + textBlock.length; |
152 |
| - const inlines = chunk && chunk.inlines.slice(start, end); |
153 |
| - const entities = chunk && chunk.entities.slice(start, end); |
154 |
| - const characterList = new List( |
155 |
| - inlines.map((style, index) => { |
156 |
| - const data = { style, entity: null }; |
157 |
| - if (entities[index]) { |
158 |
| - data.entity = entities[index]; |
159 |
| - } |
160 |
| - return CharacterMetadata.create(data); |
161 |
| - }), |
162 |
| - ); |
163 |
| - start = end; |
164 |
| - return new ContentBlock({ |
165 |
| - key: genKey(), |
166 |
| - type: chunk && chunk.blocks[ii].type, |
167 |
| - depth: chunk && chunk.blocks[ii].depth, |
168 |
| - data: chunk && chunk.blocks[ii].data, |
169 |
| - text: textBlock, |
170 |
| - characterList, |
171 |
| - }); |
172 |
| - }, |
173 |
| - ), |
| 149 | + .map( |
| 150 | + (textBlock, ii) => { |
| 151 | + const end = start + textBlock.length; |
| 152 | + const inlines = chunk && chunk.inlines.slice(start, end); |
| 153 | + const entities = chunk && chunk.entities.slice(start, end); |
| 154 | + const characterList = new List( |
| 155 | + inlines.map((style, index) => { |
| 156 | + const data = { style, entity: null }; |
| 157 | + if (entities[index]) { |
| 158 | + data.entity = entities[index]; |
| 159 | + } |
| 160 | + return CharacterMetadata.create(data); |
| 161 | + }), |
| 162 | + ); |
| 163 | + start = end; |
| 164 | + return new ContentBlock({ |
| 165 | + key: genKey(), |
| 166 | + type: (chunk && chunk.blocks[ii] && chunk.blocks[ii].type) || 'unstyled', |
| 167 | + depth: chunk && chunk.blocks[ii] && chunk.blocks[ii].depth, |
| 168 | + data: (chunk && chunk.blocks[ii] && chunk.blocks[ii].data) || new Map({}), |
| 169 | + text: textBlock, |
| 170 | + characterList, |
| 171 | + }); |
| 172 | + }, |
| 173 | + ), |
174 | 174 | entityMap,
|
175 | 175 | };
|
176 |
| - return null; |
177 | 176 | }
|
178 | 177 | return null;
|
179 | 178 | }
|
0 commit comments