mirror of
https://github.com/j0k3r/php-readability.git
synced 2026-09-27 06:26:17 +00:00
@@ -7,3 +7,4 @@
|
|||||||
/README.md export-ignore
|
/README.md export-ignore
|
||||||
/phpunit.xml.dist export-ignore
|
/phpunit.xml.dist export-ignore
|
||||||
/tests export-ignore
|
/tests export-ignore
|
||||||
|
/phpstan.neon export-ignore
|
||||||
|
|||||||
@@ -29,12 +29,14 @@ install:
|
|||||||
- composer self-update
|
- composer self-update
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
|
- if [ "$CS_FIXER" = "run" ]; then composer require phpstan/phpstan phpstan/phpstan-phpunit --dev -n ; fi;
|
||||||
- composer install -o --prefer-dist --no-interaction
|
- composer install -o --prefer-dist --no-interaction
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- mkdir -p build/logs
|
- mkdir -p build/logs
|
||||||
- php vendor/bin/simple-phpunit -v --coverage-clover build/logs/clover.xml
|
- php vendor/bin/simple-phpunit -v --coverage-clover build/logs/clover.xml
|
||||||
- if [ "$CS_FIXER" = "run" ]; then php vendor/bin/php-cs-fixer fix --verbose --dry-run ; fi;
|
- if [ "$CS_FIXER" = "run" ]; then php vendor/bin/php-cs-fixer fix --verbose --dry-run ; fi;
|
||||||
|
- if [ "$CS_FIXER" = "run" ]; then php vendor/bin/phpstan analyse src tests --no-progress --level 1 ; fi;
|
||||||
|
|
||||||
after_script:
|
after_script:
|
||||||
- php vendor/bin/php-coveralls -v -x build/logs/clover.xml
|
- php vendor/bin/php-coveralls -v -x build/logs/clover.xml
|
||||||
|
|||||||
@@ -40,5 +40,8 @@
|
|||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "Readability\\": "src/" }
|
"psr-4": { "Readability\\": "src/" }
|
||||||
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": { "Tests\\Readability\\": "tests/" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
includes:
|
||||||
|
- vendor/phpstan/phpstan-phpunit/extension.neon
|
||||||
|
- vendor/phpstan/phpstan-phpunit/rules.neon
|
||||||
|
|
||||||
|
parameters:
|
||||||
|
# https://github.com/phpstan/phpstan/issues/694#issuecomment-350724288
|
||||||
|
autoload_files:
|
||||||
|
- vendor/bin/.phpunit/phpunit-6.5/vendor/autoload.php
|
||||||
@@ -127,4 +127,14 @@ class JSLikeHTMLElement extends \DOMElement
|
|||||||
{
|
{
|
||||||
return '[' . $this->tagName . ']';
|
return '[' . $this->tagName . ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getInnerHtml()
|
||||||
|
{
|
||||||
|
return $this->__get('innerHTML');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setInnerHtml($value)
|
||||||
|
{
|
||||||
|
return $this->__set('innerHTML', $value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+60
-54
@@ -72,6 +72,9 @@ class Readability implements LoggerAwareInterface
|
|||||||
public $articleTitle;
|
public $articleTitle;
|
||||||
public $articleContent;
|
public $articleContent;
|
||||||
public $original_html;
|
public $original_html;
|
||||||
|
/**
|
||||||
|
* @var \DOMDocument
|
||||||
|
*/
|
||||||
public $dom;
|
public $dom;
|
||||||
// optional - URL where HTML was retrieved
|
// optional - URL where HTML was retrieved
|
||||||
public $url = null;
|
public $url = null;
|
||||||
@@ -169,10 +172,10 @@ class Readability implements LoggerAwareInterface
|
|||||||
/**
|
/**
|
||||||
* Create instance of Readability.
|
* Create instance of Readability.
|
||||||
*
|
*
|
||||||
* @param string UTF-8 encoded string
|
* @param string $html UTF-8 encoded string
|
||||||
* @param string (optional) URL associated with HTML (for footnotes)
|
* @param string $url URL associated with HTML (for footnotes)
|
||||||
* @param string (optional) Which parser to use for turning raw HTML into a DOMDocument
|
* @param string $parser Which parser to use for turning raw HTML into a DOMDocument
|
||||||
* @param bool (optional) Use tidy
|
* @param bool $use_tidy Use tidy
|
||||||
*/
|
*/
|
||||||
public function __construct($html, $url = null, $parser = 'libxml', $use_tidy = true)
|
public function __construct($html, $url = null, $parser = 'libxml', $use_tidy = true)
|
||||||
{
|
{
|
||||||
@@ -213,8 +216,8 @@ class Readability implements LoggerAwareInterface
|
|||||||
/**
|
/**
|
||||||
* Add pre filter for raw input HTML processing.
|
* Add pre filter for raw input HTML processing.
|
||||||
*
|
*
|
||||||
* @param string RegExp for replace
|
* @param string $filter RegExp for replace
|
||||||
* @param string (optional) Replacer
|
* @param string $replacer Replacer
|
||||||
*/
|
*/
|
||||||
public function addPreFilter($filter, $replacer = '')
|
public function addPreFilter($filter, $replacer = '')
|
||||||
{
|
{
|
||||||
@@ -224,8 +227,8 @@ class Readability implements LoggerAwareInterface
|
|||||||
/**
|
/**
|
||||||
* Add post filter for raw output HTML processing.
|
* Add post filter for raw output HTML processing.
|
||||||
*
|
*
|
||||||
* @param string RegExp for replace
|
* @param string $filter RegExp for replace
|
||||||
* @param string (optional) Replacer
|
* @param string $replacer Replacer
|
||||||
*/
|
*/
|
||||||
public function addPostFilter($filter, $replacer = '')
|
public function addPostFilter($filter, $replacer = '')
|
||||||
{
|
{
|
||||||
@@ -258,7 +261,7 @@ class Readability implements LoggerAwareInterface
|
|||||||
if (null === $this->bodyCache) {
|
if (null === $this->bodyCache) {
|
||||||
$this->bodyCache = '';
|
$this->bodyCache = '';
|
||||||
foreach ($bodyElems as $bodyNode) {
|
foreach ($bodyElems as $bodyNode) {
|
||||||
$this->bodyCache .= trim($bodyNode->innerHTML);
|
$this->bodyCache .= trim($bodyNode->getInnerHTML());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,7 +281,7 @@ class Readability implements LoggerAwareInterface
|
|||||||
$this->success = false;
|
$this->success = false;
|
||||||
$articleContent = $this->dom->createElement('div');
|
$articleContent = $this->dom->createElement('div');
|
||||||
$articleContent->setAttribute('class', 'readability-content');
|
$articleContent->setAttribute('class', 'readability-content');
|
||||||
$articleContent->innerHTML = '<p>Sorry, Readability was unable to parse this page for content.</p>';
|
$articleContent->setInnerHtml('<p>Sorry, Readability was unable to parse this page for content.</p>');
|
||||||
}
|
}
|
||||||
|
|
||||||
$overlay->setAttribute('class', 'readOverlay');
|
$overlay->setAttribute('class', 'readOverlay');
|
||||||
@@ -290,7 +293,7 @@ class Readability implements LoggerAwareInterface
|
|||||||
$overlay->appendChild($innerDiv);
|
$overlay->appendChild($innerDiv);
|
||||||
|
|
||||||
// Clear the old HTML, insert the new content.
|
// Clear the old HTML, insert the new content.
|
||||||
$this->body->innerHTML = '';
|
$this->body->setInnerHtml('');
|
||||||
$this->body->appendChild($overlay);
|
$this->body->appendChild($overlay);
|
||||||
$this->body->removeAttribute('style');
|
$this->body->removeAttribute('style');
|
||||||
$this->postProcessContent($articleContent);
|
$this->postProcessContent($articleContent);
|
||||||
@@ -307,7 +310,7 @@ class Readability implements LoggerAwareInterface
|
|||||||
*
|
*
|
||||||
* @param \DOMElement $articleContent
|
* @param \DOMElement $articleContent
|
||||||
*/
|
*/
|
||||||
public function postProcessContent($articleContent)
|
public function postProcessContent(\DOMElement $articleContent)
|
||||||
{
|
{
|
||||||
if ($this->convertLinksToFootnotes && !preg_match('/\bwiki/', $this->url)) {
|
if ($this->convertLinksToFootnotes && !preg_match('/\bwiki/', $this->url)) {
|
||||||
$this->addFootnotes($articleContent);
|
$this->addFootnotes($articleContent);
|
||||||
@@ -321,11 +324,11 @@ class Readability implements LoggerAwareInterface
|
|||||||
*
|
*
|
||||||
* @param \DOMElement $articleContent
|
* @param \DOMElement $articleContent
|
||||||
*/
|
*/
|
||||||
public function addFootnotes($articleContent)
|
public function addFootnotes(\DOMElement $articleContent)
|
||||||
{
|
{
|
||||||
$footnotesWrapper = $this->dom->createElement('footer');
|
$footnotesWrapper = $this->dom->createElement('footer');
|
||||||
$footnotesWrapper->setAttribute('class', 'readability-footnotes');
|
$footnotesWrapper->setAttribute('class', 'readability-footnotes');
|
||||||
$footnotesWrapper->innerHTML = '<h3>References</h3>';
|
$footnotesWrapper->setInnerHtml('<h3>References</h3>');
|
||||||
$articleFootnotes = $this->dom->createElement('ol');
|
$articleFootnotes = $this->dom->createElement('ol');
|
||||||
$articleFootnotes->setAttribute('class', 'readability-footnotes-list');
|
$articleFootnotes->setAttribute('class', 'readability-footnotes-list');
|
||||||
$footnotesWrapper->appendChild($articleFootnotes);
|
$footnotesWrapper->appendChild($articleFootnotes);
|
||||||
@@ -351,7 +354,7 @@ class Readability implements LoggerAwareInterface
|
|||||||
|
|
||||||
// Add a superscript reference after the article link.
|
// Add a superscript reference after the article link.
|
||||||
$refLink->setAttribute('href', '#readabilityFootnoteLink-' . $linkCount);
|
$refLink->setAttribute('href', '#readabilityFootnoteLink-' . $linkCount);
|
||||||
$refLink->innerHTML = '<small><sup>[' . $linkCount . ']</sup></small>';
|
$refLink->setInnerHtml('<small><sup>[' . $linkCount . ']</sup></small>');
|
||||||
$refLink->setAttribute('class', 'readability-DoNotFootnote');
|
$refLink->setAttribute('class', 'readability-DoNotFootnote');
|
||||||
$refLink->setAttribute('style', 'color: inherit;');
|
$refLink->setAttribute('style', 'color: inherit;');
|
||||||
|
|
||||||
@@ -363,13 +366,13 @@ class Readability implements LoggerAwareInterface
|
|||||||
|
|
||||||
$articleLink->setAttribute('style', 'color: inherit; text-decoration: none;');
|
$articleLink->setAttribute('style', 'color: inherit; text-decoration: none;');
|
||||||
$articleLink->setAttribute('name', 'readabilityLink-' . $linkCount);
|
$articleLink->setAttribute('name', 'readabilityLink-' . $linkCount);
|
||||||
$footnote->innerHTML = '<small><sup><a href="#readabilityLink-' . $linkCount . '" title="Jump to Link in Article">^</a></sup></small> ';
|
$footnote->setInnerHtml('<small><sup><a href="#readabilityLink-' . $linkCount . '" title="Jump to Link in Article">^</a></sup></small> ');
|
||||||
$footnoteLink->innerHTML = ('' !== $footnoteLink->getAttribute('title') ? $footnoteLink->getAttribute('title') : $linkText);
|
$footnoteLink->setInnerHtml(('' !== $footnoteLink->getAttribute('title') ? $footnoteLink->getAttribute('title') : $linkText));
|
||||||
$footnoteLink->setAttribute('name', 'readabilityFootnoteLink-' . $linkCount);
|
$footnoteLink->setAttribute('name', 'readabilityFootnoteLink-' . $linkCount);
|
||||||
$footnote->appendChild($footnoteLink);
|
$footnote->appendChild($footnoteLink);
|
||||||
|
|
||||||
if ($linkDomain) {
|
if ($linkDomain) {
|
||||||
$footnote->innerHTML = $footnote->innerHTML . '<small> (' . $linkDomain . ')</small>';
|
$footnote->setInnerHtml($footnote->getInnerHTML() . '<small> (' . $linkDomain . ')</small>');
|
||||||
}
|
}
|
||||||
$articleFootnotes->appendChild($footnote);
|
$articleFootnotes->appendChild($footnote);
|
||||||
}
|
}
|
||||||
@@ -383,10 +386,14 @@ class Readability implements LoggerAwareInterface
|
|||||||
* Prepare the article node for display. Clean out any inline styles,
|
* Prepare the article node for display. Clean out any inline styles,
|
||||||
* iframes, forms, strip extraneous <p> tags, etc.
|
* iframes, forms, strip extraneous <p> tags, etc.
|
||||||
*
|
*
|
||||||
* @param \DOMElement $articleContent
|
* @param \DOMNode $articleContent
|
||||||
*/
|
*/
|
||||||
public function prepArticle($articleContent)
|
public function prepArticle(\DOMNode $articleContent)
|
||||||
{
|
{
|
||||||
|
if (!$articleContent instanceof \DOMElement) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->logger->debug($this->lightClean ? 'Light clean enabled.' : 'Standard clean enabled.');
|
$this->logger->debug($this->lightClean ? 'Light clean enabled.' : 'Standard clean enabled.');
|
||||||
|
|
||||||
$this->cleanStyles($articleContent);
|
$this->cleanStyles($articleContent);
|
||||||
@@ -467,7 +474,7 @@ class Readability implements LoggerAwareInterface
|
|||||||
if (!$this->flagIsActive(self::FLAG_DISABLE_POSTFILTER)) {
|
if (!$this->flagIsActive(self::FLAG_DISABLE_POSTFILTER)) {
|
||||||
try {
|
try {
|
||||||
foreach ($this->post_filters as $search => $replace) {
|
foreach ($this->post_filters as $search => $replace) {
|
||||||
$articleContent->innerHTML = preg_replace($search, $replace, $articleContent->innerHTML);
|
$articleContent->setInnerHtml(preg_replace($search, $replace, $articleContent->getInnerHTML()));
|
||||||
}
|
}
|
||||||
unset($search, $replace);
|
unset($search, $replace);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -552,11 +559,11 @@ class Readability implements LoggerAwareInterface
|
|||||||
* Can exclude external references to differentiate between simple text and menus/infoblocks.
|
* Can exclude external references to differentiate between simple text and menus/infoblocks.
|
||||||
*
|
*
|
||||||
* @param \DOMElement $e
|
* @param \DOMElement $e
|
||||||
* @param string $excludeExternal
|
* @param bool $excludeExternal
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getLinkDensity($e, $excludeExternal = false)
|
public function getLinkDensity(\DOMElement $e, $excludeExternal = false)
|
||||||
{
|
{
|
||||||
$links = $e->getElementsByTagName('a');
|
$links = $e->getElementsByTagName('a');
|
||||||
$textLength = mb_strlen($this->getInnerText($e, true, true));
|
$textLength = mb_strlen($this->getInnerText($e, true, true));
|
||||||
@@ -583,7 +590,7 @@ class Readability implements LoggerAwareInterface
|
|||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getWeight($e)
|
public function getWeight(\DOMElement $e)
|
||||||
{
|
{
|
||||||
if (!$this->flagIsActive(self::FLAG_WEIGHT_ATTRIBUTES)) {
|
if (!$this->flagIsActive(self::FLAG_WEIGHT_ATTRIBUTES)) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -603,11 +610,11 @@ class Readability implements LoggerAwareInterface
|
|||||||
*
|
*
|
||||||
* @param \DOMElement $node
|
* @param \DOMElement $node
|
||||||
*/
|
*/
|
||||||
public function killBreaks($node)
|
public function killBreaks(\DOMElement $node)
|
||||||
{
|
{
|
||||||
$html = $node->innerHTML;
|
$html = $node->getInnerHTML();
|
||||||
$html = preg_replace($this->regexps['killBreaks'], '<br />', $html);
|
$html = preg_replace($this->regexps['killBreaks'], '<br />', $html);
|
||||||
$node->innerHTML = $html;
|
$node->setInnerHtml($html);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -619,7 +626,7 @@ class Readability implements LoggerAwareInterface
|
|||||||
* @param \DOMElement $e
|
* @param \DOMElement $e
|
||||||
* @param string $tag
|
* @param string $tag
|
||||||
*/
|
*/
|
||||||
public function clean($e, $tag)
|
public function clean(\DOMElement $e, $tag)
|
||||||
{
|
{
|
||||||
$currentItem = null;
|
$currentItem = null;
|
||||||
$targetList = $e->getElementsByTagName($tag);
|
$targetList = $e->getElementsByTagName($tag);
|
||||||
@@ -638,7 +645,7 @@ class Readability implements LoggerAwareInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Then check the elements inside this element for the same.
|
// Then check the elements inside this element for the same.
|
||||||
if (preg_match($this->regexps['media'], $targetList->item($y)->innerHTML)) {
|
if (preg_match($this->regexps['media'], $targetList->item($y)->getInnerHTML())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -655,7 +662,7 @@ class Readability implements LoggerAwareInterface
|
|||||||
* @param \DOMElement $e
|
* @param \DOMElement $e
|
||||||
* @param string $tag
|
* @param string $tag
|
||||||
*/
|
*/
|
||||||
public function cleanConditionally($e, $tag)
|
public function cleanConditionally(\DOMElement $e, $tag)
|
||||||
{
|
{
|
||||||
if (!$this->flagIsActive(self::FLAG_CLEAN_CONDITIONALLY)) {
|
if (!$this->flagIsActive(self::FLAG_CLEAN_CONDITIONALLY)) {
|
||||||
return;
|
return;
|
||||||
@@ -768,7 +775,7 @@ class Readability implements LoggerAwareInterface
|
|||||||
*
|
*
|
||||||
* @param \DOMElement $e
|
* @param \DOMElement $e
|
||||||
*/
|
*/
|
||||||
public function cleanHeaders($e)
|
public function cleanHeaders(\DOMElement $e)
|
||||||
{
|
{
|
||||||
for ($headerIndex = 1; $headerIndex < 3; ++$headerIndex) {
|
for ($headerIndex = 1; $headerIndex < 3; ++$headerIndex) {
|
||||||
$headers = $e->getElementsByTagName('h' . $headerIndex);
|
$headers = $e->getElementsByTagName('h' . $headerIndex);
|
||||||
@@ -871,7 +878,7 @@ class Readability implements LoggerAwareInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$articleTitle = $this->dom->createElement('h1');
|
$articleTitle = $this->dom->createElement('h1');
|
||||||
$articleTitle->innerHTML = $curTitle;
|
$articleTitle->setInnerHtml($curTitle);
|
||||||
|
|
||||||
return $articleTitle;
|
return $articleTitle;
|
||||||
}
|
}
|
||||||
@@ -911,7 +918,7 @@ class Readability implements LoggerAwareInterface
|
|||||||
*
|
*
|
||||||
* @param \DOMElement $node
|
* @param \DOMElement $node
|
||||||
*/
|
*/
|
||||||
protected function initializeNode($node)
|
protected function initializeNode(\DOMElement $node)
|
||||||
{
|
{
|
||||||
if (!isset($node->tagName)) {
|
if (!isset($node->tagName)) {
|
||||||
return;
|
return;
|
||||||
@@ -981,9 +988,9 @@ class Readability implements LoggerAwareInterface
|
|||||||
*
|
*
|
||||||
* @param \DOMElement $page
|
* @param \DOMElement $page
|
||||||
*
|
*
|
||||||
* @return \DOMElement|bool
|
* @return \DOMElement|false
|
||||||
*/
|
*/
|
||||||
protected function grabArticle($page = null)
|
protected function grabArticle(\DOMElement $page = null)
|
||||||
{
|
{
|
||||||
if (!$page) {
|
if (!$page) {
|
||||||
$page = $this->dom;
|
$page = $this->dom;
|
||||||
@@ -1009,11 +1016,11 @@ class Readability implements LoggerAwareInterface
|
|||||||
// Turn divs into P tags where they have been used inappropriately
|
// Turn divs into P tags where they have been used inappropriately
|
||||||
// (as in, where they contain no other block level elements).
|
// (as in, where they contain no other block level elements).
|
||||||
if (0 === strcasecmp($tagName, 'div') || 0 === strcasecmp($tagName, 'article') || 0 === strcasecmp($tagName, 'section')) {
|
if (0 === strcasecmp($tagName, 'div') || 0 === strcasecmp($tagName, 'article') || 0 === strcasecmp($tagName, 'section')) {
|
||||||
if (!preg_match($this->regexps['divToPElements'], $node->innerHTML)) {
|
if (!preg_match($this->regexps['divToPElements'], $node->getInnerHTML())) {
|
||||||
$newNode = $this->dom->createElement('p');
|
$newNode = $this->dom->createElement('p');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$newNode->innerHTML = $node->innerHTML;
|
$newNode->setInnerHtml($node->getInnerHTML());
|
||||||
|
|
||||||
$node->parentNode->replaceChild($newNode, $node);
|
$node->parentNode->replaceChild($newNode, $node);
|
||||||
--$nodeIndex;
|
--$nodeIndex;
|
||||||
@@ -1040,7 +1047,7 @@ class Readability implements LoggerAwareInterface
|
|||||||
|
|
||||||
if (XML_TEXT_NODE === $childNode->nodeType) {
|
if (XML_TEXT_NODE === $childNode->nodeType) {
|
||||||
$p = $this->dom->createElement('p');
|
$p = $this->dom->createElement('p');
|
||||||
$p->innerHTML = $childNode->nodeValue;
|
$p->setInnerHtml($childNode->nodeValue);
|
||||||
$p->setAttribute('data-readability-styled', 'true');
|
$p->setAttribute('data-readability-styled', 'true');
|
||||||
$childNode->parentNode->replaceChild($p, $childNode);
|
$childNode->parentNode->replaceChild($p, $childNode);
|
||||||
}
|
}
|
||||||
@@ -1190,14 +1197,14 @@ class Readability implements LoggerAwareInterface
|
|||||||
$this->logger->debug('The page has no body!');
|
$this->logger->debug('The page has no body!');
|
||||||
} else {
|
} else {
|
||||||
$this->logger->debug('Setting body to a raw HTML of original page!');
|
$this->logger->debug('Setting body to a raw HTML of original page!');
|
||||||
$topCandidate->innerHTML = $page->documentElement->innerHTML;
|
$topCandidate->setInnerHtml($page->documentElement->getInnerHTML());
|
||||||
$page->documentElement->innerHTML = '';
|
$page->documentElement->setInnerHtml('');
|
||||||
$this->reinitBody();
|
$this->reinitBody();
|
||||||
$page->documentElement->appendChild($topCandidate);
|
$page->documentElement->appendChild($topCandidate);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$topCandidate->innerHTML = $page->innerHTML;
|
$topCandidate->setInnerHtml($page->getInnerHTML());
|
||||||
$page->innerHTML = '';
|
$page->setInnerHtml('');
|
||||||
$page->appendChild($topCandidate);
|
$page->appendChild($topCandidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1229,8 +1236,8 @@ class Readability implements LoggerAwareInterface
|
|||||||
$siblingScoreThreshold = max(10, ((int) $topCandidate->getAttribute('readability')) * 0.2);
|
$siblingScoreThreshold = max(10, ((int) $topCandidate->getAttribute('readability')) * 0.2);
|
||||||
$siblingNodes = $topCandidate->parentNode->childNodes;
|
$siblingNodes = $topCandidate->parentNode->childNodes;
|
||||||
|
|
||||||
if (!isset($siblingNodes)) {
|
if (null === $siblingNodes) {
|
||||||
$siblingNodes = new stdClass();
|
$siblingNodes = new \stdClass();
|
||||||
$siblingNodes->length = 0;
|
$siblingNodes->length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1276,7 +1283,7 @@ class Readability implements LoggerAwareInterface
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$nodeToAppend->setAttribute('alt', $siblingNodeName);
|
$nodeToAppend->setAttribute('alt', $siblingNodeName);
|
||||||
$nodeToAppend->innerHTML = $siblingNode->innerHTML;
|
$nodeToAppend->setInnerHtml($siblingNode->getInnerHTML());
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->logger->debug('Could not alter siblingNode "' . $siblingNodeName . '" to "div", reverting to original.');
|
$this->logger->debug('Could not alter siblingNode "' . $siblingNodeName . '" to "div", reverting to original.');
|
||||||
$nodeToAppend = $siblingNode;
|
$nodeToAppend = $siblingNode;
|
||||||
@@ -1344,7 +1351,7 @@ class Readability implements LoggerAwareInterface
|
|||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
protected function weightAttribute($element, $attribute)
|
protected function weightAttribute(\DOMElement $element, $attribute)
|
||||||
{
|
{
|
||||||
if (!$element->hasAttribute($attribute)) {
|
if (!$element->hasAttribute($attribute)) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1379,7 +1386,7 @@ class Readability implements LoggerAwareInterface
|
|||||||
{
|
{
|
||||||
if (!isset($this->body->childNodes)) {
|
if (!isset($this->body->childNodes)) {
|
||||||
$this->body = $this->dom->createElement('body');
|
$this->body = $this->dom->createElement('body');
|
||||||
$this->body->innerHTML = $this->bodyCache;
|
$this->body->setInnerHtml($this->bodyCache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1435,17 +1442,16 @@ class Readability implements LoggerAwareInterface
|
|||||||
|
|
||||||
$this->html = mb_convert_encoding($this->html, 'HTML-ENTITIES', 'UTF-8');
|
$this->html = mb_convert_encoding($this->html, 'HTML-ENTITIES', 'UTF-8');
|
||||||
|
|
||||||
if (!('html5lib' === $this->parser && ($this->dom = Parser::parse($this->html)))) {
|
if ('html5lib' === $this->parser) {
|
||||||
|
$this->dom = Parser::parse($this->html);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('libxml' === $this->parser) {
|
||||||
libxml_use_internal_errors(true);
|
libxml_use_internal_errors(true);
|
||||||
|
|
||||||
$this->dom = new \DOMDocument();
|
$this->dom = new \DOMDocument();
|
||||||
$this->dom->preserveWhiteSpace = false;
|
$this->dom->preserveWhiteSpace = false;
|
||||||
|
$this->dom->loadHTML($this->html, LIBXML_NOBLANKS | LIBXML_COMPACT | LIBXML_NOERROR);
|
||||||
if (\PHP_VERSION_ID >= 50400) {
|
|
||||||
$this->dom->loadHTML($this->html, LIBXML_NOBLANKS | LIBXML_COMPACT | LIBXML_NOERROR);
|
|
||||||
} else {
|
|
||||||
$this->dom->loadHTML($this->html);
|
|
||||||
}
|
|
||||||
|
|
||||||
libxml_use_internal_errors(false);
|
libxml_use_internal_errors(false);
|
||||||
}
|
}
|
||||||
|
|||||||
+67
-67
@@ -73,8 +73,8 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertFalse($res);
|
$this->assertFalse($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertEmpty($readability->getTitle()->innerHTML);
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
||||||
$this->assertContains('Sorry, Readability was unable to parse this page for content.', $readability->getContent()->innerHTML);
|
$this->assertContains('Sorry, Readability was unable to parse this page for content.', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInitP()
|
public function testInitP()
|
||||||
@@ -85,9 +85,9 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
$this->assertContains('<div readability=', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertEmpty($readability->getTitle()->innerHTML);
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
||||||
$this->assertContains('This is the awesome content :)', $readability->getContent()->innerHTML);
|
$this->assertContains('This is the awesome content :)', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInitDivP()
|
public function testInitDivP()
|
||||||
@@ -98,9 +98,9 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
$this->assertContains('<div readability=', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertEmpty($readability->getTitle()->innerHTML);
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
||||||
$this->assertContains('This is the awesome content :)', $readability->getContent()->innerHTML);
|
$this->assertContains('This is the awesome content :)', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInitDiv()
|
public function testInitDiv()
|
||||||
@@ -112,9 +112,9 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
$this->assertContains('<div readability=', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertEmpty($readability->getTitle()->innerHTML);
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
||||||
$this->assertContains('This is the awesome content :)', $readability->getContent()->innerHTML);
|
$this->assertContains('This is the awesome content :)', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithFootnotes()
|
public function testWithFootnotes()
|
||||||
@@ -127,11 +127,11 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
$this->assertContains('<div readability=', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertEmpty($readability->getTitle()->innerHTML);
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertContains('readabilityFootnoteLink', $readability->getContent()->innerHTML);
|
$this->assertContains('readabilityFootnoteLink', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertContains('readabilityLink-3', $readability->getContent()->innerHTML);
|
$this->assertContains('readabilityLink-3', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testStandardClean()
|
public function testStandardClean()
|
||||||
@@ -144,11 +144,11 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
$this->assertContains('<div readability=', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertEmpty($readability->getTitle()->innerHTML);
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertContains('will NOT be removed', $readability->getContent()->innerHTML);
|
$this->assertContains('will NOT be removed', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertNotContains('<h2>', $readability->getContent()->innerHTML);
|
$this->assertNotContains('<h2>', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithIframe()
|
public function testWithIframe()
|
||||||
@@ -160,10 +160,10 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
$this->assertContains('<div readability=', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertEmpty($readability->getTitle()->innerHTML);
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertContains('nofollow', $readability->getContent()->innerHTML);
|
$this->assertContains('nofollow', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithArticle()
|
public function testWithArticle()
|
||||||
@@ -175,10 +175,10 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertContains('alt="article"', $readability->getContent()->innerHTML);
|
$this->assertContains('alt="article"', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertEmpty($readability->getTitle()->innerHTML);
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertContains('nofollow', $readability->getContent()->innerHTML);
|
$this->assertContains('nofollow', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithAside()
|
public function testWithAside()
|
||||||
@@ -190,10 +190,10 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertEmpty($readability->getTitle()->innerHTML);
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertNotContains('<aside>', $readability->getContent()->innerHTML);
|
$this->assertNotContains('<aside>', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertContains('<footer readability="4"/>', $readability->getContent()->innerHTML);
|
$this->assertContains('<footer readability="4"/>', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithClasses()
|
public function testWithClasses()
|
||||||
@@ -205,10 +205,10 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertContains('alt="article"', $readability->getContent()->innerHTML);
|
$this->assertContains('alt="article"', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertEmpty($readability->getTitle()->innerHTML);
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertNotContains('This text should be removed', $readability->getContent()->innerHTML);
|
$this->assertNotContains('This text should be removed', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithClassesWithoutLightClean()
|
public function testWithClassesWithoutLightClean()
|
||||||
@@ -221,10 +221,10 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertContains('alt="article"', $readability->getContent()->innerHTML);
|
$this->assertContains('alt="article"', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertEmpty($readability->getTitle()->innerHTML);
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertNotContains('This text should be removed', $readability->getContent()->innerHTML);
|
$this->assertNotContains('This text should be removed', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithTd()
|
public function testWithTd()
|
||||||
@@ -236,8 +236,8 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertEmpty($readability->getTitle()->innerHTML);
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithSameClasses()
|
public function testWithSameClasses()
|
||||||
@@ -249,9 +249,9 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertEmpty($readability->getTitle()->innerHTML);
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertContains('This text is also an awesome text and you should know that', $readability->getContent()->innerHTML);
|
$this->assertContains('This text is also an awesome text and you should know that', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithScript()
|
public function testWithScript()
|
||||||
@@ -263,9 +263,9 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertEmpty($readability->getTitle()->innerHTML);
|
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertNotContains('This text is also an awesome text and you should know that', $readability->getContent()->innerHTML);
|
$this->assertNotContains('This text is also an awesome text and you should know that', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTitle()
|
public function testTitle()
|
||||||
@@ -277,9 +277,9 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertEquals('this is my title', $readability->getTitle()->innerHTML);
|
$this->assertEquals('this is my title', $readability->getTitle()->getInnerHtml());
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertNotContains('This text is also an awesome text and you should know that', $readability->getContent()->innerHTML);
|
$this->assertNotContains('This text is also an awesome text and you should know that', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTitleWithDash()
|
public function testTitleWithDash()
|
||||||
@@ -291,9 +291,9 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertEquals('title2 - title3', $readability->getTitle()->innerHTML);
|
$this->assertEquals('title2 - title3', $readability->getTitle()->getInnerHtml());
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertNotContains('This text is also an awesome text and you should know that', $readability->getContent()->innerHTML);
|
$this->assertNotContains('This text is also an awesome text and you should know that', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTitleWithDoubleDot()
|
public function testTitleWithDoubleDot()
|
||||||
@@ -305,9 +305,9 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertEquals('title2 : title3', $readability->getTitle()->innerHTML);
|
$this->assertEquals('title2 : title3', $readability->getTitle()->getInnerHtml());
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertNotContains('This text is also an awesome text and you should know that', $readability->getContent()->innerHTML);
|
$this->assertNotContains('This text is also an awesome text and you should know that', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTitleTooShortUseH1()
|
public function testTitleTooShortUseH1()
|
||||||
@@ -319,9 +319,9 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertEquals('this is my h1 title !', $readability->getTitle()->innerHTML);
|
$this->assertEquals('this is my h1 title !', $readability->getTitle()->getInnerHtml());
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertNotContains('This text is also an awesome text and you should know that', $readability->getContent()->innerHTML);
|
$this->assertNotContains('This text is also an awesome text and you should know that', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
// dummy function to be used to the next test
|
// dummy function to be used to the next test
|
||||||
@@ -369,8 +369,8 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertContains('<iframe src="https://www.youtube.com/embed/PUep6xNeKjA" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen"> </iframe>', $readability->getContent()->innerHTML);
|
$this->assertContains('<iframe src="https://www.youtube.com/embed/PUep6xNeKjA" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen"> </iframe>', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertContains('3D Touch', $readability->getTitle()->innerHTML);
|
$this->assertContains('3D Touch', $readability->getTitle()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -440,7 +440,7 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$res = $readability->init();
|
$res = $readability->init();
|
||||||
|
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertContains('This the awesome content :)', $readability->getContent()->innerHTML);
|
$this->assertContains('This the awesome content :)', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPreFilters()
|
public function testPreFilters()
|
||||||
@@ -453,7 +453,7 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$res = $readability->init();
|
$res = $readability->init();
|
||||||
|
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertContains('This the awesome and WONDERFUL content :)', $readability->getContent()->innerHTML);
|
$this->assertContains('This the awesome and WONDERFUL content :)', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testChildNodeGoneNull()
|
public function testChildNodeGoneNull()
|
||||||
@@ -479,8 +479,8 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
|||||||
$res = $readability->init();
|
$res = $readability->init();
|
||||||
|
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertContains('<sup id="fnref1:fnfeed_2"><a href="#fn:fnfeed_2" class="footnote-ref">2</a></sup>', $readability->getContent()->innerHTML);
|
$this->assertContains('<sup id="fnref1:fnfeed_2"><a href="#fn:fnfeed_2" class="footnote-ref">2</a></sup>', $readability->getContent()->getInnerHtml());
|
||||||
$this->assertContains('<a href="#fnref1:fnfeed_2" rev="footnote"', $readability->getContent()->innerHTML);
|
$this->assertContains('<a href="#fnref1:fnfeed_2" rev="footnote"', $readability->getContent()->getInnerHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getReadability($html, $url = null, $parser = 'libxml', $useTidy = true)
|
private function getReadability($html, $url = null, $parser = 'libxml', $useTidy = true)
|
||||||
|
|||||||
Reference in New Issue
Block a user