Skip to content
Open
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: 6 additions & 3 deletions src/Readability.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,17 @@ public function prepArticle(\DOMNode $articleContent): void
$this->clean($articleContent, 'object');
$this->clean($articleContent, 'iframe');
$this->clean($articleContent, 'canvas');
$this->clean($articleContent, 'h1');

/*
* If there is only one h2, they are probably using it as a main header, so remove it since we
* If there is only one h1 or h2, they are probably using it as a main header, so remove it since we
* already have a header.
*/
$h1s = $articleContent->getElementsByTagName('h1');
if (1 === $h1s->length && mb_strlen($this->getInnerText($h1s->item(0), true, true)) < 100) {
$this->clean($articleContent, 'h1');
}
$h2s = $articleContent->getElementsByTagName('h2');
if (1 === $h2s->length && mb_strlen($this->getInnerText($h2s->item(0), true, true)) < 100) {
if (0 === $h1s->length && 1 === $h2s->length && mb_strlen($this->getInnerText($h2s->item(0), true, true)) < 100) {
$this->clean($articleContent, 'h2');
}

Expand Down