Parsoid
A bidirectional parser between wikitext and HTML5
Wikimedia\Parsoid\Parsoid Class Reference

Public Member Functions

 __construct (SiteConfig $siteConfig, DataAccess $dataAccess)
 
 wikitext2html (PageConfig $pageConfig, array $options=[], ?array &$headers=null)
 Parse the wikitext supplied in a PageConfig to HTML. More...
 
 wikitext2lint (PageConfig $pageConfig, array $options=[])
 Lint the wikitext supplied in a PageConfig. More...
 
 dom2wikitext (PageConfig $pageConfig, Document $doc, array $options=[], ?SelserData $selserData=null)
 Serialize DOM to wikitext. More...
 
 html2wikitext (PageConfig $pageConfig, string $html, array $options=[], ?SelserData $selserData=null)
 Serialize HTML to wikitext. More...
 
 pb2pb (PageConfig $pageConfig, string $update, PageBundle $pb, array $options=[])
 Update the supplied PageBundle based on the $update type. More...
 

Static Public Member Functions

static defaultHTMLVersion ()
 Returns the default HTML content version. More...
 
static resolveContentVersion (string $version)
 See if any content version Parsoid knows how to produce satisfies the the supplied version, when interpreted with semver caret semantics. More...
 
static supportsLanguageConversion ()
 Determine if language conversion is enabled, aka if the optional wikimedia/langconv library is installed. More...
 
static findDowngrade (string $from, string $to)
 Check whether a given content version can be downgraded to the requested content version. More...
 
static downgrade (array $dg, PageBundle $pageBundle)
 Downgrade a document to an older content version. More...
 

Public Attributes

const AVAILABLE_VERSIONS = [ '2.4.0', '999.0.0' ]
 Available HTML content versions. More...
 

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Parsoid\Parsoid::__construct ( SiteConfig  $siteConfig,
DataAccess  $dataAccess 
)
Parameters
SiteConfig$siteConfig
DataAccess$dataAccess

Member Function Documentation

◆ defaultHTMLVersion()

static Wikimedia\Parsoid\Parsoid::defaultHTMLVersion ( )
static

Returns the default HTML content version.

Returns
string

◆ dom2wikitext()

Wikimedia\Parsoid\Parsoid::dom2wikitext ( PageConfig  $pageConfig,
Document  $doc,
array  $options = [],
?SelserData  $selserData = null 
)

Serialize DOM to wikitext.

Parameters
PageConfig$pageConfig
Document$docData attributes are expected to have been applied already. Loading them will happen once the environment is created.
array$options[ 'scrubWikitext' => (bool) Indicates emit "clean" wikitext. 'inputContentVersion' => (string) The content version of the input. Necessary if it differs from the current default in order to account for any serialization differences. 'offsetType' => (string) ucs2, char, byte are valid values what kind of source offsets are present in the HTML? 'contentmodel' => (string|null) The content model of the input. 'htmlVariantLanguage' => (string) If non-null, the language variant used for Parsoid HTML. 'wtVariantLanguage' => (string) If non-null, the language variant used for wikitext. 'traceFlags' => (array) associative array with tracing options 'dumpFlags' => (array) associative array with dump options 'debugFlags' => (array) associative array with debug options 'logLevels' => (string[]) Levels to log 'htmlSize' => (int) Size of the HTML that generated $doc ]
?SelserData$selserData
Returns
string

◆ downgrade()

static Wikimedia\Parsoid\Parsoid::downgrade ( array  $dg,
PageBundle  $pageBundle 
)
static

Downgrade a document to an older content version.

Parameters
string[]$dgValue returned by findDowngrade().
PageBundle$pageBundle

◆ findDowngrade()

static Wikimedia\Parsoid\Parsoid::findDowngrade ( string  $from,
string  $to 
)
static

Check whether a given content version can be downgraded to the requested content version.

Parameters
string$fromCurrent content version
string$toRequested content version
Returns
string[]|null The downgrade that will fulfill the request, as [ 'from' => <old version>, 'to' => <new version> ], or null if it can't be fulfilled.

◆ html2wikitext()

Wikimedia\Parsoid\Parsoid::html2wikitext ( PageConfig  $pageConfig,
string  $html,
array  $options = [],
?SelserData  $selserData = null 
)

Serialize HTML to wikitext.

Convenience method for dom2wikitext.

Parameters
PageConfig$pageConfig
string$html
array$options
?SelserData$selserData
Returns
string

◆ pb2pb()

Wikimedia\Parsoid\Parsoid::pb2pb ( PageConfig  $pageConfig,
string  $update,
PageBundle  $pb,
array  $options = [] 
)

Update the supplied PageBundle based on the $update type.

'redlinks': Refreshes the classes of known, missing, etc. links. 'variant': Converts the HTML based on the supplied variant.

Note that these are DOM transforms, and not roundtrips through wikitext.

Parameters
PageConfig$pageConfig
string$update'redlinks'|'variant'
PageBundle$pb
array$options
Returns
PageBundle

◆ resolveContentVersion()

static Wikimedia\Parsoid\Parsoid::resolveContentVersion ( string  $version)
static

See if any content version Parsoid knows how to produce satisfies the the supplied version, when interpreted with semver caret semantics.

This will allow us to make backwards compatible changes, without the need for clients to bump the version in their headers all the time.

Parameters
string$version
Returns
string|null

◆ supportsLanguageConversion()

static Wikimedia\Parsoid\Parsoid::supportsLanguageConversion ( )
static

Determine if language conversion is enabled, aka if the optional wikimedia/langconv library is installed.

Returns
bool True if the wikimedia/langconv library is available

◆ wikitext2html()

Wikimedia\Parsoid\Parsoid::wikitext2html ( PageConfig  $pageConfig,
array  $options = [],
?array &  $headers = null 
)

Parse the wikitext supplied in a PageConfig to HTML.

Parameters
PageConfig$pageConfig
array$options[ 'wrapSections' => (bool) Whether <section> wrappers should be added. 'pageBundle' => (bool) Sets ids on nodes and stores data-* attributes in a JSON blob. 'body_only' => (bool|null) Only return the <body> children (T181657) 'outputContentVersion' => (string|null) Version of HTML to output. null returns the default version. 'contentmodel' => (string|null) The content model of the input. 'discardDataParsoid' => (bool) Drop all data-parsoid annotations. 'offsetType' => (string) ucs2, char, byte are valid values what kind of source offsets should be emitted? 'htmlVariantLanguage' => (string) If non-null, the language variant used for Parsoid HTML. 'wtVariantLanguage' => (string) If non-null, the language variant used for wikitext. 'logLinterData' => (bool) Should we log linter data if linting is enabled? 'traceFlags' => (array) associative array with tracing options 'dumpFlags' => (array) associative array with dump options 'debugFlags' => (array) associative array with debug options 'logLevels' => (string[]) Levels to log ]
?array&$headers
Returns
PageBundle|string

◆ wikitext2lint()

Wikimedia\Parsoid\Parsoid::wikitext2lint ( PageConfig  $pageConfig,
array  $options = [] 
)

Lint the wikitext supplied in a PageConfig.

Parameters
PageConfig$pageConfig
array$optionsSee wikitext2html.
Returns
array

Member Data Documentation

◆ AVAILABLE_VERSIONS

const Wikimedia\Parsoid\Parsoid::AVAILABLE_VERSIONS = [ '2.4.0', '999.0.0' ]

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