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.
 
 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 ()
 
 jsonSerialize ()
 
- 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.
 
 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 fromArray (array $dsr)
 Create a new DomSourceRange from an array of integers/null (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

◆ 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

◆ fromArray()

static Wikimedia\Parsoid\Core\DomSourceRange::fromArray ( 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.

◆ 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

◆ hasValidTagWidths()

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

◆ 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

◆ 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

◆ jsonSerialize()

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

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

◆ 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

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