public static function highlightNode(DOMNode $node, $prepend, $append)
	{
		// Create a copy of the document that we can modify without side effects
		$dom = $node->ownerDocument->cloneNode(true);
		$dom->formatOutput = true;

		$xpath = new DOMXPath($dom);
		$node  = $xpath->query($node->getNodePath())->item(0);

		// Add a unique token to the node
		$uniqid = uniqid('_');
		if ($node instanceof DOMAttr)
		{
			$node->value .= $uniqid;
		}
		elseif ($node instanceof DOMElement)
		{
			$node->setAttribute($uniqid, '');
		}
		elseif ($node instanceof DOMCharacterData || $node instanceof DOMProcessingInstruction)
		{
			$node->data .= $uniqid;
		}

		$docXml = TemplateLoader::innerXML($dom->documentElement);
		$docXml = trim(str_replace("\n  ", "\n", $docXml));

		$nodeHtml = htmlspecialchars(trim($dom->saveXML($node)));
		$docHtml  = htmlspecialchars($docXml);

		// Enclose the node's representation in our highlighting HTML
		$html = str_replace($nodeHtml, $prepend . $nodeHtml . $append, $docHtml);

		// Remove the unique token from HTML
		$html = str_replace(' ' . $uniqid . '=&quot;&quot;', '', $html);
		$html = str_replace($uniqid, '', $html);

		return $html;
	}
public static function highlightNode(DOMNode $node, $prepend, $append)
	{
		// Create a copy of the document that we can modify without side effects
		$dom = $node->ownerDocument->cloneNode(true);
		$dom->formatOutput = true;

		$xpath = new DOMXPath($dom);
		$node  = $xpath->query($node->getNodePath())->item(0);

		// Add a unique token to the node
		$uniqid = uniqid('_');
		if ($node instanceof DOMAttr)
		{
			$node->value .= $uniqid;
		}
		elseif ($node instanceof DOMElement)
		{
			$node->setAttribute($uniqid, '');
		}
		elseif ($node instanceof DOMCharacterData || $node instanceof DOMProcessingInstruction)
		{
			$node->data .= $uniqid;
		}

		$docXml = TemplateLoader::innerXML($dom->documentElement);
		$docXml = trim(str_replace("\n  ", "\n", $docXml));

		$nodeHtml = htmlspecialchars(trim($dom->saveXML($node)));
		$docHtml  = htmlspecialchars($docXml);

		// Enclose the node's representation in our highlighting HTML
		$html = str_replace($nodeHtml, $prepend . $nodeHtml . $append, $docHtml);

		// Remove the unique token from HTML
		$html = str_replace(' ' . $uniqid . '=&quot;&quot;', '', $html);
		$html = str_replace($uniqid, '', $html);

		return $html;
	}
public static function highlightNode ( DOMNode $ node , $ prepend , $ append ) { // Create a copy of the document that we can modify without side effects $ dom = $ node -> ownerDocument -> cloneNode ( true ) ; $ dom -> formatOutput = true ; $ xpath = new DOMXPath ( $ dom ) ; $ node = $ xpath -> query ( $ node -> getNodePath ( ) ) -> item ( 0 ) ; // Add a unique token to the node $ uniqid = uniqid ( '_' ) ; if ( $ node instanceof DOMAttr ) { $ node -> value .= $ uniqid ; } elseif ( $ node instanceof DOMElement ) { $ node -> setAttribute ( $ uniqid , '' ) ; } elseif ( $ node instanceof DOMCharacterData || $ node instanceof DOMProcessingInstruction ) { $ node -> data .= $ uniqid ; } $ docXml = TemplateLoader :: innerXML ( $ dom -> documentElement ) ; $ docXml = trim ( str_replace ( "\n  " , "\n" , $ docXml ) ) ; $ nodeHtml = htmlspecialchars ( trim ( $ dom -> saveXML ( $ node ) ) ) ; $ docHtml = htmlspecialchars ( $ docXml ) ; // Enclose the node's representation in our highlighting HTML $ html = str_replace ( $ nodeHtml , $ prepend . $ nodeHtml . $ append , $ docHtml ) ; // Remove the unique token from HTML $ html = str_replace ( ' ' . $ uniqid . '=&quot;&quot;' , '' , $ html ) ; $ html = str_replace ( $ uniqid , '' , $ html ) ; return $ html ; }
Highlight the source of a node inside of a template

@param  DOMNode $node    Node to highlight
@param  string  $prepend HTML to prepend
@param  string  $append  HTML to append
@return string           Template's source, as HTML
Highlight the source of a node inside of a template