MCPcopy Create free account
hub / github.com/HubSpot/draft-convert / convertFromHTMLtoContentBlocks

Function convertFromHTMLtoContentBlocks

src/convertFromHTML.js:611–673  ·  view source on GitHub ↗
(
  html,
  processCustomInlineStyles,
  checkEntityNode,
  checkEntityText,
  checkBlockType,
  createEntity,
  getEntity,
  mergeEntityData,
  replaceEntityData,
  options,
  DOMBuilder,
  generateKey
)

Source from the content-addressed store, hash-verified

609}
610
611function 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,

Callers 1

convertFromHTMLFunction · 0.85

Calls 3

getChunkForHTMLFunction · 0.85
sanitizeDraftTextFunction · 0.85
nullthrowsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…