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

State object for the wikitext serializers. More...

Public Member Functions

 __construct (WikitextSerializer $serializer, array $options=[])
 
 getEnv ()
 
 initMode (bool $selserMode)
 Initialize a few boolean flags based on serialization mode.
 
 appendSep (string $src)
 Appends the separator source to the separator src buffer.
 
 updateSep (Node $node)
 Cycle the state after processing a node.
 
 getOrigSrc (int $start, int $end)
 Extracts a subset of the page source bound by the supplied indices.
 
 updateModificationFlags (Node $node)
 Like it says on the tin.
 
 recoverTrimmedWhitespace (Node $node, bool $leading)
 Recovers and emits any trimmed whitespace for $node.
 
 emitChunk ( $res, Node $node)
 Pushes the chunk to the current line.
 
 serializeChildren (Node $node, ?callable $wtEscaper=null, ?Node $firstChild=null)
 Serialize the children of a DOM node, sharing the global serializer state.
 
 kickOffSerialize (Node $node, ?callable $wtEscaper=null)
 Abstracts some steps taken in serializeChildrenToString and serializeDOM
 
 serializeLinkChildrenToString (Node $node, ?callable $wtEscaper=null)
 Serialize children of a link to a string.
 
 serializeCaptionChildrenToString (Node $node, ?callable $wtEscaper=null)
 Serialize children of a caption to a string.
 
 serializeIndentPreChildrenToString (Node $node, ?callable $wtEscaper=null)
 Serialize children of an indent-pre to a string.
 
 openAnnotationRange (string $ann, bool $extended)
 Take notes of the open annotation ranges and whether they have been extended.
 
 closeAnnotationRange (string $ann)
 Removes the corresponding annotation range from the list of open ranges.
 

Public Attributes

 $sep
 
 $onSOL = true
 
 $atStartOfOutput = true
 
 $inLink = false
 
 $inCaption = false
 
 $inIndentPre = false
 
 $inHTMLPre = false
 
 $inPHPBlock = false
 
 $inAttribute = false
 
 $inInsertedContent
 
 $hasIndentPreNowikis = false
 
 $hasQuoteNowikis = false
 
 $hasSelfClosingNowikis = false
 
 $hasHeadingEscapes = false
 
 $wikiTableNesting = 0
 
 $wteHandlerStack = []
 
 $currLine
 
 $singleLineContext
 
 $redirectText = null
 
 $serializer
 
 $extApi
 
 $out = ''
 
 $useWhitespaceHeuristics
 
 $selserMode
 
 $prevNodeUnmodified
 
 $currNodeUnmodified
 
 $needsEscaping = false
 
 $protect
 
 $separators
 
 $currNode
 
 $openAnnotations
 
 $haveTrimmedWsDSR = false
 

Detailed Description

State object for the wikitext serializers.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Parsoid\Html2Wt\SerializerState::__construct ( WikitextSerializer $serializer,
array $options = [] )
Parameters
WikitextSerializer$serializer
array$optionsList of options for serialization:
  • onSOL: (bool)
  • inPHPBlock: (bool)
  • inAttribute: (bool)
  • protect: (string)
  • selserData: (SelserData)

Member Function Documentation

◆ appendSep()

Wikimedia\Parsoid\Html2Wt\SerializerState::appendSep ( string $src)

Appends the separator source to the separator src buffer.

Don't update $state->onSOL since this string hasn't been emitted yet. If content handlers change behavior based on whether this newline will be emitted or not, they should peek into this buffer (ex: see TDHandler and THHandler code).

Parameters
string$src

◆ closeAnnotationRange()

Wikimedia\Parsoid\Html2Wt\SerializerState::closeAnnotationRange ( string $ann)

Removes the corresponding annotation range from the list of open ranges.

Parameters
string$ann

◆ emitChunk()

Wikimedia\Parsoid\Html2Wt\SerializerState::emitChunk ( $res,
Node $node )

Pushes the chunk to the current line.

