mirror of
https://github.com/j0k3r/php-readability.git
synced 2026-09-27 06:26:17 +00:00
Update coding style for upcoming PHP-CS-Fixer changes
Once we bump minimum PHP version, we will get newer PHP-CS-Fixer, which will try to apply this cleanups. (partially cherry picked from commit648d8c605b) Though avoid disabling `modernize_strpos` since it was only introduced in PHP-CS-Fixer 3.2.0: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/commit/2ca22a27c4ffb8cc46f20e7110b1dfcbb0c8c47c Also had to disable `visibility_required` for constants since those require PHP ≥ 7.1: https://cs.symfony.com/doc/rules/class_notation/visibility_required.html And remove type hint from `grabArticle` since implicitly nullable types were deprecated in PHP 8.4: https://wiki.php.net/rfc/deprecate-implicitly-nullable-types But we cannot use explicitly nullable types, which require PHP ≥ 7.1: https://wiki.php.net/rfc/nullable_types Also switch code blocks to Markdown syntax to work around `phpdoc_separation`, ApiGen uses Markdown these days anyway. (partially cherry picked from commit9ed89bde92)
This commit is contained in:
+16
-14
@@ -144,7 +144,7 @@ class Readability implements LoggerAwareInterface
|
||||
// HACK: replace linebreaks plus br's with p's
|
||||
'!(<br[^>]*>[ \r\n\s]*){2,}!i' => '</p><p>',
|
||||
// replace noscripts
|
||||
//'!</?noscript>!is' => '',
|
||||
// '!</?noscript>!is' => '',
|
||||
// replace fonts to spans
|
||||
'!<(/?)font[^>]*>!is' => '<\\1span>',
|
||||
];
|
||||
@@ -155,8 +155,8 @@ class Readability implements LoggerAwareInterface
|
||||
// replace empty tags that break layouts
|
||||
'!<(?:a|div|p|figure)[^>]+/>!is' => '',
|
||||
// remove all attributes on text tags
|
||||
//'!<(\s*/?\s*(?:blockquote|br|hr|code|div|article|span|footer|aside|p|pre|dl|li|ul|ol)) [^>]+>!is' => "<\\1>",
|
||||
//single newlines cleanup
|
||||
// '!<(\s*/?\s*(?:blockquote|br|hr|code|div|article|span|footer|aside|p|pre|dl|li|ul|ol)) [^>]+>!is' => "<\\1>",
|
||||
// single newlines cleanup
|
||||
"/\n+/" => "\n",
|
||||
// modern web...
|
||||
'!<pre[^>]*>\s*<code!is' => '<pre',
|
||||
@@ -366,7 +366,7 @@ class Readability implements LoggerAwareInterface
|
||||
$articleLink->setAttribute('style', 'color: inherit; text-decoration: none;');
|
||||
$articleLink->setAttribute('name', 'readabilityLink-' . $linkCount);
|
||||
$footnote->setInnerHtml('<small><sup><a href="#readabilityLink-' . $linkCount . '" title="Jump to Link in Article">^</a></sup></small> ');
|
||||
$footnoteLink->setInnerHtml(('' !== $footnoteLink->getAttribute('title') ? $footnoteLink->getAttribute('title') : $linkText));
|
||||
$footnoteLink->setInnerHtml('' !== $footnoteLink->getAttribute('title') ? $footnoteLink->getAttribute('title') : $linkText);
|
||||
$footnoteLink->setAttribute('name', 'readabilityFootnoteLink-' . $linkCount);
|
||||
$footnote->appendChild($footnoteLink);
|
||||
|
||||
@@ -796,7 +796,7 @@ class Readability implements LoggerAwareInterface
|
||||
*/
|
||||
public function addFlag($flag)
|
||||
{
|
||||
$this->flags = $this->flags | $flag;
|
||||
$this->flags |= $flag;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -806,13 +806,14 @@ class Readability implements LoggerAwareInterface
|
||||
*/
|
||||
public function removeFlag($flag)
|
||||
{
|
||||
$this->flags = $this->flags & ~$flag;
|
||||
$this->flags &= ~$flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug.
|
||||
*
|
||||
* @deprecated use $this->logger->debug() instead
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function dbg($msg)
|
||||
@@ -824,6 +825,7 @@ class Readability implements LoggerAwareInterface
|
||||
* Dump debug info.
|
||||
*
|
||||
* @deprecated since Monolog gather log, we don't need it
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function dump_dbg()
|
||||
@@ -973,11 +975,11 @@ class Readability implements LoggerAwareInterface
|
||||
* Using a variety of metrics (content score, classname, element types), find the content that is
|
||||
* most likely to be the stuff a user wants to read. Then return it wrapped up in a div.
|
||||
*
|
||||
* @param \DOMElement $page
|
||||
* @param ?\DOMElement $page
|
||||
*
|
||||
* @return \DOMElement|false
|
||||
*/
|
||||
protected function grabArticle(\DOMElement $page = null)
|
||||
protected function grabArticle($page = null)
|
||||
{
|
||||
if (!$page) {
|
||||
$page = $this->dom;
|
||||
@@ -992,7 +994,7 @@ class Readability implements LoggerAwareInterface
|
||||
|
||||
$allElements = $page->getElementsByTagName('*');
|
||||
|
||||
for ($nodeIndex = 0; ($node = $allElements->item($nodeIndex)); ++$nodeIndex) {
|
||||
for ($nodeIndex = 0; $node = $allElements->item($nodeIndex); ++$nodeIndex) {
|
||||
$tagName = $node->tagName;
|
||||
|
||||
$nodeContent = $node->getInnerHTML();
|
||||
@@ -1136,9 +1138,9 @@ class Readability implements LoggerAwareInterface
|
||||
// Remove unlikely candidates
|
||||
$unlikelyMatchString = $node->getAttribute('class') . ' ' . $node->getAttribute('id') . ' ' . $node->getAttribute('style');
|
||||
|
||||
if (mb_strlen($unlikelyMatchString) > 3 && // don't process "empty" strings
|
||||
preg_match($this->regexps['unlikelyCandidates'], $unlikelyMatchString) &&
|
||||
!preg_match($this->regexps['okMaybeItsACandidate'], $unlikelyMatchString)
|
||||
if (mb_strlen($unlikelyMatchString) > 3 // don't process "empty" strings
|
||||
&& preg_match($this->regexps['unlikelyCandidates'], $unlikelyMatchString)
|
||||
&& !preg_match($this->regexps['okMaybeItsACandidate'], $unlikelyMatchString)
|
||||
) {
|
||||
$this->logger->debug('Removing unlikely candidate (using conf) ' . $node->getNodePath() . ' by "' . $unlikelyMatchString . '" with readability ' . ($node->hasAttribute('readability') ? (int) $node->getAttributeNode('readability')->value : 0));
|
||||
$node->parentNode->removeChild($node);
|
||||
@@ -1289,8 +1291,8 @@ class Readability implements LoggerAwareInterface
|
||||
|
||||
// To ensure a node does not interfere with readability styles, remove its classnames & ids.
|
||||
// Now done via RegExp post_filter.
|
||||
//$nodeToAppend->removeAttribute('class');
|
||||
//$nodeToAppend->removeAttribute('id');
|
||||
// $nodeToAppend->removeAttribute('class');
|
||||
// $nodeToAppend->removeAttribute('id');
|
||||
// Append sibling and subtract from our list as appending removes a node.
|
||||
$articleContent->appendChild($nodeToAppend);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user