laika.api

Transform

class Transform[W] 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:

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

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.

W

the writer API to use which varies depending on the renderer

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Transform
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. class DirectoryConfigBuilder extends AnyRef

    API for configuring a batch operation for a directory.

  2. class Operation extends AnyRef

    Represents a single transformation operation for a specific input that has already been parsed.

Value Members

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

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

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

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. def creatingRule(newRule: (DocumentContext) ⇒ PartialFunction[Element, Option[Element]]): Transform[W]

    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.

  9. final def eq(arg0: AnyRef): Boolean

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

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

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. def fromDirectory(dir: File)(implicit codec: Codec): DirectoryConfigBuilder

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

    Parses files from the specified directory and its subdirectories and returns a new builder 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)(implicit codec: Codec): DirectoryConfigBuilder

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

    Parses files from the specified directory and its subdirectories and returns a new builder 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.

  14. def fromFile(file: File)(implicit codec: Codec): Operation

    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.

  15. def fromFile(name: String)(implicit codec: Codec): Operation

    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.

  16. def fromReader(reader: Reader): Operation

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

  17. def fromStream(stream: InputStream)(implicit codec: Codec): Operation

    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.

  18. def fromString(str: String): Operation

    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.

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

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

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

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

    Definition Classes
    AnyRef
  23. final def notify(): Unit

    Definition Classes
    AnyRef
  24. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  25. def rendering(customRenderer: (W) ⇒ PartialFunction[Element, Unit]): Transform[W]

    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"
  26. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  27. def toString(): String

    Definition Classes
    AnyRef → Any
  28. def usingRule(newRule: PartialFunction[Element, Option[Element]]): Transform[W]

    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.

  29. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  32. def withConfig(config: BatchConfig): Unit

    Transforms documents according to the specified batch configuration.

    Transforms documents according to the specified batch configuration.

    config

    the configuration for the input and output trees to process

  33. def withConfig(builder: BatchConfigBuilder): Unit

    Transforms documents according to the specified batch configuration.

    Transforms documents according to the specified batch configuration.

    builder

    a builder for the configuration for the input and output trees to process

  34. def withDefaultDirectories(implicit codec: Codec): Unit

    Parses files from the source directory inside the current working directory and renders the result to the target directory inside the current working directory.

    Parses files from the source directory inside the current working directory and renders the result to the target directory inside the current working directory.

    codec

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

  35. def withRootDirectory(dir: File)(implicit codec: Codec): Unit

    Parses files from the source directory inside the specified root directory and renders the result to the target directory inside the root directory.

    Parses files from the source directory inside the specified root directory and renders the result to the target directory inside the root directory. Both directories must already exist inside the specified directory.

    dir

    the root directory that contains the source and target directory

    codec

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

  36. def withRootDirectory(name: String)(implicit codec: Codec): Unit

    Parses files from the source directory inside the specified root directory and renders the result to the target directory inside the root directory.

    Parses files from the source directory inside the specified root directory and renders the result to the target directory inside the root directory. Both directories must already exist inside the specified directory.

    name

    the name of the root directory that contains the source and target directory

    codec

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

Inherited from AnyRef

Inherited from Any

Ungrouped