Merge "Simplify RemexStripTagHandler by extending NullTokenHandler"
This commit is contained in:
commit
0ebeb72733
1 changed files with 5 additions and 26 deletions
|
|
@ -1,36 +1,23 @@
|
|||
<?php
|
||||
|
||||
use RemexHtml\Tokenizer\Attributes;
|
||||
use RemexHtml\Tokenizer\TokenHandler;
|
||||
use RemexHtml\Tokenizer\Tokenizer;
|
||||
use RemexHtml\Tokenizer\NullTokenHandler;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class RemexStripTagHandler implements TokenHandler {
|
||||
class RemexStripTagHandler extends NullTokenHandler {
|
||||
private $text = '';
|
||||
|
||||
public function getResult() {
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
function startDocument( Tokenizer $t, $fns, $fn ) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
function endDocument( $pos ) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
function error( $text, $pos ) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
|
||||
public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
|
||||
$this->text .= substr( $text, $start, $length );
|
||||
}
|
||||
|
||||
function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
|
||||
public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
|
||||
// Inject whitespace for typical block-level tags to
|
||||
// prevent merging unrelated<br>words.
|
||||
if ( $this->isBlockLevelTag( $name ) ) {
|
||||
|
|
@ -38,7 +25,7 @@ class RemexStripTagHandler implements TokenHandler {
|
|||
}
|
||||
}
|
||||
|
||||
function endTag( $name, $sourceStart, $sourceLength ) {
|
||||
public function endTag( $name, $sourceStart, $sourceLength ) {
|
||||
// Inject whitespace for typical block-level tags to
|
||||
// prevent merging unrelated<br>words.
|
||||
if ( $this->isBlockLevelTag( $name ) ) {
|
||||
|
|
@ -46,14 +33,6 @@ class RemexStripTagHandler implements TokenHandler {
|
|||
}
|
||||
}
|
||||
|
||||
function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
function comment( $text, $sourceStart, $sourceLength ) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
// Per https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
|
||||
// retrieved on sept 12, 2018. <br> is not block level but was added anyways.
|
||||
// The following is a complete list of all HTML block level elements
|
||||
|
|
|
|||
Loading…
Reference in a new issue