Class: AsyncTokenTransformManager

wt2html/TokenTransformManager~AsyncTokenTransformManager()

Asynchronous and potentially out-of-order token transformations, used in phase 2.

Return protocol for individual transforms:

    { tokens: [tokens], async: true }: async expansion -> outstanding++ in parent
    { tokens: [tokens] }: fully expanded, tokens will be reprocessed

Constructor

new AsyncTokenTransformManager()

...

Extends

Methods

addListenersOn(tokenEmitter)

Register to a token source, normally the tokenizer.

Register to a token source, normally the tokenizer. The event emitter emits a 'chunk' event with a chunk of tokens, and signals the end of tokens by triggering the 'end' event. XXX: Perform registration directly in the constructor?

Parameters:
Name Type Description
tokenEmitter EventEmitter

Token event emitter.

Inherited From:
Source:

addTransform(transformation, debugName, rank, type, name)

Add a transform registration.

Add a transform registration.

Parameters:
Name Type Description
transformation function
Properties
Name Type Description
token Token
frame Object
cb function
Properties
Name Type Description
result Object
Properties
Name Type Description
tokens Array.<Token>
return Object
Properties
Name Type Description
tokens Array.<Token>
debugName string

Debug string to identify the transformer in a trace.

rank number

A number in [0,3) with:

  • [0,1) in-order on input token stream,
  • [1,2) out-of-order and
  • [2,3) in-order on output token stream.
type string

One of 'tag', 'text', 'newline', 'comment', 'end', 'martian' (unknown token), 'any' (any token, matched before other matches).

name string

Tag name for tags, omitted for non-tags

Inherited From:
Source:

process()

Simple wrapper that processes all tokens passed in.

Simple wrapper that processes all tokens passed in.

Source:

removeTransform(rank, type, name)

Remove a transform registration.

Remove a transform registration.

Parameters:
Name Type Description
rank number

A number in [0,3) with:

  • [0,1) in-order on input token stream,
  • [1,2) out-of-order and
  • [2,3) in-order on output token stream.
type string

One of 'tag', 'text', 'newline', 'comment', 'end', 'martian' (unknown token), 'any' (any token, matched before other matches).

name string

Tag name for tags, omitted for non-tags.

Inherited From:
Source:

reset()

Reset state between uses.

Reset state between uses.

Source:

setFrame(parentFrame, title)

Reset the internal token and outstanding-callback state of the TokenTransformManager, but keep registrations untouched.

Reset the internal token and outstanding-callback state of the TokenTransformManager, but keep registrations untouched.

Parameters:
Name Type Description
parentFrame Frame
title string | null
Source:

setPipelineId()

Debugging aid: set pipeline id

.

Debugging aid: set pipeline id

Source:

transformTokens(tokens, parentCB) → {Object|Array|TokenAccumulator|null}

Run asynchronous transformations.

Run asynchronous transformations. This is the big workhorse where templates, images, links and other async expansions (see the transform recipe parser.js) are processed.

The returned chunk is fully expanded for this phase, and the rank set to reflect this.

Parameters:
Name Type Description
tokens Array

Chunk of tokens, potentially with rank and other meta information associated with it.

parentCB function

Callback for asynchronous results.

Source:
Returns: