MCPcopy
hub / github.com/codex-team/editor.js / processHTML

Method processHTML

src/components/modules/paste.ts:579–701  ·  view source on GitHub ↗

* Split HTML string to blocks and return it as array of Block data * * @param {string} innerHTML - html string to process * @returns {PasteData[]}

(innerHTML: string)

Source from the content-addressed store, hash-verified

577 * @returns {PasteData[]}
578 */
579 private processHTML(innerHTML: string): PasteData[] {
580 const { Tools } = this.Editor;
581
582 /**
583 * @todo Research, do we really need to always wrap innerHTML to a div:
584 * - <img> tag could be processed separately, but for now it becomes div-wrapped
585 * and then .getNodes() returns strange: [document-fragment, img]
586 * (description of the method says that it should should return only block tags or fragments,
587 * but there are inline-block element along with redundant empty fragment)
588 * - probably this is a reason of bugs with unexpected new block creation instead of inline pasting:
589 * - https://github.com/codex-team/editor.js/issues/1427
590 * - https://github.com/codex-team/editor.js/issues/1244
591 * - https://github.com/codex-team/editor.js/issues/740
592 */
593 const wrapper = $.make('DIV');
594
595 wrapper.innerHTML = innerHTML;
596
597 const nodes = this.getNodes(wrapper);
598
599 return nodes
600 .map((node) => {
601 let content, tool = Tools.defaultTool, isBlock = false;
602
603 switch (node.nodeType) {
604 /** If node is a document fragment, use temp wrapper to get innerHTML */
605 case Node.DOCUMENT_FRAGMENT_NODE:
606 content = $.make('div');
607 content.appendChild(node);
608 break;
609
610 /** If node is an element, then there might be a substitution */
611 case Node.ELEMENT_NODE:
612 content = node as HTMLElement;
613 isBlock = true;
614
615 if (this.toolsTags[content.tagName]) {
616 tool = this.toolsTags[content.tagName].tool;
617 }
618 break;
619 }
620
621 /**
622 * Returns empty array if there is no paste config
623 */
624 const { tags: tagsOrSanitizeConfigs } = tool.pasteConfig || { tags: [] };
625
626 /**
627 * Reduce the tags or sanitize configs to a single array of sanitize config.
628 * For example:
629 * If sanitize config is
630 * [ 'tbody',
631 * {
632 * table: {
633 * width: true,
634 * height: true,
635 * },
636 * },

Callers 1

processTextMethod · 0.95

Calls 8

getNodesMethod · 0.95
collectTagNamesMethod · 0.95
composePasteEventMethod · 0.95
cleanFunction · 0.90
forEachMethod · 0.80
isSingleTagMethod · 0.80
makeMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected