Customizable and extensible toolkit for transforming lightweight text markup and template based site and e-book generation.
Supporting Markdown and reStructuredText as input and HTML, EPUB and PDF as output, either through its integrated sbt plugin or embedded in Scala applications, without the need to install external tools.
Open Source under the Apache 2.0 License.
The main artifact is published to Maven Central for Scala 2.13 and 2.12.
The sbt plugin is published to the sbt plugin repository for sbt 1.x.
The final release for Scala 2.11 had been 0.10.0, the final release for Scala 2.10 and sbt 0.13 was 0.7.0.
Using the sbt Plugin
Add the plugin to
addSbtPlugin("org.planet42" % "laika-sbt" % "0.12.0")
Enable the plugin in your project's
Add Markdown, reStructuredText or HTML template files to
src/docs in your
project and run the
laikaSite task from within sbt to generate the site
Using the Library API
If you are updating from a version before 0.12.0, it's recommended to read the Migration Guide first, as there were significant changes in the Library API.
Adding the Laika dependency to your sbt build:
libraryDependencies += "org.planet42" %% "laika-core" % "0.12.0"
Example for transforming Markdown to HTML:
import laika.api._ import laika.format._ val transformer = Transformer .from(Markdown) .to(HTML) .build val res: Either[ParserError, String] = transformer .transform("hello *there*")
For file/stream IO, parallel processing and/or EPUB support, based on cats-effect, add the laika-io module to your build:
libraryDependencies += "org.planet42" %% "laika-io" % "0.12.0"
Example for transforming an entire directory of markup files to a single EPUB file:
import laika.api._ import laika.format._ import laika.io.implicits._ implicit val cs: ContextShift[IO] = IO.contextShift(ExecutionContext.global) val blocker = Blocker.liftExecutionContext( ExecutionContext.fromExecutor(Executors.newCachedThreadPool()) ) val transformer = Transformer .from(Markdown) .to(EPUB) .using(GitHubFlavor) .io(blocker) .parallel[IO] .build val res: IO[Unit] = transformer .fromDirectory("src") .toFile("hello.epub") .transform
When using Laika's PDF support you need to add one more dependency to your build:
libraryDependencies += "org.planet42" %% "laika-pdf" % "0.12.0"
The example for how to transform a directory of input files into a PDF file looks
the same as the EPUB example, apart from swapping
For further information:
*Note that all licence references and agreements mentioned in the Laika README section above are relevant to that project's source code only.