mirror of
https://github.com/j0k3r/php-readability.git
synced 2026-09-27 06:26:17 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3fa88461a0 | ||
|
|
6a8ecf232f | ||
|
|
52b1ddba57 | ||
|
|
90c625bb57 | ||
|
|
4d1c3b1777 | ||
|
|
d649b59414 | ||
|
|
44bebfc3d6 | ||
|
|
b1acc9ed73 | ||
|
|
9306996b47 | ||
|
|
bb75b4f089 | ||
|
|
11d2946904 | ||
|
|
f808c1b0a2 | ||
|
|
bb65caf864 |
@@ -4,8 +4,6 @@ root = true
|
||||
; Unix-style newlines
|
||||
[*]
|
||||
end_of_line = LF
|
||||
|
||||
[*.php]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
+1
-2
@@ -4,7 +4,6 @@
|
||||
/.scrutinizer.yml export-ignore
|
||||
/.travis.yml export-ignore
|
||||
/.php_cs export-ignore
|
||||
/README.md export-ignore
|
||||
/phpunit.xml.dist export-ignore
|
||||
/tests export-ignore
|
||||
/phpstan.neon export-ignore
|
||||
/tests export-ignore
|
||||
|
||||
@@ -2,3 +2,4 @@ vendor/
|
||||
coverage/
|
||||
composer.lock
|
||||
.php_cs.cache
|
||||
.phpunit.result.cache
|
||||
|
||||
@@ -1,2 +1,12 @@
|
||||
tools:
|
||||
external_code_coverage: false
|
||||
|
||||
build:
|
||||
nodes:
|
||||
analysis:
|
||||
tests:
|
||||
override:
|
||||
- php-scrutinizer-run
|
||||
environment:
|
||||
php:
|
||||
version: 7.2
|
||||
|
||||
+27
-15
@@ -1,42 +1,54 @@
|
||||
dist: xenial
|
||||
os: linux
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.6
|
||||
- 7.0
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
- nightly
|
||||
|
||||
matrix:
|
||||
jobs:
|
||||
include:
|
||||
- php: 7.2
|
||||
env: CS_FIXER=run
|
||||
env: SYMFONY_PHPUNIT_VERSION=7.5
|
||||
- php: 7.2
|
||||
env: SYMFONY_PHPUNIT_VERSION=7.5 COMPOSER_FLAGS="--prefer-lowest"
|
||||
- php: 7.3
|
||||
env: SYMFONY_PHPUNIT_VERSION=7.5 CS_FIXER=run COVERAGE=run
|
||||
- php: 7.4
|
||||
env: SYMFONY_PHPUNIT_VERSION=7.5
|
||||
- php: nightly
|
||||
env: SYMFONY_PHPUNIT_VERSION=7.5
|
||||
fast_finish: true
|
||||
allow_failures:
|
||||
- php: nightly
|
||||
|
||||
# cache vendor dirs
|
||||
cache:
|
||||
directories:
|
||||
- vendor
|
||||
- $HOME/.composer/cache
|
||||
- $HOME/.composer/cache/files
|
||||
|
||||
before_install:
|
||||
- if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi;
|
||||
|
||||
install:
|
||||
- composer self-update
|
||||
# only install phpstan when we need it
|
||||
- if [ "$CS_FIXER" = "run" ]; then composer require phpstan/phpstan phpstan/phpstan-phpunit --dev --no-progress --no-suggest ; fi;
|
||||
- composer update --prefer-dist --no-progress --no-suggest -o $COMPOSER_FLAGS
|
||||
- php vendor/bin/simple-phpunit install
|
||||
|
||||
before_script:
|
||||
- if [ "$CS_FIXER" = "run" ]; then composer require phpstan/phpstan phpstan/phpstan-phpunit --dev -n ; fi;
|
||||
- composer install -o --prefer-dist --no-interaction
|
||||
- mkdir -p build/logs
|
||||
- if [ "$COVERAGE" = "run" ]; then PHPUNIT_FLAGS="--coverage-clover build/logs/clover.xml"; fi;
|
||||
|
||||
script:
|
||||
- mkdir -p build/logs
|
||||
- php vendor/bin/simple-phpunit -v --coverage-clover build/logs/clover.xml
|
||||
- php vendor/bin/simple-phpunit -v $PHPUNIT_FLAGS
|
||||
- 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:
|
||||
- php vendor/bin/php-coveralls -v -x build/logs/clover.xml
|
||||
after_success:
|
||||
- |
|
||||
if [ "$COVERAGE" = "run" ]; then
|
||||
wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.2.0/php-coveralls.phar
|
||||
chmod +x php-coveralls.phar
|
||||
php php-coveralls.phar -v -x build/logs/clover.xml
|
||||
fi
|
||||
|
||||
+2
-3
@@ -27,12 +27,11 @@
|
||||
"php": ">=5.6.0",
|
||||
"ext-mbstring": "*",
|
||||
"psr/log": "^1.0",
|
||||
"electrolinux/php-html5lib": "^0.1.0"
|
||||
"masterminds/html5": "^2.7"
|
||||
},
|
||||
"require-dev": {
|
||||
"php-coveralls/php-coveralls": "^2.1",
|
||||
"friendsofphp/php-cs-fixer": "^2.14",
|
||||
"monolog/monolog": "^1.24",
|
||||
"monolog/monolog": "^1.24|^2.1",
|
||||
"symfony/phpunit-bridge": "^4.2.3"
|
||||
},
|
||||
"suggest": {
|
||||
|
||||
+1
-1
@@ -5,4 +5,4 @@ includes:
|
||||
parameters:
|
||||
# https://github.com/phpstan/phpstan/issues/694#issuecomment-350724288
|
||||
autoload_files:
|
||||
- vendor/bin/.phpunit/phpunit-6.5/vendor/autoload.php
|
||||
- vendor/bin/.phpunit/phpunit-7.5-0/vendor/autoload.php
|
||||
|
||||
+1
-2
@@ -7,7 +7,6 @@
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
bootstrap="vendor/autoload.php"
|
||||
>
|
||||
|
||||
@@ -27,6 +26,6 @@
|
||||
</filter>
|
||||
|
||||
<!-- <logging>
|
||||
<log type="coverage-html" target="coverage" title="Readability" charset="UTF-8" yui="true" highlight="true" lowUpperBound="35" highLowerBound="70"/>
|
||||
<log type="coverage-html" target="coverage" lowUpperBound="35" highLowerBound="70"/>
|
||||
</logging> -->
|
||||
</phpunit>
|
||||
|
||||
+6
-28
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Readability;
|
||||
|
||||
use HTML5Lib\Parser;
|
||||
use Masterminds\HTML5;
|
||||
use Psr\Log\LoggerAwareInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
@@ -61,7 +61,7 @@ class Readability implements LoggerAwareInterface
|
||||
// constants
|
||||
const SCORE_CHARS_IN_PARAGRAPH = 100;
|
||||
const SCORE_WORDS_IN_PARAGRAPH = 20;
|
||||
const GRANDPARENT_SCORE_DIVISOR = 2.2;
|
||||
const GRANDPARENT_SCORE_DIVISOR = 2;
|
||||
const MIN_PARAGRAPH_LENGTH = 20;
|
||||
const MIN_COMMAS_IN_PARAGRAPH = 6;
|
||||
const MIN_ARTICLE_LENGTH = 200;
|
||||
@@ -95,7 +95,7 @@ class Readability implements LoggerAwareInterface
|
||||
'negative' => '/bottom|stat|info|discuss|e[\-]?mail|comment|reply|log.{2}(n|ed)|sign|single|combx|com-|contact|_nav|link|media|promo|\bad-|related|scroll|shoutbox|sidebar|sponsor|shopping|teaser|recommend/i',
|
||||
'divToPElements' => '/<(?:blockquote|header|section|code|div|article|footer|aside|img|p|pre|dl|ol|ul)/mi',
|
||||
'killBreaks' => '/(<br\s*\/?>([ \r\n\s]| ?)*)+/',
|
||||
'media' => '!//(?:[^\.\?/]+\.)?(?:youtu(?:be)?|giphy|soundcloud|dailymotion|vimeo|pornhub|xvideos|twitvid|rutube|viddler)\.(?:com|be|org|net)/!i',
|
||||
'media' => '!//(?:[^\.\?/]+\.)?(?:youtu(?:be)?|giphy|soundcloud|dailymotion|vimeo|pornhub|xvideos|twitvid|rutube|openload\.co|viddler)\.(?:com|be|org|net)/!i',
|
||||
'skipFootnoteLink' => '/^\s*(\[?[a-z0-9]{1,2}\]?|^|edit|citation needed)\s*$/i',
|
||||
];
|
||||
public $tidy_config = [
|
||||
@@ -307,8 +307,6 @@ class Readability implements LoggerAwareInterface
|
||||
|
||||
/**
|
||||
* Run any post-process modifications to article content as necessary.
|
||||
*
|
||||
* @param \DOMElement $articleContent
|
||||
*/
|
||||
public function postProcessContent(\DOMElement $articleContent)
|
||||
{
|
||||
@@ -321,8 +319,6 @@ class Readability implements LoggerAwareInterface
|
||||
* For easier reading, convert this document to have footnotes at the bottom rather than inline links.
|
||||
*
|
||||
* @see http://www.roughtype.com/archives/2010/05/experiments_in.php
|
||||
*
|
||||
* @param \DOMElement $articleContent
|
||||
*/
|
||||
public function addFootnotes(\DOMElement $articleContent)
|
||||
{
|
||||
@@ -385,8 +381,6 @@ class Readability implements LoggerAwareInterface
|
||||
/**
|
||||
* Prepare the article node for display. Clean out any inline styles,
|
||||
* iframes, forms, strip extraneous <p> tags, etc.
|
||||
*
|
||||
* @param \DOMNode $articleContent
|
||||
*/
|
||||
public function prepArticle(\DOMNode $articleContent)
|
||||
{
|
||||
@@ -558,7 +552,6 @@ class Readability implements LoggerAwareInterface
|
||||
* This is the amount of text that is inside a link divided by the total text in the node.
|
||||
* Can exclude external references to differentiate between simple text and menus/infoblocks.
|
||||
*
|
||||
* @param \DOMElement $e
|
||||
* @param bool $excludeExternal
|
||||
*
|
||||
* @return int
|
||||
@@ -586,8 +579,6 @@ class Readability implements LoggerAwareInterface
|
||||
/**
|
||||
* Get an element relative weight.
|
||||
*
|
||||
* @param \DOMElement $e
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getWeight(\DOMElement $e)
|
||||
@@ -607,8 +598,6 @@ class Readability implements LoggerAwareInterface
|
||||
|
||||
/**
|
||||
* Remove extraneous break tags from a node.
|
||||
*
|
||||
* @param \DOMElement $node
|
||||
*/
|
||||
public function killBreaks(\DOMElement $node)
|
||||
{
|
||||
@@ -623,12 +612,10 @@ class Readability implements LoggerAwareInterface
|
||||
*
|
||||
* Updated 2012-09-18 to preserve youtube/vimeo iframes
|
||||
*
|
||||
* @param \DOMElement $e
|
||||
* @param string $tag
|
||||
*/
|
||||
public function clean(\DOMElement $e, $tag)
|
||||
{
|
||||
$currentItem = null;
|
||||
$targetList = $e->getElementsByTagName($tag);
|
||||
$isEmbed = ('audio' === $tag || 'video' === $tag || 'iframe' === $tag || 'object' === $tag || 'embed' === $tag);
|
||||
|
||||
@@ -659,7 +646,6 @@ class Readability implements LoggerAwareInterface
|
||||
* "Fishy" is an algorithm based on content length, classnames,
|
||||
* link density, number of images & embeds, etc.
|
||||
*
|
||||
* @param \DOMElement $e
|
||||
* @param string $tag
|
||||
*/
|
||||
public function cleanConditionally(\DOMElement $e, $tag)
|
||||
@@ -670,7 +656,6 @@ class Readability implements LoggerAwareInterface
|
||||
|
||||
$tagsList = $e->getElementsByTagName($tag);
|
||||
$curTagsLength = $tagsList->length;
|
||||
$node = null;
|
||||
|
||||
/*
|
||||
* Gather counts for other typical elements embedded within.
|
||||
@@ -772,8 +757,6 @@ class Readability implements LoggerAwareInterface
|
||||
|
||||
/**
|
||||
* Clean out spurious headers from an Element. Checks things like classnames and link density.
|
||||
*
|
||||
* @param \DOMElement $e
|
||||
*/
|
||||
public function cleanHeaders(\DOMElement $e)
|
||||
{
|
||||
@@ -915,8 +898,6 @@ class Readability implements LoggerAwareInterface
|
||||
/**
|
||||
* Initialize a node with the readability object. Also checks the
|
||||
* className/id for special names to add to its score.
|
||||
*
|
||||
* @param \DOMElement $node
|
||||
*/
|
||||
protected function initializeNode(\DOMElement $node)
|
||||
{
|
||||
@@ -1115,7 +1096,7 @@ class Readability implements LoggerAwareInterface
|
||||
// Add the score to the parent. The grandparent gets half.
|
||||
$parentNode->getAttributeNode('readability')->value += $contentScore;
|
||||
if ($grandParentNode) {
|
||||
$grandParentNode->getAttributeNode('readability')->value += $contentScore / self::GRANDPARENT_SCORE_DIVISOR;
|
||||
$grandParentNode->getAttributeNode('readability')->value += round($contentScore / self::GRANDPARENT_SCORE_DIVISOR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1125,7 +1106,6 @@ class Readability implements LoggerAwareInterface
|
||||
*/
|
||||
if ($this->flagIsActive(self::FLAG_STRIP_UNLIKELYS) && $xpath) {
|
||||
$candidates = $xpath->query('.//*[(self::footer and count(//footer)<2) or (self::aside and count(//aside)<2)]', $page->documentElement);
|
||||
$node = null;
|
||||
|
||||
for ($c = $candidates->length - 1; $c >= 0; --$c) {
|
||||
$node = $candidates->item($c);
|
||||
@@ -1137,7 +1117,6 @@ class Readability implements LoggerAwareInterface
|
||||
}
|
||||
|
||||
$candidates = $xpath->query('.//*[not(self::body) and (@class or @id or @style) and ((number(@readability) < 40) or not(@readability))]', $page->documentElement);
|
||||
$node = null;
|
||||
|
||||
for ($c = $candidates->length - 1; $c >= 0; --$c) {
|
||||
$node = $candidates->item($c);
|
||||
@@ -1346,7 +1325,6 @@ class Readability implements LoggerAwareInterface
|
||||
* Get an element weight by attribute.
|
||||
* Uses regular expressions to tell if this element looks good or bad.
|
||||
*
|
||||
* @param \DOMElement $element
|
||||
* @param string $attribute
|
||||
*
|
||||
* @return int
|
||||
@@ -1442,8 +1420,8 @@ class Readability implements LoggerAwareInterface
|
||||
|
||||
$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 || 'html5' === $this->parser) {
|
||||
$this->dom = (new HTML5())->loadHTML($this->html);
|
||||
}
|
||||
|
||||
if ('libxml' === $this->parser) {
|
||||
|
||||
@@ -193,7 +193,7 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
||||
$this->assertEmpty($readability->getTitle()->getInnerHtml());
|
||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
|
||||
$this->assertNotContains('<aside>', $readability->getContent()->getInnerHtml());
|
||||
$this->assertContains('<footer readability="4"/>', $readability->getContent()->getInnerHtml());
|
||||
$this->assertContains('<footer readability="5"/>', $readability->getContent()->getInnerHtml());
|
||||
}
|
||||
|
||||
public function testWithClasses()
|
||||
|
||||
Reference in New Issue
Block a user