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

Function getChunkForHTML

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

Source from the content-addressed store, hash-verified

526}
527
528function getChunkForHTML(
529 html,
530 processCustomInlineStyles,
531 checkEntityNode,
532 checkEntityText,
533 checkBlockType,
534 createEntity,
535 getEntity,
536 mergeEntityData,
537 replaceEntityData,
538 options,
539 DOMBuilder
540) {
541 html = html
542 .trim()
543 .replace(REGEX_CR, '')
544 .replace(REGEX_NBSP, SPACE);
545
546 const safeBody = DOMBuilder(html);
547 if (!safeBody) {
548 return null;
549 }
550
551 // Sometimes we aren't dealing with content that contains nice semantic
552 // tags. In this case, use divs to separate everything out into paragraphs
553 // and hope for the best.
554 const workingBlocks = containsSemanticBlockMarkup(html)
555 ? blockTags.concat(['div'])
556 : ['div'];
557
558 // Start with -1 block depth to offset the fact that we are passing in a fake
559 // UL block to sta rt with.
560 let chunk = genFragment(
561 safeBody,
562 OrderedSet(),
563 'ul',
564 null,
565 workingBlocks,
566 -1,
567 processCustomInlineStyles,
568 checkEntityNode,
569 checkEntityText,
570 checkBlockType,
571 createEntity,
572 getEntity,
573 mergeEntityData,
574 replaceEntityData,
575 options
576 );
577
578 // join with previous block to prevent weirdness on paste
579 if (chunk.text.indexOf('\r') === 0) {
580 chunk = {
581 text: chunk.text.slice(1),
582 inlines: chunk.inlines.slice(1),
583 entities: chunk.entities.slice(1),
584 blocks: chunk.blocks,
585 };

Callers 1

Calls 2

genFragmentFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…