Class/Object

laika.api

Transform

Related Docs: object Transform | package api

Permalink

abstract class Transform[Writer] extends AnyRef

API for performing a transformation operation from and to various types of input and output, combining a parse and render operation.

In cases where a parse or render operation should be performed separately, for example for manually processing the document tree model between these operations, the laika.api.Parse and laika.api.Render APIs should be used instead.

Example for transforming from Markdown to HTML using files for both input and output:

Transform from Markdown to HTML fromFile "hello.md" toFile "hello.html"

Example for transforming an entire directory and its subdirectories to HTML in a target directory:

Transform from Markdown to HTML fromDirectory "source" toDirectory "target"

Example for transforming an entire directory and its subdirectories to a single PDF file:

Transform from Markdown to PDF fromDirectory "source" toFile "hello.pdf"

Or for transforming a document fragment from a string to the PrettyPrint format for debugging purposes:

val input = "some *emphasized* text"

Transform from Markdown to PrettyPrint fromString input toString

res0: java.lang.String =
Document - Blocks: 1
. Paragraph - Spans: 3
. . Text - 'some '
. . Emphasized - Spans: 1
. . . Text - 'emphasized'
. . Text - ' text'

Apart from specifying input and output, the Transform API also allows to customize the operation in various ways. The usingRule and creatingRule methods allow to rewrite the document tree between the parse and render operations and the rendering method allows to customize the way certain types of elements are rendered.

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Transform
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract type DocTarget

    Permalink

    The type of the transformation target for a single input document.

  2. abstract type ThisType <: Transform[Writer]

    Permalink

    The concrete implementation of the abstract Transform type.

  3. abstract type TreeTarget

    Permalink

    The type of the transformation target for an entire tree of input documents.

