public function replace_node_with_html( \DOMNode $node, $content ) {
		$result = $node;

		$parent = $node->parentNode;
		if ( empty( $parent ) ) {
			return $node; // abort early to save cycles.
		}

		// Encode bare < > & and decode escaped HTML tag.
		$content = RE::unescape_tags( \htmlspecialchars( $content, ENT_NOQUOTES | ENT_HTML5 | ENT_SUBSTITUTE, 'UTF-8', true ) );

		\set_error_handler( [ $this, 'handle_parsing_errors' ] ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler

		$html_fragment = $this->get_html5_parser()->loadHTMLFragment( $content );
		if ( ! empty( $html_fragment ) ) {
			$imported_fragment = $node->ownerDocument->importNode( $html_fragment, true );

			if ( ! empty( $imported_fragment ) ) {
				// Save the children of the imported DOMDocumentFragment before replacement.
				$children = DOM::nodelist_to_array( $imported_fragment->childNodes );

				if ( false !== $parent->replaceChild( $imported_fragment, $node ) ) {
					// Success! We return the saved array of DOMNodes as
					// $imported_fragment is just an empty DOMDocumentFragment now.
					$result = $children;
				}
			}
		}

		\restore_error_handler();

		return $result;
	}
public function replace_node_with_html( \DOMNode $node, $content ) {
		$result = $node;

		$parent = $node->parentNode;
		if ( empty( $parent ) ) {
			return $node; // abort early to save cycles.
		}

		// Encode bare < > & and decode escaped HTML tag.
		$content = RE::unescape_tags( \htmlspecialchars( $content, ENT_NOQUOTES | ENT_HTML5 | ENT_SUBSTITUTE, 'UTF-8', true ) );

		\set_error_handler( [ $this, 'handle_parsing_errors' ] ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler

		$html_fragment = $this->get_html5_parser()->loadHTMLFragment( $content );
		if ( ! empty( $html_fragment ) ) {
			$imported_fragment = $node->ownerDocument->importNode( $html_fragment, true );

			if ( ! empty( $imported_fragment ) ) {
				// Save the children of the imported DOMDocumentFragment before replacement.
				$children = DOM::nodelist_to_array( $imported_fragment->childNodes );

				if ( false !== $parent->replaceChild( $imported_fragment, $node ) ) {
					// Success! We return the saved array of DOMNodes as
					// $imported_fragment is just an empty DOMDocumentFragment now.
					$result = $children;
				}
			}
		}

		\restore_error_handler();

		return $result;
	}
public function replace_node_with_html ( \ DOMNode $ node , $ content ) { $ result = $ node ; $ parent = $ node -> parentNode ; if ( empty ( $ parent ) ) { return $ node ; // abort early to save cycles. } // Encode bare < > & and decode escaped HTML tag. $ content = RE :: unescape_tags ( \ htmlspecialchars ( $ content , ENT_NOQUOTES | ENT_HTML5 | ENT_SUBSTITUTE , 'UTF-8' , true ) ) ; \ set_error_handler ( [ $ this , 'handle_parsing_errors' ] ) ; // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler $ html_fragment = $ this -> get_html5_parser ( ) -> loadHTMLFragment ( $ content ) ; if ( ! empty ( $ html_fragment ) ) { $ imported_fragment = $ node -> ownerDocument -> importNode ( $ html_fragment , true ) ; if ( ! empty ( $ imported_fragment ) ) { // Save the children of the imported DOMDocumentFragment before replacement. $ children = DOM :: nodelist_to_array ( $ imported_fragment -> childNodes ) ; if ( false !== $ parent -> replaceChild ( $ imported_fragment , $ node ) ) { // Success! We return the saved array of DOMNodes as // $imported_fragment is just an empty DOMDocumentFragment now. $ result = $ children ; } } } \ restore_error_handler ( ) ; return $ result ; }
Replaces the given node with HTML content. Uses the HTML5 parser.

@param \DOMNode $node    The node to replace.
@param string   $content The HTML fragment used to replace the node.

@return \DOMNode|array An array of \DOMNode containing the new nodes or the old \DOMNode if the replacement failed.
Replaces the given node with HTML content . Uses the HTML5 parser .