Parsoid
A bidirectional parser between wikitext and HTML5
Loading...
Searching...
No Matches
Wikimedia\Parsoid\Core\DomSourceRange Class Reference

Represents a DOM source range. More...

+ Inheritance diagram for Wikimedia\Parsoid\Core\DomSourceRange:
+ Collaboration diagram for Wikimedia\Parsoid\Core\DomSourceRange:

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ __construct()

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).

Parameters
?int$startThe starting index (UTF-8 byte count, inclusive)
?int$endThe ending index (UTF-8 byte count, exclusive)
?int$openWidthThe width of the open container tag
?int$closeWidthThe width of the close container tag
int$leadingWSThe width of WS chars between opening tag & first child
int$trailingWSThe width of WS chars between last child & closing tag

Member Function Documentation

◆ closeRange()

Wikimedia\Parsoid\Core\DomSourceRange::closeRange ( )

Return the source range corresponding to the close portion of this range.

Returns
SourceRange

◆ closeSubstr()

Wikimedia\Parsoid\Core\DomSourceRange::closeSubstr ( string $str)

Return the substring of the given string corresponding to the close portion of this range.

Parameters
string$strThe source text string
Returns
string

◆ fromTsr()

static Wikimedia\Parsoid\Core\DomSourceRange::fromTsr ( SourceRange $tsr)
static

Convert a TSR to a DSR with zero-width container open/close tags.

Parameters
SourceRange$tsr
Returns
DomSourceRange

◆ hasTrimmedWS()

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.

Returns
bool True if either leadingWS or trailingWS is non-zero.

◆ hasValidLeadingWS()

Wikimedia\Parsoid\Core\DomSourceRange::hasValidLeadingWS ( )
Note
In most cases you should check to see if this node ::hasTrimmedWS() and whether the amount is valid.
Returns
bool if the amount of leading whitespace is known.

◆ hasValidTagWidths()

Wikimedia\Parsoid\Core\DomSourceRange::hasValidTagWidths ( )
Returns
bool True if the tag widths are valid.

◆ hasValidTrailingWS()

Wikimedia\Parsoid\Core\DomSourceRange::hasValidTrailingWS ( )
Note
In most cases you should check to see if this node ::hasTrimmedWS() and whether the amount is valid.
Returns
bool if the amount of trailing whitespace is known.

◆ hint()

static Wikimedia\Parsoid\Core\DomSourceRange::hint ( )
static

JsonCodec serialization hint.

Reimplemented from Wikimedia\Parsoid\Tokens\SourceRange.

◆ innerEnd()

Wikimedia\Parsoid\Core\DomSourceRange::innerEnd ( )

Return the "inner end", that is, the end offset minus the close width.

Returns
int

◆ innerLength()

Wikimedia\Parsoid\Core\DomSourceRange::innerLength ( )

Return the length of this source range, excluding the open and close tag widths.

Returns
int

◆ innerRange()

Wikimedia\Parsoid\Core\DomSourceRange::innerRange ( )

Return the source range corresponding to the inner portion of this range.

Returns
SourceRange

◆ innerStart()

Wikimedia\Parsoid\Core\DomSourceRange::innerStart ( )

Return the "inner start", that is, the start offset plus the open width.

Returns
int

◆ innerSubstr()

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).

Parameters
string$strThe source text string
Returns
string

◆ newFromJsonArray()

static Wikimedia\Parsoid\Core\DomSourceRange::newFromJsonArray ( array $dsr)
static

Create a new DomSourceRange from an array of integers/null (such as created during JSON serialization).

Parameters
array<int|null>$dsr
Returns
DomSourceRange

Reimplemented from Wikimedia\Parsoid\Tokens\SourceRange.

◆ offset()

Wikimedia\Parsoid\Core\DomSourceRange::offset ( int $amount)

Return a new DOM source range shifted by $amount.

Parameters
int$amountThe amount to shift by
Returns
DomSourceRange

Reimplemented from Wikimedia\Parsoid\Tokens\SourceRange.

◆ openRange()

Wikimedia\Parsoid\Core\DomSourceRange::openRange ( )

Return the source range corresponding to the open portion of this range.

Returns
SourceRange

◆ openSubstr()

Wikimedia\Parsoid\Core\DomSourceRange::openSubstr ( string $str)

Return the substring of the given string corresponding to the open portion of this range.

Parameters
string$strThe source text string
Returns
string

◆ stripTags()

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 ).)

Parameters
string$srcThe source text string from $this->start (inclusive) to $this->end (exclusive).
Returns
string

◆ toJsonArray()

Wikimedia\Parsoid\Core\DomSourceRange::toJsonArray ( )

The documentation for this class was generated from the following file: