Parsoid
A bidirectional parser between wikitext and HTML5
|
A non-atomic fragment comprised of a wikitext string and a strip state. More...
Public Member Functions | |
isEmpty () | |
Returns true if this fragment is empty.This enables optimizations if implemented, but returns false by default. | |
isAtomic () | |
asDom (ParsoidExtensionAPI $ext, bool $release=false) | |
Return the fragment as a (prepared and loaded) DOM DocumentFragment belonging to the Parsoid top-level document.If $release is true, then this PFragment will become invalid after this method returns.
| |
asMarkedWikitext (StripState $stripState) | |
This method returns a "wikitext string" in the legacy format.Wikitext constructs will be parsed in the result. Constructs which are not representable in wikitext will be replaced with strip markers, and you will get a strip state which maps those markers back to PFragment objects. When you (for example) compose two marked strings and then ask for the result asDom , the strip markers in the marked strings will first be conceptually replaced with the PFragment from the StripState, and then the resulting interleaved strings and fragments will be composed. | |
split () | |
Split this fragment at its strip markers and return an array which alternates between string items and PFragment items. | |
trim () | |
Trim leading and trailing whitespace from this fragment. | |
toJsonArray () | |
Public Member Functions inherited from Wikimedia\Parsoid\Fragments\PFragment | |
isValid () | |
As an optimization to avoid unnecessary copying, certain operations on fragments may be destructive or lead to aliasing. | |
getSrcOffsets () | |
Return the region of the source document that corresponds to this fragment. | |
asHtmlString (ParsoidExtensionAPI $ext) | |
Return the fragment as a string of HTML. | |
registerFragmentClass (string $className) | |
Register a fragment type with the JSON deserialization code. | |
Static Public Member Functions | |
static | newFromWt (string $wikitext, ?DomSourceRange $srcOffsets) |
Return a new WikitextPFragment consisting of the given fragment of wikitext, and an optional source string for it. | |
static | newFromSplitWt (array $pieces, ?DomSourceRange $srcOffsets=null) |
Return a new WikitextPFragment consisting of the given array of pieces concatenated together. | |
static | newFromLiteral (string $value, ?DomSourceRange $srcOffsets) |
Returns a new WikitextPFragment from the given literal string and optional source offsets. | |
static | castFromPFragment (PFragment $fragment) |
Return a WikitextPFragment corresponding to the given PFragment. | |
static | concat (PFragment ... $fragments) |
Return a WikitextPFragment representing the concatenation of the given fragments, as wikitext. | |
static | newFromJsonArray (array $json) |
static | jsonClassHintFor (string $keyName) |
Static Public Member Functions inherited from Wikimedia\Parsoid\Fragments\PFragment | |
static | fromSplitWt (array $pieces, ?DomSourceRange $srcOffset=null) |
Helper function to create a new fragment from a mixed array of strings and fragments. | |
static | hint () |
Public Attributes | |
const | TYPE_HINT = 'wt' |
Additional Inherited Members | |
Protected Member Functions inherited from Wikimedia\Parsoid\Fragments\PFragment | |
__construct (?DomSourceRange $srcOffsets) | |
Static Protected Member Functions inherited from Wikimedia\Parsoid\Fragments\PFragment | |
static | joinSourceRange (?DomSourceRange $first, ?DomSourceRange $second) |
Helper function to append two source ranges. | |
Protected Attributes inherited from Wikimedia\Parsoid\Fragments\PFragment | |
DomSourceRange | $srcOffsets |
The original wikitext source range for this fragment, or null for synthetic content that corresponds to no part of the original authored text. | |
Static Protected Attributes inherited from Wikimedia\Parsoid\Fragments\PFragment | |
static array | $FRAGMENT_TYPES |
A non-atomic fragment comprised of a wikitext string and a strip state.
The wikitext string may contain strip markers, which are placeholders corresponding to other atomic fragments. The internal StripState holds the mapping between placeholders and the corresponding atomic fragments.
WikitextPFragments are not atomic, and so a WikitextPFragment should never contain strip markers corresponding to other WikitextPFragments.
Wikimedia\Parsoid\Fragments\WikitextPFragment::asDom | ( | ParsoidExtensionAPI | $ext, |
bool | $release = false ) |
Return the fragment as a (prepared and loaded) DOM DocumentFragment belonging to the Parsoid top-level document.If $release is true, then this PFragment will become invalid after this method returns.
Reimplemented from Wikimedia\Parsoid\Fragments\PFragment.
Wikimedia\Parsoid\Fragments\WikitextPFragment::asMarkedWikitext | ( | StripState | $stripState | ) |
This method returns a "wikitext string" in the legacy format.Wikitext constructs will be parsed in the result. Constructs which are not representable in wikitext will be replaced with strip markers, and you will get a strip state which maps those markers back to PFragment objects. When you (for example) compose two marked strings and then ask for the result asDom
, the strip markers in the marked strings will first be conceptually replaced with the PFragment from the StripState, and then the resulting interleaved strings and fragments will be composed.
Reimplemented from Wikimedia\Parsoid\Fragments\PFragment.
|
static |
Return a WikitextPFragment corresponding to the given PFragment.
If the fragment is not already a WikitextPFragment, this will convert it using PFragment::asMarkedWikitext().
Wikimedia\Parsoid\Fragments\WikitextPFragment::isAtomic | ( | ) |
Reimplemented from Wikimedia\Parsoid\Fragments\PFragment.
Wikimedia\Parsoid\Fragments\WikitextPFragment::isEmpty | ( | ) |
Returns true if this fragment is empty.This enables optimizations if implemented, but returns false by default.
Reimplemented from Wikimedia\Parsoid\Fragments\PFragment.
|
static |
Reimplemented from Wikimedia\Parsoid\Fragments\PFragment.
|
static |
Reimplemented from Wikimedia\Parsoid\Fragments\PFragment.
|
static |
Returns a new WikitextPFragment from the given literal string and optional source offsets.
Unlike LiteralStringPFragment, the resulting fragment is non-atomic – it will not be an opaque strip marked but instead will consists of escaped wikitext that will evaluate to the desired string value.
string | $value | The literal string |
?DomSourceRange | $srcOffsets | The source range corresponding to this literal string, if there is one |
|
static |
Return a new WikitextPFragment consisting of the given array of pieces concatenated together.
Each piece can contain either a string
of wikitext (without strip markers) or a PFragment.
array<string|PFragment> | $pieces |
Wikimedia\Parsoid\Fragments\WikitextPFragment::split | ( | ) |
Split this fragment at its strip markers and return an array which alternates between string items and PFragment items.
The first and last items are guaranteed to be strings, and the array length is guaranteed to be odd and at least 1.
Wikimedia\Parsoid\Fragments\WikitextPFragment::toJsonArray | ( | ) |
Reimplemented from Wikimedia\Parsoid\Fragments\PFragment.
Wikimedia\Parsoid\Fragments\WikitextPFragment::trim | ( | ) |
Trim leading and trailing whitespace from this fragment.
If the result is just a strip marker, will return the fragment corresponding to that strip marker; that is, this method is not guaranteed to return a WikitextPFragment.