* Parse an HTML fragment in the target document and return its single root * element, or null when it is empty, multi-root, or contains a . * The dispatch path skips validateOp, so these guards are re-enforced here: * never insert raw , never silently drop extra roots.
(document: Document, html: string)
| 678 | * never insert raw <script>, never silently drop extra roots. |
| 679 | */ |
| 680 | function parseInsertableFragment(document: Document, html: string): Element | null { |
| 681 | // Same temp-div approach as apply-patches.ts to avoid cross-document issues. |
| 682 | const tmp = document.createElement("div"); |
| 683 | tmp.innerHTML = html; |
| 684 | if (tmp.querySelector("script")) return null; |
| 685 | const node = tmp.firstElementChild; |
| 686 | if (!node || node.nextElementSibling) return null; |
| 687 | return node; |
| 688 | } |
| 689 | |
| 690 | function handleAddElement( |
| 691 | parsed: ParsedDocument, |
no test coverage detected