typelevel / Laika

Site and E-book Generator and Customizable Text Markup Transformer for sbt, Scala and Scala.js
https://typelevel.org/Laika/
Apache License 2.0
406 stars 44 forks source link

sbt plugin: add new laikaTreeProcessors setting #598

Closed jenshalm closed 3 months ago

jenshalm commented 3 months ago

Like #588, this PR closes a gap where functionality that was easy to access for API users required unnecessary boilerplate for plugin users (in this case the need to create a theme just to be able to apply a tree processor).

The new setting laikaTreeProcessors (empty by default) adds a new shortcut to define such a processor without wrapping it in a theme first.

Example for adding a document to the virtual tree for PDF documents only:

import cats.effect.IO
import laika.ast._
import laika.theme.TreeProcessorBuilder

def intro: Document = ??? // e.g. generated in-memory

val processor = TreeProcessorBuilder[IO].mapTree { tree =>
  tree.modifyTree(_.prependContent(intro))
}

laikaTreeProcessors += LaikaTreeProcessor(processor, OutputContext(PDF))

Needs to be merged after #588.