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

A page bundle stores an HTML DOM with separated data-parsoid and data-mw content. More...

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

Public Member Functions

 toDom (bool $load=true, ?array $options=null, ?array &$fragments=null)
 Return a DOM from the contents of this page bundle.
 
 toSingleDocument ()
 Create a "PageBundle as single Document" by embedding page bundle information into a <script> element in the <head> of the DOM.
 
 toSingleDocumentHtml (array $options=[])
 Convert this DomPageBundle to "single document" form, where page bundle information is embedded in the <head> of the document.
 
 toInlineAttributeDocument (SiteConfig $siteConfig, array $options=[], ?array &$fragments=null,)
 Convert this DomPageBundle to "inline attribute" form, where page bundle information is represented as inline JSON-valued attributes.
 
 toInlineAttributeHtml (SiteConfig $siteConfig, array $options=[], ?array &$fragments=null,)
 Convert this DomPageBundle to "inline attribute" form, where page bundle information is represented as inline JSON-valued attributes.
 
 toJsonArray ()
 
- Public Member Functions inherited from Wikimedia\Parsoid\Core\BasePageBundle
 validate (string $contentVersion, ?string &$errorMessage=null)
 Check if this pagebundle is valid.
 
 withHtml (string $html, array $fragments=[])
 Build an HtmlPageBundle by adding HTML string contents to this base page bundle.
 
 withDocument (Document $doc, array $fragments=[])
 Build an DomPageBundle by adding DOM contents to this base page bundle.
 
 toBasePageBundle ()
 Build a BasePageBundle with just the metadata from another page bundle.
 

Static Public Member Functions

static newEmpty (Document $doc, ?string $version=null, ?array $headers=null, ?string $contentmodel=null)
 
static fromHtmlPageBundle (HtmlPageBundle $pb)
 Create a DomPageBundle from a HtmlPageBundle.
 
static fromSingleDocument (Document $doc, array $options=[])
 Return a DomPageBundle from a "PageBundle as single Document" representation, where some page bundle information has been embedded as a <script> element into the <head> of the DOM.
 
static fromLoadedDocument (Document $doc, SiteConfig $siteConfig, array $options=[], array $fragments=[],)
 Create a new DomPageBundle from a "prepared and loaded" document.
 
static isSingleDocument (Document $doc)
 Return true iff the given Document has page bundle information embedded as a <script id="mw-pagebundle"> element in its <head>.
 
static newFromJsonArray (array $json)
 

Detailed Description

A page bundle stores an HTML DOM with separated data-parsoid and data-mw content.

The data-parsoid and data-mw content is indexed by the id attributes on individual nodes. This content needs to be loaded before the data-parsoid and/or data-mw information can be used.

Note that the parsoid/mw properties of the page bundle are in "serialized array" form; that is, they are flat arrays appropriate for json-encoding and do not contain DataParsoid or DataMw objects.

See HtmlPageBundle for a similar structure used where the HTML DOM has been serialized into a string.

Member Function Documentation

◆ fromHtmlPageBundle()

static Wikimedia\Parsoid\Core\DomPageBundle::fromHtmlPageBundle ( HtmlPageBundle $pb)
static

Create a DomPageBundle from a HtmlPageBundle.

This simply parses the HTML string from the HtmlPageBundle, preserving the metadata.

◆ fromLoadedDocument()

static Wikimedia\Parsoid\Core\DomPageBundle::fromLoadedDocument ( Document $doc,
SiteConfig $siteConfig,
array $options = [],
array $fragments = [] )
static

Create a new DomPageBundle from a "prepared and loaded" document.

If a pageBundle key is present in the options, the version/headers/contentmodel will be initialized from that page bundle.

Parameters
Document$docShould be "prepared and loaded"
SiteConfig$siteConfig
array$optionsstore options
array<string,DocumentFragment>$fragments
Returns
DomPageBundle

◆ fromSingleDocument()

static Wikimedia\Parsoid\Core\DomPageBundle::fromSingleDocument ( Document $doc,
array $options = [] )
static

Return a DomPageBundle from a "PageBundle as single Document" representation, where some page bundle information has been embedded as a <script> element into the <head> of the DOM.

See also
::toSingleDocument()
Parameters
Document$docdoc
array$optionsOptional content version/headers/contentmodel
Returns
DomPageBundle

◆ newFromJsonArray()

static Wikimedia\Parsoid\Core\DomPageBundle::newFromJsonArray ( array $json)
static

◆ toDom()

Wikimedia\Parsoid\Core\DomPageBundle::toDom ( bool $load = true,
?array $options = null,
?array & $fragments = null )

Return a DOM from the contents of this page bundle.

Note
Although technically the Document and DocumentFragments held by the DomPageBundle are the same as the Document and DocumentFragments returned from this method, the former are not directly usable (parsoid/mw attributes are not loaded or present in inline attributes) while the latter are. It is recommended that you treat the Document/DocumentFragment held by the DomPageBundle and the Document/DocumentFragment returned by this method as separate objects and consider the DomPageBundle "used up" and invalid once ::toDom() is called.
Parameters
bool$loadIf $load is true (the default), the returned DOM will be prepared and loaded using $options.

If $load is false, any data-parsoid or data-mw information from this page bundle will be converted to inline attributes in the DOM. This process is less efficient than preparing and loading the document directly from the DOM and should be avoided if possible.

Parameters
?array$optionsAdditional options to DOMDataUtils::visitAndLoadDataAttribs, used when $load is true.
?array<string,DocumentFragment>&$fragments Additional fragments present in the page bundle, which will also be loaded as necessary. This is an output parameter.

◆ toInlineAttributeDocument()

Wikimedia\Parsoid\Core\DomPageBundle::toInlineAttributeDocument ( SiteConfig $siteConfig,
array $options = [],
?array & $fragments = null )

Convert this DomPageBundle to "inline attribute" form, where page bundle information is represented as inline JSON-valued attributes.

Parameters
SiteConfig$siteConfig
array$optionsXHtmlSerializer options
array<string,DocumentFragment>|null&$fragments Additional fragments from the page bundle which will also be converted to "inline attribute" form. This is an output parameter.
Returns
Document a standalone document with page bundle information represented as inline JSON-valued attributes.

◆ toInlineAttributeHtml()

Wikimedia\Parsoid\Core\DomPageBundle::toInlineAttributeHtml ( SiteConfig $siteConfig,
array $options = [],
?array & $fragments = null )

Convert this DomPageBundle to "inline attribute" form, where page bundle information is represented as inline JSON-valued attributes.

Parameters
SiteConfig$siteConfig
array$optionsXHtmlSerializer options
array<string,string>|null&$fragments Additional fragments from the page bundle which will also be serialized to HTML strings. This is an output parameter.
Returns
string an HTML string

◆ toJsonArray()

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

◆ toSingleDocument()

Wikimedia\Parsoid\Core\DomPageBundle::toSingleDocument ( )

Create a "PageBundle as single Document" by embedding page bundle information into a <script> element in the <head> of the DOM.

See also
::fromSingleDocument()

◆ toSingleDocumentHtml()

Wikimedia\Parsoid\Core\DomPageBundle::toSingleDocumentHtml ( array $options = [])

Convert this DomPageBundle to "single document" form, where page bundle information is embedded in the <head> of the document.

Parameters
array$optionsXHtmlSerializer options
Returns
string an HTML string

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