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

A fragment comprised of a literal string, which will be protected from future processing and will be appropriately escaped when embedded in HTML. More...

+ Inheritance diagram for Wikimedia\Parsoid\Fragments\LiteralStringPFragment:
+ Collaboration diagram for Wikimedia\Parsoid\Fragments\LiteralStringPFragment:

Public Member Functions

 isEmpty ()
 Returns true if this fragment is empty.This enables optimizations if implemented, but returns false by default.
 
 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.
Note
The default implementation of asDom() calls asHtmlString(). Subclassses must implement either asDom() or asHtmlString() to avoid infinite mutual recursion.

 
 asHtmlString (ParsoidExtensionAPI $ext)
 Return the fragment as a string of HTML.This method is very similar to asDom() but also supports fragmentary and unbalanced HTML, and therefore composition may yield unexpected results. This is a common type in legacy MediaWiki code, but use in new code should be discouraged. Data attributes will be represented as inline attributes, which may be suboptimal.

Note
The default implementation of asHtmlString() calls asDom(). Subclassses must implement either asDom() or asHtmlString() to avoid infinite mutual recursion.

 
 toJsonArray ()
 
- Public Member Functions inherited from Wikimedia\Parsoid\Fragments\PFragment
 isAtomic ()
 Returns true if this fragment contains no wikitext elements; that is, if ::asMarkedWikitext() given an empty strip state would return a single strip marker and add a single item to the strip state (representing $this).
 
 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.
 
 asMarkedWikitext (StripState $stripState)
 This method returns a "wikitext string" in the legacy format.
 
 registerFragmentClass (string $className)
 Register a fragment type with the JSON deserialization code.
 

Static Public Member Functions

static newFromLiteral (string $value, ?DomSourceRange $srcOffsets)
 Returns a new LiteralStringPFragment from the given literal string and optional source offsets.
 
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 = 'lit'
 

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
 

Detailed Description

A fragment comprised of a literal string, which will be protected from future processing and will be appropriately escaped when embedded in HTML.

This fragment is equivalent to the "nowiki" strip state in the legacy parser. It is an atomic fragment.

Member Function Documentation

◆ asDom()

Wikimedia\Parsoid\Fragments\LiteralStringPFragment::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.

Note
The default implementation of asDom() calls asHtmlString(). Subclassses must implement either asDom() or asHtmlString() to avoid infinite mutual recursion.

Reimplemented from Wikimedia\Parsoid\Fragments\PFragment.

◆ asHtmlString()

Wikimedia\Parsoid\Fragments\LiteralStringPFragment::asHtmlString ( ParsoidExtensionAPI $ext)

Return the fragment as a string of HTML.This method is very similar to asDom() but also supports fragmentary and unbalanced HTML, and therefore composition may yield unexpected results. This is a common type in legacy MediaWiki code, but use in new code should be discouraged. Data attributes will be represented as inline attributes, which may be suboptimal.

Note
The default implementation of asHtmlString() calls asDom(). Subclassses must implement either asDom() or asHtmlString() to avoid infinite mutual recursion.

Reimplemented from Wikimedia\Parsoid\Fragments\PFragment.

◆ isEmpty()

Wikimedia\Parsoid\Fragments\LiteralStringPFragment::isEmpty ( )

Returns true if this fragment is empty.This enables optimizations if implemented, but returns false by default.

Reimplemented from Wikimedia\Parsoid\Fragments\PFragment.

◆ jsonClassHintFor()

static Wikimedia\Parsoid\Fragments\LiteralStringPFragment::jsonClassHintFor ( string $keyName)
static

◆ newFromJsonArray()

static Wikimedia\Parsoid\Fragments\LiteralStringPFragment::newFromJsonArray ( array $json)
static

◆ newFromLiteral()

static Wikimedia\Parsoid\Fragments\LiteralStringPFragment::newFromLiteral ( string $value,
?DomSourceRange $srcOffsets )
static

Returns a new LiteralStringPFragment from the given literal string and optional source offsets.

Unlike WikitextPFragment, the resulting fragment is atomic: it will be treated as an opaque strip marker, not escaped wikitext, and will thus be invisible to future wikitext processing.

See also
WikitextPFragment::newFromLiteral() for a non-atomic fragment equivalent.
Parameters
string$valueThe literal string
?DomSourceRange$srcOffsetsThe source range corresponding to this literal string, if there is one

◆ toJsonArray()

Wikimedia\Parsoid\Fragments\LiteralStringPFragment::toJsonArray ( )

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