( html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder, generateKey )
| 609 | } |
| 610 | |
| 611 | function convertFromHTMLtoContentBlocks( |
| 612 | html, |
| 613 | processCustomInlineStyles, |
| 614 | checkEntityNode, |
| 615 | checkEntityText, |
| 616 | checkBlockType, |
| 617 | createEntity, |
| 618 | getEntity, |
| 619 | mergeEntityData, |
| 620 | replaceEntityData, |
| 621 | options, |
| 622 | DOMBuilder, |
| 623 | generateKey |
| 624 | ) { |
| 625 | // Be ABSOLUTELY SURE that the dom builder you pass hare won't execute |
| 626 | // arbitrary code in whatever environment you're running this in. For an |
| 627 | // example of how we try to do this in-browser, see getSafeBodyFromHTML. |
| 628 | |
| 629 | const chunk = getChunkForHTML( |
| 630 | html, |
| 631 | processCustomInlineStyles, |
| 632 | checkEntityNode, |
| 633 | checkEntityText, |
| 634 | checkBlockType, |
| 635 | createEntity, |
| 636 | getEntity, |
| 637 | mergeEntityData, |
| 638 | replaceEntityData, |
| 639 | options, |
| 640 | DOMBuilder, |
| 641 | generateKey |
| 642 | ); |
| 643 | if (chunk == null) { |
| 644 | return []; |
| 645 | } |
| 646 | let start = 0; |
| 647 | return chunk.text.split('\r').map((textBlock, blockIndex) => { |
| 648 | // Make absolutely certain that our text is acceptable. |
| 649 | textBlock = sanitizeDraftText(textBlock); |
| 650 | const end = start + textBlock.length; |
| 651 | const inlines = nullthrows(chunk).inlines.slice(start, end); |
| 652 | const entities = nullthrows(chunk).entities.slice(start, end); |
| 653 | const characterList = List( |
| 654 | inlines.map((style, entityIndex) => { |
| 655 | const data = { style, entity: null }; |
| 656 | if (entities[entityIndex]) { |
| 657 | data.entity = entities[entityIndex]; |
| 658 | } |
| 659 | return CharacterMetadata.create(data); |
| 660 | }) |
| 661 | ); |
| 662 | start = end + 1; |
| 663 | |
| 664 | return new ContentBlock({ |
| 665 | key: generateKey(), |
| 666 | type: nullthrows(chunk).blocks[blockIndex].type, |
| 667 | data: nullthrows(chunk).blocks[blockIndex].data, |
| 668 | depth: nullthrows(chunk).blocks[blockIndex].depth, |
no test coverage detected
searching dependent graphs…