Parameters
ConstrainedText | string$res
Node$node

◆ getEnv()

Wikimedia\Parsoid\Html2Wt\SerializerState::getEnv ( )
Note
Porting note: this replaces direct access
Returns
Env

◆ getOrigSrc()

Wikimedia\Parsoid\Html2Wt\SerializerState::getOrigSrc ( int $start,
int $end )

Extracts a subset of the page source bound by the supplied indices.

Parameters
int$startStart offset, in bytes
int$endEnd offset, in bytes
Returns
string|null

◆ initMode()

Wikimedia\Parsoid\Html2Wt\SerializerState::initMode ( bool $selserMode)

Initialize a few boolean flags based on serialization mode.

FIXME: Ideally, this should be private. Requires shuffing around where SerializerState is constructed so that $selserMode is known at the time of construction. for use by WikitextSerializer only

Parameters
bool$selserModeAre we running selective serialization?

◆ kickOffSerialize()

Wikimedia\Parsoid\Html2Wt\SerializerState::kickOffSerialize ( Node $node,
?callable $wtEscaper = null )

Abstracts some steps taken in serializeChildrenToString and serializeDOM

Parameters
Element | DocumentFragment$node
?callable$wtEscaperSee serializeChildren()

◆ openAnnotationRange()

Wikimedia\Parsoid\Html2Wt\SerializerState::openAnnotationRange ( string $ann,
bool $extended )

Take notes of the open annotation ranges and whether they have been extended.

Parameters
string$ann
bool$extended

◆ recoverTrimmedWhitespace()

Wikimedia\Parsoid\Html2Wt\SerializerState::recoverTrimmedWhitespace ( Node $node,
bool $leading )

Recovers and emits any trimmed whitespace for $node.

Parameters
Node$node
bool$leadingif true, trimmed leading whitespace is emitted if false, trimmed railing whitespace is emitted
Returns
string|null

◆ serializeCaptionChildrenToString()

Wikimedia\Parsoid\Html2Wt\SerializerState::serializeCaptionChildrenToString ( Node $node,
?callable $wtEscaper = null )

Serialize children of a caption to a string.

Parameters
Element | DocumentFragment$node
?callable$wtEscaperSee serializeChildren()
Returns
string

◆ serializeChildren()

callable[] See link Wikimedia\Parsoid\Html2Wt\SerializerState::serializeChildren ( Node $node,
?callable $wtEscaper = null,
?Node $firstChild = null )

Serialize the children of a DOM node, sharing the global serializer state.

Stack of wikitext escaping handlers – these handlers are responsible for smart escaping when the surrounding wikitext context is known.

Typically called by a DOM-based handler to continue handling its children.

Parameters
Element | DocumentFragment$node
?callable$wtEscaper( $state, $text, $opts ) PORT-FIXME document better; should this be done via WikitextEscapeHandlers somehow?
?Node$firstChild

◆ serializeIndentPreChildrenToString()

Wikimedia\Parsoid\Html2Wt\SerializerState::serializeIndentPreChildrenToString ( Node $node,
?callable $wtEscaper = null )

Serialize children of an indent-pre to a string.

Parameters
Element | DocumentFragment$node
?callable$wtEscaperSee serializeChildren()
Returns
string

◆ serializeLinkChildrenToString()

Wikimedia\Parsoid\Html2Wt\SerializerState::serializeLinkChildrenToString ( Node $node,
?callable $wtEscaper = null )

Serialize children of a link to a string.

Parameters
Element | DocumentFragment$node
?callable$wtEscaperSee serializeChildren()
Returns
string

◆ updateModificationFlags()

Wikimedia\Parsoid\Html2Wt\SerializerState::updateModificationFlags ( Node $node)

Like it says on the tin.

Parameters
Node$node

◆ updateSep()

Wikimedia\Parsoid\Html2Wt\SerializerState::updateSep ( Node $node)

Cycle the state after processing a node.

Parameters
Node$node

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