Replaces subscribing feeds through a self-hosted Full-Text RSS proxy. Feed URLs go back to being real feed URLs and extraction happens inside tt-rss, using the same ftr-site-config rules the proxy used. The engine in lib/ has no tt-rss dependencies, so rules can be developed and audited from the command line; init.php is a thin adapter over it. Two findings from measuring the real subscription first, both of which shaped the design: - Firecrawl's own onlyMainContent is far too coarse to extract with (73KB of chrome on a Cloudflare post), but it is an excellent renderer. So it is used for rawHtml only and the rule engine does the extraction. - A body rule that stops matching after a redesign falls through to Readability and still produces a plausible article, so the breakage is invisible. Every extraction now records which rule matched and whether it fell back; auditing the 34 live feeds surfaced five community rules that match nothing. Custom rules included for the sites that needed them, including three comics where the article is an image and text-scoring extractors return the wrong thing or nothing at all. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011sSJdftQx5bW5HZHgUKF3i
117 lines
2.5 KiB
PHP
117 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Masterminds\HTML5\Tests\Parser;
|
|
|
|
use Masterminds\HTML5\Elements;
|
|
use Masterminds\HTML5\Parser\EventHandler;
|
|
|
|
/**
|
|
* This testing class gathers events from a parser and builds a stack of events.
|
|
* It is useful for checking the output of a tokenizer.
|
|
*
|
|
* IMPORTANT:
|
|
*
|
|
* The startTag event also kicks the parser into TEXT_RAW when it encounters
|
|
* script or pre tags. This is to match the behavior required by the HTML5 spec,
|
|
* which says that the tree builder must tell the tokenizer when to switch states.
|
|
*/
|
|
class EventStack implements EventHandler
|
|
{
|
|
protected $stack;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->stack = array();
|
|
}
|
|
|
|
/**
|
|
* Get the event stack.
|
|
*/
|
|
public function events()
|
|
{
|
|
return $this->stack;
|
|
}
|
|
|
|
public function depth()
|
|
{
|
|
return count($this->stack);
|
|
}
|
|
|
|
public function get($index)
|
|
{
|
|
return $this->stack[$index];
|
|
}
|
|
|
|
protected function store($event, $data = null)
|
|
{
|
|
$this->stack[] = array(
|
|
'name' => $event,
|
|
'data' => $data,
|
|
);
|
|
}
|
|
|
|
public function doctype($name, $type = 0, $id = null, $quirks = false)
|
|
{
|
|
$args = array(
|
|
$name,
|
|
$type,
|
|
$id,
|
|
$quirks,
|
|
);
|
|
$this->store('doctype', $args);
|
|
}
|
|
|
|
public function startTag($name, $attributes = array(), $selfClosing = false)
|
|
{
|
|
$args = func_get_args();
|
|
$this->store('startTag', $args);
|
|
if ('pre' == $name || 'script' == $name) {
|
|
return Elements::TEXT_RAW;
|
|
}
|
|
}
|
|
|
|
public function endTag($name)
|
|
{
|
|
$this->store('endTag', array(
|
|
$name,
|
|
));
|
|
}
|
|
|
|
public function comment($cdata)
|
|
{
|
|
$this->store('comment', array(
|
|
$cdata,
|
|
));
|
|
}
|
|
|
|
public function cdata($data)
|
|
{
|
|
$this->store('cdata', func_get_args());
|
|
}
|
|
|
|
public function text($cdata)
|
|
{
|
|
// fprintf(STDOUT, "Received TEXT event with: " . $cdata);
|
|
$this->store('text', array(
|
|
$cdata,
|
|
));
|
|
}
|
|
|
|
public function eof()
|
|
{
|
|
$this->store('eof');
|
|
}
|
|
|
|
public function parseError($msg, $line, $col)
|
|
{
|
|
// throw new EventStackParseError(sprintf("%s (line %d, col %d)", $msg, $line, $col));
|
|
// $this->store(sprintf("%s (line %d, col %d)", $msg, $line, $col));
|
|
$this->store('error', func_get_args());
|
|
}
|
|
|
|
public function processingInstruction($name, $data = null)
|
|
{
|
|
$this->store('pi', func_get_args());
|
|
}
|
|
}
|