TwoPhaseTransformerBuilder

laika.api.builder.TwoPhaseTransformerBuilder

Builder API for Transformer instances.

Allows to add ExtensionBundles, to register AST rewrite rules, to override the renderer for specific elements and other options.

Type parameters

FMT

the formatter API to use which varies depending on the renderer

PP

the type of the post processor

Attributes

Source
TwoPhaseTransformerBuilder.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Type members

Types

The type of the operation being configured by this instance.

The type of the operation being configured by this instance.

Attributes

Source
TwoPhaseTransformerBuilder.scala

Value members

Concrete methods

Returns a new instance with the specified configuration.

Returns a new instance with the specified configuration.

This method discards any previously specified options. It is usually meant to be used when copying over the configuration from a fully configured object to an unconfigured one.

Attributes

Source
TwoPhaseTransformerBuilder.scala

Inherited methods

def buildingRules(newRules: RewriteRulesBuilder): ThisType

Specifies a rewrite rule to be applied to the document tree model between the parse and render operations.

Specifies a rewrite rule to be applied to the document tree model between the parse and render operations. This is identical to calling Document.rewrite directly, but if there is no need to otherwise access the document instance and just chain parse and render operations this hook is more convenient.

The difference of this method to the usingRules method is that it expects a function that takes a DocumentCursor instance and returns the rewrite rules. This way the full document can be queried before any rule is applied. This is necessary in cases where the rule (which gets applied node-by-node) depends on information from other nodes. An example from the built-in rewrite rules is the rule that resolves link references. To replace all link reference elements with actual link elements, the rewrite rule needs to know all LinkDefinitions the document tree contains.

For being able to perform inspection tasks like this, the rule is executed in a later phase than rules added via usingRules. This means that such a rule is not supposed to insert any link targets itself, as the processing for those has already happened when this rule is run.

The builder function returns an Either[ConfigError, RewriteRules] which allows for validation of document configuration before creating the rule.

The rules themselves are partial functions of type PartialFunction[T, RewriteRule[T]] where T is either Span, Block or TemplateSpan, the 3 main categories of element types that support rewriting.

If the partial function is not defined for a specific element or the rule returns a Retain action as a result the old block remains in the tree unchanged.

If it returns Remove then the element gets removed from the ast, if it returns Replace with a new element it will replace the old one.

The rewriting is performed bottom-up (depth-first), therefore any element container passed to the rule only contains children which have already been processed.

Attributes

Inherited from:
TransformerBuilderOps (hidden)
Source
TransformerBuilderOps.scala
def rendering(customRenderer: PartialFunction[(FMT, Element), String]): ThisType

Specifies a custom render function that overrides one or more of the default renderers for the output format this instance uses.

Specifies a custom render function that overrides one or more of the default renderers for the output format this instance uses.

This method expects a partial function that takes a formatter and the element to render. It will then be invoked for each element it is defined at.

Simple example for customizing the HTML output for emphasized text, adding a specific style class:

val transformer = Transformer.from(Markdown).to(HTML).rendering {
  case (fmt, Emphasized(content, opt)) => fmt.element("em", opt, content, "class" -> "big")
}.build

Attributes

Inherited from:
RendererBuilderOps (hidden)
Source
RendererBuilderOps.scala
def strict: ThisType

Turns strict mode on for the target parser, switching off any features not part of the original markup syntax.

Turns strict mode on for the target parser, switching off any features not part of the original markup syntax. This includes the registration of markup directives (custom tags) as well as configuration sections at the start of the document.

Attributes

Inherited from:
ParserBuilderOps (hidden)
Source
ParserBuilderOps.scala
def using(bundles: ExtensionBundle*): ThisType

Returns a new instance with the specified extension bundles installed.

Returns a new instance with the specified extension bundles installed. Features in the new bundles may override features in already installed bundles.

Bundles are usually provided by libraries (by Laika itself or a 3rd-party extension library) or as re-usable building blocks by application code.

Attributes

Inherited from:
CommonBuilderOps (hidden)
Source
CommonBuilderOps.scala
def usingBlockRule(rule: RewriteRule[Block]): ThisType

Specifies a single block rewrite rule to be applied to the document tree model between the parse and render operations.

Specifies a single block rewrite rule to be applied to the document tree model between the parse and render operations. This is identical to calling Document.rewrite directly, but if there is no need to otherwise access the document instance and just chain parse and render operations this hook is more convenient.

The rule is a type alias for a partial function of type PartialFunction[Block, RewriteRule[Block]].

If the partial function is not defined for a specific block or the rule returns a Retain action as a result the old block remains in the tree unchanged.

If it returns Remove then the block gets removed from the ast, if it returns Replace with a new block it will replace the old one.

The rewriting is performed bottom-up (depth-first), therefore any element container passed to the rule only contains children which have already been processed.

Attributes

Inherited from:
TransformerBuilderOps (hidden)
Source
TransformerBuilderOps.scala
def usingRules(newRules: RewriteRules): ThisType

Specifies rewrite rules to be applied to the document tree model between the parse and render operations.

