summaryrefslogtreecommitdiff
path: root/src/NodeUtility.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/NodeUtility.php')
-rw-r--r--src/NodeUtility.php66
1 files changed, 1 insertions, 65 deletions
diff --git a/src/NodeUtility.php b/src/NodeUtility.php
index 07bc8da..d0796dd 100644
--- a/src/NodeUtility.php
+++ b/src/NodeUtility.php
@@ -1,6 +1,7 @@
<?php
namespace andreskrey\Readability;
+
use andreskrey\Readability\NodeClass\DOMDocument;
use andreskrey\Readability\NodeClass\DOMElement;
use andreskrey\Readability\NodeClass\DOMNode;
@@ -13,23 +14,6 @@ class NodeUtility
{
/**
- * @var array
- */
- private static $divToPElements = [
- 'a',
- 'blockquote',
- 'dl',
- 'div',
- 'img',
- 'ol',
- 'p',
- 'pre',
- 'table',
- 'ul',
- 'select',
- ];
-
- /**
* Collection of regexps to check the node usability
*
* @var array
@@ -177,52 +161,4 @@ class NodeUtility
return ($originalNode) ? $originalNode->nextSibling : $originalNode;
}
-
- /**
- * Checks if the current node has a single child and if that child is a P node.
- * Useful to convert <div><p> nodes to a single <p> node and avoid confusing the scoring system since div with p
- * tags are, in practice, paragraphs.
- *
- * @param DOMNode $node
- *
- * @return bool
- */
- public static function hasSinglePNode($node)
- {
- // There should be exactly 1 element child which is a P:
- if (count($children = $node->getChildren(true)) !== 1 || $children[0]->nodeName !== 'p') {
- return false;
- }
-
- // And there should be no text nodes with real content (param true on ->getChildren)
- foreach ($children as $child) {
- /** @var $child DOMNode */
- if ($child->nodeType === XML_TEXT_NODE && !preg_match('/\S$/', $child->getTextContent())) {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * @param $node DOMNode
- * @return bool
- */
- public static function hasSingleChildBlockElement($node)
- {
- $result = false;
- if ($node->hasChildNodes()) {
- foreach ($node->getChildren() as $child) {
- if (in_array($child->nodeName, self::$divToPElements)) {
- $result = true;
- } else {
- // If any of the hasSingleChildBlockElement calls return true, return true then.
- $result = ($result || self::hasSingleChildBlockElement($child));
- }
- }
- }
-
- return $result;
- }
}