Parsoid
A bidirectional parser between wikitext and HTML5
|
A page bundle stores an HTML DOM with separated data-parsoid and data-mw content. More...
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 | |
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.
|
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.
Document | $doc | Should be "prepared and loaded" |
array | $options | store options |
|
static |
Create a DomPageBundle from a PageBundle.
This simply parses the HTML string from the PageBundle, preserving the metadata.
|
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.
Document | $doc | doc |
array | $options | Optional content version/headers/contentmodel |
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.
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.
array | $options | XMLSerializer options |
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.
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.
array | $options | XMLSerializer options |