Parsoid
A bidirectional parser between wikitext and HTML5
|
An abstraction/generalization of "strip state" from mediawiki core. More...
Public Member Functions | |
__clone () | |
isEmpty () | |
Return true if there are no items in this strip state. | |
addWtItem (PFragment $fragment) | |
Add the given fragment to the strip state, returning a wikitext string that can be used as a placeholder for it. | |
splitWt (string $wikitext) | |
Split the given wikitext string at its strip markers and return an array which alternates between string items and PFragment items. | |
addAllFrom (StripState ... $others) | |
Add all mappings from the given strip states to this one. | |
Static Public Member Functions | |
static | containsStripMarker (string $s) |
Return true if the given wikitext string contains a strip marker, or false otherwise. | |
static | startsWithStripMarker (string $s) |
Return true if the given wikitext string starts with a strip marker, or false otherwise. | |
static | endsWithStripMarker (string $s) |
Return true if the given wikitext string ends with a strip marker, or false otherwise. | |
static | new () |
Create a new empty strip state. | |
static | merge (StripState $first, StripState ... $others) |
Create a new strip state which contains the mappings of all of the given strip states. | |
An abstraction/generalization of "strip state" from mediawiki core.
The basic idea is that a special "strip marker" can be added to a text string to represent the insertion of a fragment, here represented as a PFragment (in core, represented as HTML). This allows us to tunnel rich content through interfaces which only allow strings, as long as (a) we can maintain a strip state on the side, and (b) we guarantee that the "strip markers" can never be forged in the string. For strip markers in wikitext and HTML this is guaranteed by using a character (\x7f) which is invalid in both wikitext and HTML.
The StripState object is not serializable because we can't easily enforce the uniqueness of strip state keys on deserialization. It is recommended that wikitext+strip state be serialized using ::splitWt() (ie, as an array alternating between wikitext strings and serialized PFragments) which both avoids the need to serialize the strip state itself and also avoids exposing the internal keys in the serialized representation.
StripState should generally be considered an opaque type internal to Parsoid; most external clients should use the appropriate split
methods to yield a list of Fragments rather than directly interact with strip markers.
Wikimedia\Parsoid\Fragments\StripState::splitWt | ( | string | $wikitext | ) |
Split the given wikitext string 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.