Parsoid
A bidirectional parser between wikitext and HTML5
|
Represents a DOM source range. More...
Public Member Functions | |
__construct (?int $start, ?int $end, ?int $openWidth, ?int $closeWidth, int $leadingWS=0, int $trailingWS=0) | |
Create a new DOM source offset range (DSR). | |
innerSubstr (string $str) | |
Return the substring of the given string corresponding to the inner portion of this range (that is, not including the opening and closing tag widths). | |
innerStart () | |
Return the "inner start", that is, the start offset plus the open width. | |
innerEnd () | |
Return the "inner end", that is, the end offset minus the close width. | |
innerLength () | |
Return the length of this source range, excluding the open and close tag widths. | |
openSubstr (string $str) | |
Return the substring of the given string corresponding to the open portion of this range. | |
closeSubstr (string $str) | |
Return the substring of the given string corresponding to the close portion of this range. | |
openRange () | |
Return the source range corresponding to the open portion of this range. | |
closeRange () | |
Return the source range corresponding to the close portion of this range. | |
innerRange () | |
Return the source range corresponding to the inner portion of this range. | |
stripTags (string $src) | |
Strip the tag open and close from the beginning and end of the provided string. | |
offset (int $amount) | |
Return a new DOM source range shifted by $amount. | |
hasValidTagWidths () | |
hasTrimmedWS () | |
Determine if this DSR records that whitespace was trimmed from this node. | |
hasValidLeadingWS () | |
hasValidTrailingWS () | |
toJsonArray () | |
Public Member Functions inherited from Wikimedia\Parsoid\Tokens\SourceRange | |
__construct (?int $start, ?int $end) | |
Create a new source offset range. | |
expandTsrK () | |
Return a KVSourceRange where this SourceRange is the key, and the value has zero length. | |
expandTsrV () | |
Return a KVSourceRange where this SourceRange is the value, and the key has zero length. | |
join (SourceRange $value) | |
Return a KVSourceRange by using this SourceRange for the key and the given SourceRange parameter for the value. | |
substr (string $str) | |
Return the substring of the given string corresponding to this range. | |
to (SourceRange $sr) | |
Return a range from the end of this range to the start of the given range. | |
length () | |
Return the length of this source range. | |
Static Public Member Functions | |
static | fromTsr (SourceRange $tsr) |
Convert a TSR to a DSR with zero-width container open/close tags. | |
static | newFromJsonArray (array $dsr) |
Create a new DomSourceRange from an array of integers/null (such as created during JSON serialization). | |
static | hint () |
JsonCodec serialization hint. | |
Static Public Member Functions inherited from Wikimedia\Parsoid\Tokens\SourceRange | |
static | fromArray (array $sr) |
Create a new source offset range from an array of integers (such as created during JSON serialization). | |
Public Attributes | |
$openWidth | |
$closeWidth | |
$leadingWS = 0 | |
$trailingWS = 0 | |
Public Attributes inherited from Wikimedia\Parsoid\Tokens\SourceRange | |
$start | |
$end | |
Represents a DOM source range.
That is, for a given DOM tree, gives the source offset range in the original wikitext for this DOM tree, as well as the opening and closing tag widths if appropriate.
Wikimedia\Parsoid\Core\DomSourceRange::__construct | ( | ?int | $start, |
?int | $end, | ||
?int | $openWidth, | ||
?int | $closeWidth, | ||
int | $leadingWS = 0, | ||
int | $trailingWS = 0 ) |
Create a new DOM source offset range (DSR).
?int | $start | The starting index (UTF-8 byte count, inclusive) |
?int | $end | The ending index (UTF-8 byte count, exclusive) |
?int | $openWidth | The width of the open container tag |
?int | $closeWidth | The width of the close container tag |
int | $leadingWS | The width of WS chars between opening tag & first child |
int | $trailingWS | The width of WS chars between last child & closing tag |
Wikimedia\Parsoid\Core\DomSourceRange::closeRange | ( | ) |
Return the source range corresponding to the close portion of this range.
Wikimedia\Parsoid\Core\DomSourceRange::closeSubstr | ( | string | $str | ) |
Return the substring of the given string corresponding to the close portion of this range.
string | $str | The source text string |
|
static |
Convert a TSR to a DSR with zero-width container open/close tags.
SourceRange | $tsr |
Wikimedia\Parsoid\Core\DomSourceRange::hasTrimmedWS | ( | ) |
Determine if this DSR records that whitespace was trimmed from this node.
Note that this doesn't mean that the amount trimmed is known; use ::hasValidLeadingWS() or ::hasValidTrimmedWS() to determine that.
Wikimedia\Parsoid\Core\DomSourceRange::hasValidLeadingWS | ( | ) |
Wikimedia\Parsoid\Core\DomSourceRange::hasValidTagWidths | ( | ) |
Wikimedia\Parsoid\Core\DomSourceRange::hasValidTrailingWS | ( | ) |
|
static |
JsonCodec serialization hint.
Reimplemented from Wikimedia\Parsoid\Tokens\SourceRange.
Wikimedia\Parsoid\Core\DomSourceRange::innerEnd | ( | ) |
Return the "inner end", that is, the end offset minus the close width.
Wikimedia\Parsoid\Core\DomSourceRange::innerLength | ( | ) |
Return the length of this source range, excluding the open and close tag widths.
Wikimedia\Parsoid\Core\DomSourceRange::innerRange | ( | ) |
Return the source range corresponding to the inner portion of this range.
Wikimedia\Parsoid\Core\DomSourceRange::innerStart | ( | ) |
Return the "inner start", that is, the start offset plus the open width.
Wikimedia\Parsoid\Core\DomSourceRange::innerSubstr | ( | string | $str | ) |
Return the substring of the given string corresponding to the inner portion of this range (that is, not including the opening and closing tag widths).
string | $str | The source text string |
|
static |
Create a new DomSourceRange from an array of integers/null (such as created during JSON serialization).
array<int|null> | $dsr |
Reimplemented from Wikimedia\Parsoid\Tokens\SourceRange.
Wikimedia\Parsoid\Core\DomSourceRange::offset | ( | int | $amount | ) |
Return a new DOM source range shifted by $amount.
int | $amount | The amount to shift by |
Reimplemented from Wikimedia\Parsoid\Tokens\SourceRange.
Wikimedia\Parsoid\Core\DomSourceRange::openRange | ( | ) |
Return the source range corresponding to the open portion of this range.
Wikimedia\Parsoid\Core\DomSourceRange::openSubstr | ( | string | $str | ) |
Return the substring of the given string corresponding to the open portion of this range.
string | $str | The source text string |
Wikimedia\Parsoid\Core\DomSourceRange::stripTags | ( | string | $src | ) |
Strip the tag open and close from the beginning and end of the provided string.
This is similar to DomSourceRange::innerSubstr()
but we assume that the string before $this->start
and after $this->end
has already been removed. (That is, that the input is $this->substr( $originalWikitextSource )
.)
string | $src | The source text string from $this->start (inclusive) to $this->end (exclusive). |
Wikimedia\Parsoid\Core\DomSourceRange::toJsonArray | ( | ) |
Reimplemented from Wikimedia\Parsoid\Tokens\SourceRange.