$codehl = str_replace(array('$$$$$', '£££££'), array('>', '<'), $codehl); $codehl = preg_replace("!\n\n\n+!", "\n\n", $codehl); $codehl = trim($codehl); return $codehl; } private static function _createBlockCode($code) { $dom = new DomDocument(); $dom->loadXML($code); $xpath = new DomXPath($dom); $parentSpan = $xpath->query('/span')->item(0); $block_code = self::$_dom->createElement('fo:inline'); $block_code->setAttribute('color', substr($parentSpan->getAttributeNode('style')->value, 7, 7)); $nodes = $xpath->query('/span/node()'); foreach ($nodes as $node) { if ($node->nodeType == XML_ELEMENT_NODE) { $child = self::$_dom->createElement('fo:inline', $node->nodeValue); $child->setAttribute('color', substr($node->getAttributeNode('style')->value, 7, 7)); } else { $child = self::$_dom->importNode($node, true); } $block_code->appendChild($child); } if (preg_match("/^\\s+\$/", $block_code->firstChild->textContent)) { $block_code->removeChild($block_code->firstChild); } return $block_code; } } HighlightPDF::main($argv[1]);