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

A Parsoid extension module may register handlers for one or more extension tags. More...

+ Inheritance diagram for Wikimedia\Parsoid\Ext\ExtensionTagHandler:

Public Member Functions

 sourceToDom (ParsoidExtensionAPI $extApi, string $src, array $extArgs)
 Convert an extension tag's content to DOM.
 
 processAttributeEmbeddedHTML (ParsoidExtensionAPI $extApi, Element $elt, Closure $proc)
 Extensions might embed HTML in attributes in their own custom representation (whether in data-mw or elsewhere).
 
 lintHandler (ParsoidExtensionAPI $extApi, Element $rootNode, callable $defaultHandler)
 Lint handler for this extension.
 
 domToWikitext (ParsoidExtensionAPI $extApi, Element $node, bool $wrapperUnmodified)
 Serialize a DOM node created by this extension to wikitext.
 
 diffHandler (ParsoidExtensionAPI $extApi, callable $domDiff, Element $origNode, Element $editedNode)
 XXX: Experimental.
 

Detailed Description

A Parsoid extension module may register handlers for one or more extension tags.

The only method which is generally required by all extension tags is sourceToDom (but Translate doesn't even implement that). All other methods have default do-nothing implementations; override them iff you wish to implement those features. Default implementations consistently return false to indicate not-implemented (in some cases null would be a valid return value, and in other cases null would be a likely "accidental" return value which we'd like to catch and flag).

Member Function Documentation

◆ diffHandler()

Wikimedia\Parsoid\Ext\ExtensionTagHandler::diffHandler ( ParsoidExtensionAPI $extApi,
callable $domDiff,
Element $origNode,
Element $editedNode )

XXX: Experimental.

Call $domDiff on corresponding substrees of $origNode and $editedNode

Parameters
ParsoidExtensionAPI$extApi
callable$domDiff
Element$origNode
Element$editedNode
Returns
bool

Reimplemented in Wikimedia\Parsoid\Ext\Gallery\Gallery.

◆ domToWikitext()

Wikimedia\Parsoid\Ext\ExtensionTagHandler::domToWikitext ( ParsoidExtensionAPI $extApi,
Element $node,
bool $wrapperUnmodified )

Serialize a DOM node created by this extension to wikitext.

Parameters
ParsoidExtensionAPI$extApi
Element$node
bool$wrapperUnmodified
Returns
string|false Return false to use the default serialization.

Reimplemented in Wikimedia\Parsoid\Ext\Gallery\Gallery, Wikimedia\Parsoid\Ext\LST\LST, Wikimedia\Parsoid\Ext\Nowiki\Nowiki, and Wikimedia\Parsoid\ParserTests\ParserHook.

◆ lintHandler()

Wikimedia\Parsoid\Ext\ExtensionTagHandler::lintHandler ( ParsoidExtensionAPI $extApi,
Element $rootNode,
callable $defaultHandler )

Lint handler for this extension.

If the extension has lints it wants to expose, it should use $extApi to register those lints. Alternatively, the extension might simply inspect its DOM and invoke the default lint handler on a DOM tree that it wants inspected. For example, <ref> nodes often only have a pointer (the id attribute) to its content, and its lint handler would look up the DOM tree and invoke the default lint handler on that tree.

Parameters
ParsoidExtensionAPI$extApi
Element$rootNodeExtension content's root node
callable$defaultHandlerDefault lint handler
  • Default lint handler has signature $defaultHandler( Element $elt ): void
Returns
bool Return false to indicate that this extension has no special lint handler (the default lint handler will be used. Return true to indicate linting should proceed with the next sibling.

◆ processAttributeEmbeddedHTML()

Wikimedia\Parsoid\Ext\ExtensionTagHandler::processAttributeEmbeddedHTML ( ParsoidExtensionAPI $extApi,
Element $elt,
Closure $proc )

Extensions might embed HTML in attributes in their own custom representation (whether in data-mw or elsewhere).

Core Parsoid will need a way to traverse such content. This method is a way for extension tag handlers to provide this functionality. Parsoid will only call this method if the tag's config sets the options['wt2html']['embedsHTMLInAttributes'] property to true.

Parameters
ParsoidExtensionAPI$extApi
Element$eltThe node whose data attributes need to be examined
Closure$procThe processor that will process the embedded HTML Signature: (string) -> string This processor will be provided the HTML string as input and is expected to return a possibly modified string.

Reimplemented in Wikimedia\Parsoid\Ext\Indicator\Indicator, and Wikimedia\Parsoid\ParserTests\ParserHook.

◆ sourceToDom()

Wikimedia\Parsoid\Ext\ExtensionTagHandler::sourceToDom ( ParsoidExtensionAPI $extApi,
string $src,
array $extArgs )

Convert an extension tag's content to DOM.

Parameters
ParsoidExtensionAPI$extApi
string$srcExtension tag content
array$extArgsExtension tag arguments The extension tag arguments should be treated as opaque objects and any necessary inspection should be handled through the API.
Returns
DocumentFragment|false|null DocumentFragment if returning some parsed content false to fallback to the default handler for the content null to drop the instance completely

Reimplemented in Wikimedia\Parsoid\Ext\Gallery\Gallery, Wikimedia\Parsoid\Ext\Indicator\Indicator, Wikimedia\Parsoid\ParserTests\I18nTag, Wikimedia\Parsoid\ParserTests\ParserHook, Wikimedia\Parsoid\ParserTests\RawHTML, Wikimedia\Parsoid\ParserTests\StyleTag, Wikimedia\Parsoid\Ext\Nowiki\Nowiki, and Wikimedia\Parsoid\Ext\Pre\Pre.


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