mirror of
https://github.com/j0k3r/php-readability.git
synced 2026-09-27 14:36:23 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9632c4df8c | ||
|
|
bd9ca1b2cd | ||
|
|
6c917794a7 | ||
|
|
7cea79c23a | ||
|
|
c6425cc28b | ||
|
|
e6ad806460 | ||
|
|
3fa88461a0 | ||
|
|
6a8ecf232f | ||
|
|
52b1ddba57 | ||
|
|
90c625bb57 | ||
|
|
4d1c3b1777 | ||
|
|
d649b59414 | ||
|
|
44bebfc3d6 | ||
|
|
b1acc9ed73 |
+3
-2
@@ -4,9 +4,10 @@ root = true
|
|||||||
; Unix-style newlines
|
; Unix-style newlines
|
||||||
[*]
|
[*]
|
||||||
end_of_line = LF
|
end_of_line = LF
|
||||||
|
|
||||||
[*.php]
|
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[.github/**.yml]
|
||||||
|
indent_size = 2
|
||||||
|
|||||||
+2
-2
@@ -4,7 +4,7 @@
|
|||||||
/.scrutinizer.yml export-ignore
|
/.scrutinizer.yml export-ignore
|
||||||
/.travis.yml export-ignore
|
/.travis.yml export-ignore
|
||||||
/.php_cs export-ignore
|
/.php_cs export-ignore
|
||||||
/README.md export-ignore
|
|
||||||
/phpunit.xml.dist export-ignore
|
/phpunit.xml.dist export-ignore
|
||||||
/tests export-ignore
|
|
||||||
/phpstan.neon export-ignore
|
/phpstan.neon export-ignore
|
||||||
|
/.github export-ignore
|
||||||
|
/tests export-ignore
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
name: "CS"
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
env:
|
||||||
|
SYMFONY_PHPUNIT_VERSION: 7.5
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
coding-standards:
|
||||||
|
name: "CS Fixer & PHPStan"
|
||||||
|
runs-on: "ubuntu-18.04"
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
php:
|
||||||
|
- "7.3"
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: "Checkout"
|
||||||
|
uses: "actions/checkout@v2"
|
||||||
|
|
||||||
|
- name: "Install PHP"
|
||||||
|
uses: "shivammathur/setup-php@v2"
|
||||||
|
with:
|
||||||
|
coverage: "none"
|
||||||
|
php-version: "${{ matrix.php }}"
|
||||||
|
tools: cs2pr, composer:v1
|
||||||
|
ini-values: "date.timezone=Europe/Paris"
|
||||||
|
env:
|
||||||
|
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: "Add PHPStan"
|
||||||
|
run: "composer require phpstan/phpstan phpstan/phpstan-phpunit --dev --no-progress --no-suggest"
|
||||||
|
|
||||||
|
- name: "Install dependencies with Composer"
|
||||||
|
uses: "ramsey/composer-install@v1"
|
||||||
|
with:
|
||||||
|
composer-options: "--optimize-autoloader --prefer-dist"
|
||||||
|
|
||||||
|
- name: "Run PHP CS Fixer"
|
||||||
|
run: "php vendor/bin/php-cs-fixer fix --verbose --dry-run --format=checkstyle | cs2pr"
|
||||||
|
|
||||||
|
- name: "Install PHPUnit for PHPStan"
|
||||||
|
run: "php vendor/bin/simple-phpunit install"
|
||||||
|
|
||||||
|
- name: "Run PHPStan"
|
||||||
|
run: "php vendor/bin/phpstan analyse --error-format=checkstyle | cs2pr"
|
||||||
@@ -0,0 +1,202 @@
|
|||||||
|
name: "CI"
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- "master"
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- "master"
|
||||||
|
|
||||||
|
env:
|
||||||
|
fail-fast: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
phpunit:
|
||||||
|
name: "PHPUnit (PHP ${{ matrix.php }})"
|
||||||
|
runs-on: "ubuntu-18.04"
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
php:
|
||||||
|
- "5.6"
|
||||||
|
- "7.0"
|
||||||
|
- "7.1"
|
||||||
|
- "7.2"
|
||||||
|
- "7.3"
|
||||||
|
- "7.4"
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: "Checkout"
|
||||||
|
uses: "actions/checkout@v2"
|
||||||
|
with:
|
||||||
|
fetch-depth: 2
|
||||||
|
|
||||||
|
- name: "Install PHP"
|
||||||
|
uses: "shivammathur/setup-php@v2"
|
||||||
|
with:
|
||||||
|
php-version: "${{ matrix.php }}"
|
||||||
|
coverage: "none"
|
||||||
|
tools: composer:v1
|
||||||
|
extensions: tidy
|
||||||
|
ini-values: "date.timezone=Europe/Paris"
|
||||||
|
env:
|
||||||
|
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: "Force PHPUnit version"
|
||||||
|
if: matrix.php >= '7.2'
|
||||||
|
run: "echo $SYMFONY_PHPUNIT_VERSION"
|
||||||
|
env:
|
||||||
|
SYMFONY_PHPUNIT_VERSION: 7.5
|
||||||
|
|
||||||
|
- name: "Remove useless deps"
|
||||||
|
run: "composer remove friendsofphp/php-cs-fixer --dev --no-progress --no-update"
|
||||||
|
|
||||||
|
- name: "Install dependencies with Composer"
|
||||||
|
uses: "ramsey/composer-install@v1"
|
||||||
|
with:
|
||||||
|
composer-options: "--optimize-autoloader --prefer-dist"
|
||||||
|
|
||||||
|
- name: "Setup logs"
|
||||||
|
run: "mkdir -p build/logs"
|
||||||
|
|
||||||
|
- name: "Run PHPUnit"
|
||||||
|
run: "php vendor/bin/simple-phpunit -v"
|
||||||
|
|
||||||
|
phpunit-coverage:
|
||||||
|
name: "PHPUnit coverage (PHP ${{ matrix.php }})"
|
||||||
|
runs-on: "ubuntu-18.04"
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
php:
|
||||||
|
- "7.4"
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: "Checkout"
|
||||||
|
uses: "actions/checkout@v2"
|
||||||
|
with:
|
||||||
|
fetch-depth: 2
|
||||||
|
|
||||||
|
- name: "Install PHP with Xdebug"
|
||||||
|
uses: "shivammathur/setup-php@v2"
|
||||||
|
with:
|
||||||
|
php-version: "${{ matrix.php }}"
|
||||||
|
coverage: "xdebug"
|
||||||
|
tools: composer:v1
|
||||||
|
extensions: tidy
|
||||||
|
ini-values: "date.timezone=Europe/Paris"
|
||||||
|
env:
|
||||||
|
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: "Remove useless deps"
|
||||||
|
run: "composer remove friendsofphp/php-cs-fixer --dev --no-progress --no-update"
|
||||||
|
|
||||||
|
- name: "Install dependencies with Composer"
|
||||||
|
uses: "ramsey/composer-install@v1"
|
||||||
|
with:
|
||||||
|
composer-options: "--optimize-autoloader --prefer-dist"
|
||||||
|
|
||||||
|
- name: "Setup logs"
|
||||||
|
run: "mkdir -p build/logs"
|
||||||
|
|
||||||
|
- name: "Run PHPUnit (with coverage)"
|
||||||
|
run: "php vendor/bin/simple-phpunit -v --coverage-clover build/logs/clover.xml"
|
||||||
|
env:
|
||||||
|
SYMFONY_PHPUNIT_VERSION: 7.5
|
||||||
|
|
||||||
|
- name: "Retrieve Coveralls phar"
|
||||||
|
run: "wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.4.2/php-coveralls.phar"
|
||||||
|
|
||||||
|
- name: "Enable Coveralls phar"
|
||||||
|
run: "chmod +x php-coveralls.phar"
|
||||||
|
|
||||||
|
- name: "Upload to Coveralls"
|
||||||
|
run: "php php-coveralls.phar -v -x build/logs/clover.xml"
|
||||||
|
env:
|
||||||
|
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
phpunit-lowest:
|
||||||
|
name: "PHPUnit lowest deps (PHP ${{ matrix.php }})"
|
||||||
|
runs-on: "ubuntu-18.04"
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
php:
|
||||||
|
- "7.2"
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: "Checkout"
|
||||||
|
uses: "actions/checkout@v2"
|
||||||
|
with:
|
||||||
|
fetch-depth: 2
|
||||||
|
|
||||||
|
- name: "Install PHP"
|
||||||
|
uses: "shivammathur/setup-php@v2"
|
||||||
|
with:
|
||||||
|
php-version: "${{ matrix.php }}"
|
||||||
|
coverage: "none"
|
||||||
|
tools: composer:v1
|
||||||
|
extensions: tidy
|
||||||
|
ini-values: "date.timezone=Europe/Paris"
|
||||||
|
env:
|
||||||
|
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: "Remove useless deps"
|
||||||
|
run: "composer remove friendsofphp/php-cs-fixer --dev --no-progress --no-update"
|
||||||
|
|
||||||
|
- name: "Install dependencies with Composer"
|
||||||
|
uses: "ramsey/composer-install@v1"
|
||||||
|
with:
|
||||||
|
composer-options: "--optimize-autoloader --prefer-dist"
|
||||||
|
dependency-versions: "lowest"
|
||||||
|
|
||||||
|
- name: "Setup logs"
|
||||||
|
run: "mkdir -p build/logs"
|
||||||
|
|
||||||
|
- name: "Run PHPUnit"
|
||||||
|
run: "php vendor/bin/simple-phpunit -v"
|
||||||
|
env:
|
||||||
|
SYMFONY_PHPUNIT_VERSION: 7.5
|
||||||
|
|
||||||
|
phpunit-composerv2:
|
||||||
|
name: "PHPUnit with Composer v2 (PHP ${{ matrix.php }})"
|
||||||
|
runs-on: "ubuntu-18.04"
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
php:
|
||||||
|
- "7.4"
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: "Checkout"
|
||||||
|
uses: "actions/checkout@v2"
|
||||||
|
with:
|
||||||
|
fetch-depth: 2
|
||||||
|
|
||||||
|
- name: "Install PHP"
|
||||||
|
uses: "shivammathur/setup-php@v2"
|
||||||
|
with:
|
||||||
|
php-version: "${{ matrix.php }}"
|
||||||
|
coverage: "none"
|
||||||
|
tools: composer:v2
|
||||||
|
extensions: tidy
|
||||||
|
ini-values: "date.timezone=Europe/Paris"
|
||||||
|
env:
|
||||||
|
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: "Remove useless deps"
|
||||||
|
run: "composer remove friendsofphp/php-cs-fixer --dev --no-progress --no-update"
|
||||||
|
|
||||||
|
- name: "Install dependencies with Composer"
|
||||||
|
uses: "ramsey/composer-install@v1"
|
||||||
|
with:
|
||||||
|
composer-options: "--optimize-autoloader --prefer-dist"
|
||||||
|
|
||||||
|
- name: "Setup logs"
|
||||||
|
run: "mkdir -p build/logs"
|
||||||
|
|
||||||
|
- name: "Run PHPUnit"
|
||||||
|
run: "php vendor/bin/simple-phpunit -v"
|
||||||
|
env:
|
||||||
|
SYMFONY_PHPUNIT_VERSION: 7.5
|
||||||
@@ -2,3 +2,4 @@ vendor/
|
|||||||
coverage/
|
coverage/
|
||||||
composer.lock
|
composer.lock
|
||||||
.php_cs.cache
|
.php_cs.cache
|
||||||
|
.phpunit.result.cache
|
||||||
|
|||||||
@@ -1,2 +1,12 @@
|
|||||||
tools:
|
tools:
|
||||||
external_code_coverage: false
|
external_code_coverage: false
|
||||||
|
|
||||||
|
build:
|
||||||
|
nodes:
|
||||||
|
analysis:
|
||||||
|
tests:
|
||||||
|
override:
|
||||||
|
- php-scrutinizer-run
|
||||||
|
environment:
|
||||||
|
php:
|
||||||
|
version: 7.2
|
||||||
|
|||||||
+16
-24
@@ -1,42 +1,34 @@
|
|||||||
|
dist: xenial
|
||||||
|
os: linux
|
||||||
language: php
|
language: php
|
||||||
|
|
||||||
php:
|
# avoid double Travis build when the PR is created on upstream
|
||||||
- 5.6
|
if: |
|
||||||
- 7.0
|
type = pull_request OR \
|
||||||
- 7.1
|
branch = master
|
||||||
- 7.2
|
|
||||||
- 7.3
|
|
||||||
- nightly
|
|
||||||
|
|
||||||
matrix:
|
jobs:
|
||||||
include:
|
include:
|
||||||
- php: 7.2
|
- php: 8.0
|
||||||
env: CS_FIXER=run
|
env: SYMFONY_PHPUNIT_VERSION=7.5
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- php: nightly
|
- php: 8.0
|
||||||
|
|
||||||
# cache vendor dirs
|
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
- vendor
|
- $HOME/.composer/cache/files
|
||||||
- $HOME/.composer/cache
|
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi;
|
- if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi;
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- composer self-update
|
- if [ "$CS_FIXER" != "run" ]; then composer remove friendsofphp/php-cs-fixer --dev --no-progress --no-update ; fi;
|
||||||
|
- composer update --prefer-dist --no-progress --no-suggest -o $
|
||||||
|
- php vendor/bin/simple-phpunit install
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- if [ "$CS_FIXER" = "run" ]; then composer require phpstan/phpstan phpstan/phpstan-phpunit --dev -n ; fi;
|
- mkdir -p build/logs
|
||||||
- composer install -o --prefer-dist --no-interaction
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- mkdir -p build/logs
|
- php vendor/bin/simple-phpunit -v
|
||||||
- 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/phpstan analyse src tests --no-progress --level 1 ; fi;
|
|
||||||
|
|
||||||
after_script:
|
|
||||||
- php vendor/bin/php-coveralls -v -x build/logs/clover.xml
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# Readability
|
# Readability
|
||||||
|
|
||||||
|

|
||||||
[](https://travis-ci.org/j0k3r/php-readability)
|
[](https://travis-ci.org/j0k3r/php-readability)
|
||||||
[](https://coveralls.io/github/j0k3r/php-readability/?branch=master)
|
[](https://coveralls.io/github/j0k3r/php-readability/?branch=master)
|
||||||
[](https://packagist.org/packages/j0k3r/php-readability)
|
[](https://packagist.org/packages/j0k3r/php-readability)
|
||||||
|
|||||||
+2
-3
@@ -27,12 +27,11 @@
|
|||||||
"php": ">=5.6.0",
|
"php": ">=5.6.0",
|
||||||
"ext-mbstring": "*",
|
"ext-mbstring": "*",
|
||||||
"psr/log": "^1.0",
|
"psr/log": "^1.0",
|
||||||
"electrolinux/php-html5lib": "^0.1.0"
|
"masterminds/html5": "^2.7"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"php-coveralls/php-coveralls": "^2.1",
|
|
||||||
"friendsofphp/php-cs-fixer": "^2.14",
|
"friendsofphp/php-cs-fixer": "^2.14",
|
||||||
"monolog/monolog": "^1.24",
|
"monolog/monolog": "^1.24|^2.1",
|
||||||
"symfony/phpunit-bridge": "^4.2.3"
|
"symfony/phpunit-bridge": "^4.2.3"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
|
|||||||
+10
-5
@@ -1,8 +1,13 @@
|
|||||||
|
parameters:
|
||||||
|
level: 1
|
||||||
|
paths:
|
||||||
|
- src
|
||||||
|
- tests
|
||||||
|
|
||||||
|
# https://github.com/phpstan/phpstan/issues/694#issuecomment-350724288
|
||||||
|
bootstrapFiles:
|
||||||
|
- vendor/bin/.phpunit/phpunit-7.5-0/vendor/autoload.php
|
||||||
|
|
||||||
includes:
|
includes:
|
||||||
- vendor/phpstan/phpstan-phpunit/extension.neon
|
- vendor/phpstan/phpstan-phpunit/extension.neon
|
||||||
- vendor/phpstan/phpstan-phpunit/rules.neon
|
- vendor/phpstan/phpstan-phpunit/rules.neon
|
||||||
|
|
||||||
parameters:
|
|
||||||
# https://github.com/phpstan/phpstan/issues/694#issuecomment-350724288
|
|
||||||
autoload_files:
|
|
||||||
- vendor/bin/.phpunit/phpunit-7.4/vendor/autoload.php
|
|
||||||
|
|||||||
+1
-1
@@ -26,6 +26,6 @@
|
|||||||
</filter>
|
</filter>
|
||||||
|
|
||||||
<!-- <logging>
|
<!-- <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> -->
|
</logging> -->
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|||||||
+3
-26
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Readability;
|
namespace Readability;
|
||||||
|
|
||||||
use HTML5Lib\Parser;
|
use Masterminds\HTML5;
|
||||||
use Psr\Log\LoggerAwareInterface;
|
use Psr\Log\LoggerAwareInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Psr\Log\NullLogger;
|
use Psr\Log\NullLogger;
|
||||||
@@ -116,7 +116,6 @@ class Readability implements LoggerAwareInterface
|
|||||||
'drop-empty-paras' => true,
|
'drop-empty-paras' => true,
|
||||||
'drop-proprietary-attributes' => false,
|
'drop-proprietary-attributes' => false,
|
||||||
'enclose-text' => true,
|
'enclose-text' => true,
|
||||||
'enclose-block-text' => true,
|
|
||||||
'merge-divs' => true,
|
'merge-divs' => true,
|
||||||
// 'merge-spans' => true,
|
// 'merge-spans' => true,
|
||||||
'input-encoding' => '????',
|
'input-encoding' => '????',
|
||||||
@@ -307,8 +306,6 @@ class Readability implements LoggerAwareInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Run any post-process modifications to article content as necessary.
|
* Run any post-process modifications to article content as necessary.
|
||||||
*
|
|
||||||
* @param \DOMElement $articleContent
|
|
||||||
*/
|
*/
|
||||||
public function postProcessContent(\DOMElement $articleContent)
|
public function postProcessContent(\DOMElement $articleContent)
|
||||||
{
|
{
|
||||||
@@ -321,8 +318,6 @@ class Readability implements LoggerAwareInterface
|
|||||||
* For easier reading, convert this document to have footnotes at the bottom rather than inline links.
|
* 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
|
* @see http://www.roughtype.com/archives/2010/05/experiments_in.php
|
||||||
*
|
|
||||||
* @param \DOMElement $articleContent
|
|
||||||
*/
|
*/
|
||||||
public function addFootnotes(\DOMElement $articleContent)
|
public function addFootnotes(\DOMElement $articleContent)
|
||||||
{
|
{
|
||||||
@@ -385,8 +380,6 @@ 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 \DOMNode $articleContent
|
|
||||||
*/
|
*/
|
||||||
public function prepArticle(\DOMNode $articleContent)
|
public function prepArticle(\DOMNode $articleContent)
|
||||||
{
|
{
|
||||||
@@ -558,7 +551,6 @@ class Readability implements LoggerAwareInterface
|
|||||||
* This is the amount of text that is inside a link divided by the total text in the node.
|
* 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.
|
* Can exclude external references to differentiate between simple text and menus/infoblocks.
|
||||||
*
|
*
|
||||||
* @param \DOMElement $e
|
|
||||||
* @param bool $excludeExternal
|
* @param bool $excludeExternal
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
@@ -586,8 +578,6 @@ class Readability implements LoggerAwareInterface
|
|||||||
/**
|
/**
|
||||||
* Get an element relative weight.
|
* Get an element relative weight.
|
||||||
*
|
*
|
||||||
* @param \DOMElement $e
|
|
||||||
*
|
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getWeight(\DOMElement $e)
|
public function getWeight(\DOMElement $e)
|
||||||
@@ -607,8 +597,6 @@ class Readability implements LoggerAwareInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove extraneous break tags from a node.
|
* Remove extraneous break tags from a node.
|
||||||
*
|
|
||||||
* @param \DOMElement $node
|
|
||||||
*/
|
*/
|
||||||
public function killBreaks(\DOMElement $node)
|
public function killBreaks(\DOMElement $node)
|
||||||
{
|
{
|
||||||
@@ -623,12 +611,10 @@ class Readability implements LoggerAwareInterface
|
|||||||
*
|
*
|
||||||
* Updated 2012-09-18 to preserve youtube/vimeo iframes
|
* Updated 2012-09-18 to preserve youtube/vimeo iframes
|
||||||
*
|
*
|
||||||
* @param \DOMElement $e
|
|
||||||
* @param string $tag
|
* @param string $tag
|
||||||
*/
|
*/
|
||||||
public function clean(\DOMElement $e, $tag)
|
public function clean(\DOMElement $e, $tag)
|
||||||
{
|
{
|
||||||
$currentItem = null;
|
|
||||||
$targetList = $e->getElementsByTagName($tag);
|
$targetList = $e->getElementsByTagName($tag);
|
||||||
$isEmbed = ('audio' === $tag || 'video' === $tag || 'iframe' === $tag || 'object' === $tag || 'embed' === $tag);
|
$isEmbed = ('audio' === $tag || 'video' === $tag || 'iframe' === $tag || 'object' === $tag || 'embed' === $tag);
|
||||||
|
|
||||||
@@ -659,7 +645,6 @@ class Readability implements LoggerAwareInterface
|
|||||||
* "Fishy" is an algorithm based on content length, classnames,
|
* "Fishy" is an algorithm based on content length, classnames,
|
||||||
* link density, number of images & embeds, etc.
|
* link density, number of images & embeds, etc.
|
||||||
*
|
*
|
||||||
* @param \DOMElement $e
|
|
||||||
* @param string $tag
|
* @param string $tag
|
||||||
*/
|
*/
|
||||||
public function cleanConditionally(\DOMElement $e, $tag)
|
public function cleanConditionally(\DOMElement $e, $tag)
|
||||||
@@ -670,7 +655,6 @@ class Readability implements LoggerAwareInterface
|
|||||||
|
|
||||||
$tagsList = $e->getElementsByTagName($tag);
|
$tagsList = $e->getElementsByTagName($tag);
|
||||||
$curTagsLength = $tagsList->length;
|
$curTagsLength = $tagsList->length;
|
||||||
$node = null;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Gather counts for other typical elements embedded within.
|
* Gather counts for other typical elements embedded within.
|
||||||
@@ -772,8 +756,6 @@ class Readability implements LoggerAwareInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean out spurious headers from an Element. Checks things like classnames and link density.
|
* Clean out spurious headers from an Element. Checks things like classnames and link density.
|
||||||
*
|
|
||||||
* @param \DOMElement $e
|
|
||||||
*/
|
*/
|
||||||
public function cleanHeaders(\DOMElement $e)
|
public function cleanHeaders(\DOMElement $e)
|
||||||
{
|
{
|
||||||
@@ -915,8 +897,6 @@ class Readability implements LoggerAwareInterface
|
|||||||
/**
|
/**
|
||||||
* Initialize a node with the readability object. Also checks the
|
* Initialize a node with the readability object. Also checks the
|
||||||
* className/id for special names to add to its score.
|
* className/id for special names to add to its score.
|
||||||
*
|
|
||||||
* @param \DOMElement $node
|
|
||||||
*/
|
*/
|
||||||
protected function initializeNode(\DOMElement $node)
|
protected function initializeNode(\DOMElement $node)
|
||||||
{
|
{
|
||||||
@@ -1125,7 +1105,6 @@ class Readability implements LoggerAwareInterface
|
|||||||
*/
|
*/
|
||||||
if ($this->flagIsActive(self::FLAG_STRIP_UNLIKELYS) && $xpath) {
|
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);
|
$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) {
|
for ($c = $candidates->length - 1; $c >= 0; --$c) {
|
||||||
$node = $candidates->item($c);
|
$node = $candidates->item($c);
|
||||||
@@ -1137,7 +1116,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);
|
$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) {
|
for ($c = $candidates->length - 1; $c >= 0; --$c) {
|
||||||
$node = $candidates->item($c);
|
$node = $candidates->item($c);
|
||||||
@@ -1346,7 +1324,6 @@ class Readability implements LoggerAwareInterface
|
|||||||
* Get an element weight by attribute.
|
* Get an element weight by attribute.
|
||||||
* Uses regular expressions to tell if this element looks good or bad.
|
* Uses regular expressions to tell if this element looks good or bad.
|
||||||
*
|
*
|
||||||
* @param \DOMElement $element
|
|
||||||
* @param string $attribute
|
* @param string $attribute
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
@@ -1442,8 +1419,8 @@ 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) {
|
if ('html5lib' === $this->parser || 'html5' === $this->parser) {
|
||||||
$this->dom = Parser::parse($this->html);
|
$this->dom = (new HTML5())->loadHTML($this->html);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('libxml' === $this->parser) {
|
if ('libxml' === $this->parser) {
|
||||||
|
|||||||
Reference in New Issue
Block a user