Abstract Value Members

  1. abstract def creatingRule(newRule: (DocumentContext) ⇒ RewriteRule): ThisType

    Permalink

    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 usingRule method is that it expects a function that expects a Document instance and returns the rewrite rule. 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.

    The rule itself is a partial function that takes an Element and returns an Option[Element].

    If the function is not defined for a specific element the old element remains in the tree unchanged. If it returns None then the node gets removed from the tree, if it returns an element it will replace the old one. Of course the function may also return the old element.

    The rewriting is performed in a way that only branches of the tree that contain new or removed elements will be replaced. It is processed bottom-up, therefore any element container passed to the rule only contains children which have already been processed.

    In case multiple rewrite rules need to be applied it may be more efficient to first combine them with orElse.

  2. abstract def fromDocument(doc: Document): DocTarget

    Permalink

    Renders the specified document and returns a new target instance which allows to specify the output and other configuration options.

    Renders the specified document and returns a new target instance which allows to specify the output and other configuration options.

    Attributes
    protected[this]
  3. abstract def fromTree(inputBuilder: InputConfigBuilder): TreeTarget

    Permalink

    Parses from the specified input and returns a new target instance which allows to specify the output and other configuration options.

    Parses from the specified input and returns a new target instance which allows to specify the output and other configuration options.

    inputBuilder

    the input to transform

  4. abstract def rendering(customRenderer: (Writer) ⇒ RenderFunction): ThisType

    Permalink

    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 function that returns a partial function as the parameter. The outer function allows to capture the writer instance to write to and will only be invoked once. The partial function will then be invoked for each elememnt it is defined at.

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

    Transform from Markdown to HTML rendering { out =>
      { case Emphasized(content) => out << """<em class="big">""" << content << "</em>" }
    } fromFile "hello.md" toFile "hello.html"

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. def fromDirectories(roots: Seq[File], exclude: FileFilter)(implicit codec: Codec): TreeTarget

    Permalink

    Parses files from the specified directories and its subdirectories, merging them into a tree with a single root and returns a new target instance which allows to specify the output and other configuration options.

    Parses files from the specified directories and its subdirectories, merging them into a tree with a single root and returns a new target instance which allows to specify the output and other configuration options.

    roots

    the root directories to traverse

    exclude

    the files to exclude from processing

    codec

    the character encoding of the files, if not specified the platform default will be used.

  10. def fromDirectories(roots: Seq[File])(implicit codec: Codec): TreeTarget

    Permalink

    Parses files from the specified directories and its subdirectories, merging them into a tree with a single root and returns a new target instance which allows to specify the output and other configuration options.

    Parses files from the specified directories and its subdirectories, merging them into a tree with a single root and returns a new target instance which allows to specify the output and other configuration options.

    roots

    the root directories to traverse

    codec

    the character encoding of the files, if not specified the platform default will be used.

  11. def fromDirectory(dir: File, exclude: FileFilter)(implicit codec: Codec): TreeTarget

    Permalink

    Parses files from the specified directory and its subdirectories and returns a new target instance which allows to specify the output and other configuration options.

    Parses files from the specified directory and its subdirectories and returns a new target instance which allows to specify the output and other configuration options.

    dir

    the directory to traverse

    exclude

    the files to exclude from processing

    codec

    the character encoding of the files, if not specified the platform default will be used.

  12. def fromDirectory(dir: File)(implicit codec: Codec): TreeTarget

    Permalink

    Parses files from the specified directory and its subdirectories and returns a new target instance which allows to specify the output and other configuration options.

    Parses files from the specified directory and its subdirectories and returns a new target instance which allows to specify the output and other configuration options.

    dir

    the directory to traverse

    codec

    the character encoding of the files, if not specified the platform default will be used.

  13. def fromDirectory(name: String, exclude: FileFilter)(implicit codec: Codec): TreeTarget

    Permalink

    Parses files from the specified directory and its subdirectories and returns a new target instance which allows to specify the output and other configuration options.

    Parses files from the specified directory and its subdirectories and returns a new target instance which allows to specify the output and other configuration options.

    name

    the name of the directory to traverse

    exclude

    the files to exclude from processing

    codec

    the character encoding of the files, if not specified the platform default will be used.

  14. def fromDirectory(name: String)(implicit codec: Codec): TreeTarget

    Permalink

    Parses files from the specified directory and its subdirectories and returns a new target instance which allows to specify the output and other configuration options.

    Parses files from the specified directory and its subdirectories and returns a new target instance which allows to specify the output and other configuration options.

    name

    the name of the directory to traverse

    codec

    the character encoding of the files, if not specified the platform default will be used.

  15. def fromFile(file: File)(implicit codec: Codec): DocTarget

    Permalink

    Parses the specified file and returns a new Operation instance which allows to specify the output.

    Parses the specified file and returns a new Operation instance which allows to specify the output. Any kind of character input is valid, including empty files.

    file

    the file to read from

    codec

    the character encoding of the file, if not specified the platform default will be used.

  16. def fromFile(name: String)(implicit codec: Codec): DocTarget

    Permalink

    Parses the file with the specified name and returns a new Operation instance which allows to specify the output.

    Parses the file with the specified name and returns a new Operation instance which allows to specify the output. Any kind of character input is valid, including empty files.

    name

    the name of the file to parse

    codec

    the character encoding of the file, if not specified the platform default will be used.

  17. def fromReader(reader: Reader): DocTarget

    Permalink

    Parses the input from the specified reader and returns a new Operation instance which allows to specify the output.

  18. def fromStream(stream: InputStream)(implicit codec: Codec): DocTarget

    Permalink

    Parses the input from the specified stream and returns a new Operation instance which allows to specify the output.

    Parses the input from the specified stream and returns a new Operation instance which allows to specify the output.

    stream

    the stream to use as input for the parser

    codec

    the character encoding of the stream, if not specified the platform default will be used.

  19. def fromString(str: String): DocTarget

    Permalink

    Parses the specified string and returns a new Operation instance which allows to specify the output.

    Parses the specified string and returns a new Operation instance which allows to specify the output. Any kind of input is valid, including an empty string.

  20. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  21. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  22. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  23. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  24. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  25. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  26. def rewrite(tree: DocumentTree, rules: Rules): DocumentTree

    Permalink

    Rewrites the specified document tree, using the given rules.

    Rewrites the specified document tree, using the given rules.

    Attributes
    protected[this]
  27. def rewrite(doc: Document, rules: Rules): Document

    Permalink

    Rewrites the specified document, using the given rules.

    Rewrites the specified document, using the given rules.

    Attributes
    protected[this]
  28. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  29. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  30. def usingRule(newRule: RewriteRule): ThisType

    Permalink

    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 rule is a partial function that takes an Element and returns an Option[Element].

    If the function is not defined for a specific element the old element remains in the tree unchanged. If it returns None then the node gets removed from the tree, if it returns an element it will replace the old one. Of course the function may also return the old element.

    The rewriting is performed in a way that only branches of the tree that contain new or removed elements will be replaced. It is processed bottom-up, therefore any element container passed to the rule only contains children which have already been processed.

    In case multiple rewrite rules need to be applied it may be more efficient to first combine them with orElse.

  31. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  32. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  33. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped