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

 __construct (Document $doc, ?array $parsoid=null, ?array $mw=null, ?string $version=null, ?array $headers=null, ?string $contentmodel=null)
 
 toDom (bool $load=true, ?array $options=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.
 
 toInlineAttributeHtml (array $options=[])
 Convert this DomPageBundle to "inline attribute" form, where page bundle information is represented as inline JSON-valued attributes.
 
 toJsonArray ()
 

Static Public Member Functions

static fromPageBundle (PageBundle $pb)
 Create a DomPageBundle from a PageBundle.
 
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, array $options=[])
 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)
 

Public Attributes

Document $doc
 The document, as a DOM.
 
 $parsoid
 
 $mw
 
 $version
 
 $headers
 
 $contentmodel
 

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 PageBundle for a similar structure used where the HTML DOM has been serialized into a string.

Member Function Documentation

◆ fromLoadedDocument()

static Wikimedia\Parsoid\Core\DomPageBundle::fromLoadedDocument ( Document $doc,
array $options = [] )
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"
array$optionsstore options
Returns
DomPageBundle

◆ fromPageBundle()

static Wikimedia\Parsoid\Core\DomPageBundle::fromPageBundle ( PageBundle $pb)
static

Create a DomPageBundle from a PageBundle.

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

◆ 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

◆ toDom()

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

Return a DOM from the contents of this page bundle.

If $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.

◆ toInlineAttributeHtml()

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

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

Parameters
array$optionsXMLSerializer options
Returns
string an HTML string

◆ 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$optionsXMLSerializer options
Returns
string an HTML string

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