Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow DOMProcessingInstruction in Readability and NodeUtility #36

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/Nodes/NodeUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use fivefilters\Readability\Nodes\DOM\DOMDocument;
use fivefilters\Readability\Nodes\DOM\DOMElement;
use fivefilters\Readability\Nodes\DOM\DOMNode;
use fivefilters\Readability\Nodes\DOM\DOMProcessingInstruction;
use fivefilters\Readability\Nodes\DOM\DOMText;
use fivefilters\Readability\Nodes\DOM\DOMComment;
use fivefilters\Readability\Nodes\DOM\DOMNodeList;
Expand Down Expand Up @@ -120,7 +121,7 @@ public static function removeNode(DOMNode|DOMComment|DOMText|DOMElement $node):
* Returns the next node. First checks for children (if the flag allows it), then for siblings, and finally
* for parents.
*/
public static function getNextNode(DOMNode|DOMComment|DOMText|DOMElement|DOMDocument $originalNode, bool $ignoreSelfAndKids = false): DOMNode|DOMComment|DOMText|DOMElement|DOMDocument|null
public static function getNextNode(DOMNode|DOMComment|DOMText|DOMElement|DOMDocument|DOMProcessingInstruction $originalNode, bool $ignoreSelfAndKids = false): DOMNode|DOMComment|DOMText|DOMElement|DOMDocument|DOMProcessingInstruction|null
{
/*
* Traverse the DOM from node to node, starting at the node passed in.
Expand Down
9 changes: 5 additions & 4 deletions src/Readability.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use fivefilters\Readability\Nodes\DOM\DOMDocument;
use fivefilters\Readability\Nodes\DOM\DOMElement;
use fivefilters\Readability\Nodes\DOM\DOMNode;
use fivefilters\Readability\Nodes\DOM\DOMProcessingInstruction;
use fivefilters\Readability\Nodes\DOM\DOMText;
use fivefilters\Readability\Nodes\DOM\DOMComment;
use fivefilters\Readability\Nodes\NodeUtility;
Expand Down Expand Up @@ -391,7 +392,7 @@ private function getJSONLD(DOMDocument $dom): array
return $metadata;
} catch (\Exception $err) {
// The try-catch blocks are from the JS version. Not sure if there's anything
// here in the PHP version that would trigger an error or exception, so perhaps we can
// here in the PHP version that would trigger an error or exception, so perhaps we can
// remove the try-catch blocks here (or at least translate errors to exceptions for this bit)
$this->logger->debug('[JSON-LD] Error parsing: ' . $err->getMessage());
}
Expand All @@ -418,7 +419,7 @@ private function getMetadata(): void
/* @var DOMNode $meta */
$elementName = $meta->getAttribute('name');
$elementProperty = $meta->getAttribute('property');
$content = $meta->getAttribute('content');
$content = $meta->getAttribute('content');
$matches = null;
$name = null;

Expand Down Expand Up @@ -960,7 +961,7 @@ private function textSimilarity(string $textA, string $textB): float
/**
* Checks if the node is a byline.
*/
private function checkByline(DOMNode|DOMText|DOMElement $node, string $matchString): bool
private function checkByline(DOMNode|DOMText|DOMElement|DOMProcessingInstruction $node, string $matchString): bool
{
if (!$this->configuration->getArticleByline()) {
return false;
Expand Down Expand Up @@ -2043,7 +2044,7 @@ public function _cleanHeaders(DOMDocument $article): void
* @param DOMNode the node to check.
* @return boolean indicating whether this is a title-like header.
*/
private function headerDuplicatesTitle(DOMNode|DOMText|DOMElement $node): bool
private function headerDuplicatesTitle(DOMNode|DOMText|DOMElement|DOMProcessingInstruction $node): bool
{
if ($node->nodeName !== 'h1' && $node->nodeName !== 'h2') {
return false;
Expand Down