From f00f598014db90593ebb9e2a647655b86cf602c1 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 12 Feb 2015 10:24:55 +0100 Subject: [PATCH] doc/lib: Fix undefined entity   and too greedy regex --- .../library/Doc/Renderer/DocSectionRenderer.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/doc/library/Doc/Renderer/DocSectionRenderer.php b/modules/doc/library/Doc/Renderer/DocSectionRenderer.php index 668e2fb56..e6f0ea186 100644 --- a/modules/doc/library/Doc/Renderer/DocSectionRenderer.php +++ b/modules/doc/library/Doc/Renderer/DocSectionRenderer.php @@ -125,9 +125,7 @@ class DocSectionRenderer extends DocRenderer protected function highlightSearch($html, DocSearch $search) { $doc = new DOMDocument(); - $fragment = $doc->createDocumentFragment(); - $fragment->appendXML($html); - $doc->appendChild($fragment); + @$doc->loadHTML($html); $iter = new RecursiveIteratorIterator(new DomNodeIterator($doc), RecursiveIteratorIterator::SELF_FIRST); foreach ($iter as $node) { if ($node->nodeType !== XML_TEXT_NODE @@ -152,7 +150,10 @@ class DocSectionRenderer extends DocRenderer $fragment->appendChild($doc->createTextNode(substr($text, $offset))); $node->parentNode->replaceChild($fragment, $node); } - return $doc->saveHTML(); + // Remove removeChild($doc->doctype); + // Remove and + return substr($doc->saveHTML(), 12, -15); } /** @@ -250,14 +251,14 @@ class DocSectionRenderer extends DocRenderer $section->getLevel(), $title ); - $content = $this->parsedown->text(implode('', $section->getContent())); - if (empty($content)) { + $html = $this->parsedown->text(implode('', $section->getContent())); + if (empty($html)) { continue; } $html = preg_replace_callback( '#
(.*?)
#s', array($this, 'highlightPhp'), - $content + $html ); $html = preg_replace_callback( '/]+>/', @@ -270,7 +271,7 @@ class DocSectionRenderer extends DocRenderer $html ); $html = preg_replace_callback( - '/[^>]*?\s+)?href="(?:(?!http:\/\/)[^#]*)#(?P[^"]+)"/', + '/[^>]*?\s+)?href="(?:(?!http:\/\/)[^"#]*)#(?P[^"]+)"/', array($this, 'replaceLink'), $html );