summaryrefslogtreecommitdiffstats
path: root/articleenhancer
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-09-29 14:08:27 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-09-29 14:08:27 +0200
commitd4f19a20c64aa9abcf396a252f5057139770ac1e (patch)
treee4abc873acb80b445ff28f729b26d371edf13fa1 /articleenhancer
parentade0ecb98ba1cdc5436b70e2eca5c5ea6356b0da (diff)
require libxml
Diffstat (limited to 'articleenhancer')
-rw-r--r--articleenhancer/globalarticleenhancer.php13
1 files changed, 6 insertions, 7 deletions
diff --git a/articleenhancer/globalarticleenhancer.php b/articleenhancer/globalarticleenhancer.php
index 1b6713ef7..7411d0adc 100644
--- a/articleenhancer/globalarticleenhancer.php
+++ b/articleenhancer/globalarticleenhancer.php
@@ -24,7 +24,12 @@ class GlobalArticleEnhancer implements ArticleEnhancer {
*/
public function enhance(Item $item) {
$dom = new \DOMDocument();
- @$dom->loadHTML($item->getBody());
+
+ // wrap it inside a div if there is none to prevent invalid wrapping
+ // inside <p> tags
+ $body = '<div>' . $item->getBody() . '</div>';
+
+ @$dom->loadHTML($body, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$xpath = new \DOMXpath($dom);
// remove youtube autoplay
@@ -45,12 +50,6 @@ class GlobalArticleEnhancer implements ArticleEnhancer {
}
}
- // remove <!DOCTYPE
- $dom->removeChild($dom->firstChild);
-
- // remove <html><body></body></html>
- $dom->replaceChild($dom->firstChild->firstChild->firstChild, $dom->firstChild);
-
// save all changes back to the item
$item->setBody(trim($dom->saveHTML()));