Skip to content
This repository was archived by the owner on Aug 14, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/HTMLParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,9 @@ public function prepArticle(DOMDocument $article)
$this->_clean($article, 'h1');
$this->_clean($article, 'footer');

// Readability.js cleans styles on prepDocument but we do it here.
$this->_clean($article, 'style');

// If there is only one h2, they are probably using it as a header
// and not a subheader, so remove it since we already have a header.
if ($article->getElementsByTagName('h2')->length === 1) {
Expand Down Expand Up @@ -957,7 +960,11 @@ public function _clean(DOMDocument $article, $tag)
{
$isEmbed = in_array($tag, ['object', 'embed', 'iframe']);

foreach ($article->getElementsByTagName($tag) as $item) {
$DOMNodeList = $article->getElementsByTagName($tag);
$length = $DOMNodeList->length;
for ($i = 0; $i < $length; $i++) {
$item = $DOMNodeList->item($length - 1 - $i);

// Allow youtube and vimeo videos through as people usually want to see those.
if ($isEmbed) {
$attributeValues = [];
Expand Down