Specifies rewrite rules to be applied to the document tree model between the parse and render operations. This is identical to calling Document.rewrite directly, but if there is no need to otherwise access the document instance and just chain parse and render operations this hook is more convenient.

The rules are partial functions of type PartialFunction[T, RewriteRule[T]] where T is either Span, Block or TemplateSpan, the 3 main categories of element types that support rewriting.

If the partial function is not defined for a specific element or the rule returns a Retain action as a result the old element remains in the tree unchanged.

If it returns Remove then the element gets removed from the ast, if it returns Replace with a new element it will replace the old one.

The rewriting is performed bottom-up (depth-first), therefore any element container passed to the rule only contains children which have already been processed.

Attributes

Inherited from:
TransformerBuilderOps (hidden)
Source
TransformerBuilderOps.scala
def usingSpanRule(rule: RewriteRule[Span]): ThisType

Specifies a single span rewrite rule to be applied to the document tree model between the parse and render operations.

Specifies a single span rewrite rule to be applied to the document tree model between the parse and render operations. This is identical to calling Document.rewrite directly, but if there is no need to otherwise access the document instance and just chain parse and render operations this hook is more convenient.

The rule is a type alias for a partial function of type PartialFunction[Span, RewriteRule[Span].

If the partial function is not defined for a specific span or the rule returns a Retain action as a result the old span remains in the tree unchanged.

If it returns Remove then the span gets removed from the ast, if it returns Replace with a new span it will replace the old one.

The rewriting is performed bottom-up (depth-first), therefore any element container passed to the rule only contains children which have already been processed.

Attributes

Inherited from:
TransformerBuilderOps (hidden)
Source
TransformerBuilderOps.scala

Specifies a single rewrite rule for template spans to be applied to the template tree model between the parse and render operations.

Specifies a single rewrite rule for template spans to be applied to the template tree model between the parse and render operations. This is identical to calling TemplateDocument.rewrite directly, but if there is no need to otherwise access the document instance and just chain parse and render operations this hook is more convenient.

The rule is a type alias for a partial function of type PartialFunction[TemplateSpan, RewriteRule[TemplateSpan].

If the partial function is not defined for a specific span or the rule returns a Retain action as a result the old span remains in the tree unchanged.

If it returns Remove then the span gets removed from the ast, if it returns Replace with a new span it will replace the old one.

The rewriting is performed bottom-up (depth-first), therefore any element container passed to the rule only contains children which have already been processed.

Attributes

Inherited from:
TransformerBuilderOps (hidden)
Source
TransformerBuilderOps.scala
def withCompactRendering: ThisType

Renders without any formatting (line breaks or indentation).

Renders without any formatting (line breaks or indentation). Useful when storing the output in a database for example.

Attributes

Inherited from:
RendererBuilderOps (hidden)
Source
RendererBuilderOps.scala
def withConfigValue[T : ConfigEncoder](key: Key, value: T): ThisType

Returns a new instance with the specified configuration value added.

Returns a new instance with the specified configuration value added.

The specified value with have higher precedence than any value with the same key registered by extension bundles, but lower precedence than any value with the same key specified in a configuration file for a directory or a configuration header in a markup document.

Attributes

Inherited from:
ParserBuilderOps (hidden)
Source
ParserBuilderOps.scala
def withConfigValue[T : ConfigEncoder](key: String, value: T): ThisType

Returns a new instance with the specified configuration value added.

Returns a new instance with the specified configuration value added.

The specified value with have higher precedence than any value with the same key registered by extension bundles, but lower precedence than any value with the same key specified in a configuration file for a directory or a configuration header in a markup document.

Attributes

Inherited from:
ParserBuilderOps (hidden)
Source
ParserBuilderOps.scala
def withConfigValue[T : DefaultKey](value: T): ThisType

Returns a new instance with the specified configuration value added.

Returns a new instance with the specified configuration value added.

The specified value with have higher precedence than any value with the same key registered by extension bundles, but lower precedence than any value with the same key specified in a configuration file for a directory or a configuration header in a markup document.

Attributes

Inherited from:
ParserBuilderOps (hidden)
Source
ParserBuilderOps.scala
def withMessageFilters(filters: MessageFilters): ThisType

Specifies the message filters to apply to the operation.

Specifies the message filters to apply to the operation.

By default operations fail on errors and do not render any messages (e.g. warnings) embedded in the AST. For visual debugging MessageFilters.forVisualDebugging can be used instead, where the transformation will always succeed (unless an error occurs that cannot be recovered from), and messages in the AST with level Info or higher will be rendered in the position they occurred.

Attributes

Inherited from:
RendererBuilderOps (hidden)
Source
RendererBuilderOps.scala
def withRawContent: ThisType

Enables all extensions that process raw content embedded into the host markup language.

Enables all extensions that process raw content embedded into the host markup language. These are disabled by default as Laika is designed to render to multiple output formats from a single input document. With raw content embedded the markup document is tied to a specific output format.

Attributes

Inherited from:
ParserBuilderOps (hidden)
Source
ParserBuilderOps.scala

Concrete fields

The current configuration for this instance.

The current configuration for this instance.

Attributes

Source
TwoPhaseTransformerBuilder.scala