spandoc


License

License

GroupId

GroupId

com.davegurnell
ArtifactId

ArtifactId

spandoc_2.12
Last Version

Last Version

0.6.0
Release Date

Release Date

Type

Type

jar
Description

Description

spandoc
spandoc
Project URL

Project URL

https://github.com/davegurnell/spandoc
Project Organization

Project Organization

com.davegurnell
Source Code Management

Source Code Management

https://github.com/davegurnell/spandoc.git

Download spandoc_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/com.davegurnell/spandoc_2.12/ -->
<dependency>
    <groupId>com.davegurnell</groupId>
    <artifactId>spandoc_2.12</artifactId>
    <version>0.6.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.davegurnell/spandoc_2.12/
implementation 'com.davegurnell:spandoc_2.12:0.6.0'
// https://jarcasting.com/artifacts/com.davegurnell/spandoc_2.12/
implementation ("com.davegurnell:spandoc_2.12:0.6.0")
'com.davegurnell:spandoc_2.12:jar:0.6.0'
<dependency org="com.davegurnell" name="spandoc_2.12" rev="0.6.0">
  <artifact name="spandoc_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.davegurnell', module='spandoc_2.12', version='0.6.0')
)
libraryDependencies += "com.davegurnell" % "spandoc_2.12" % "0.6.0"
[com.davegurnell/spandoc_2.12 "0.6.0"]

Dependencies

compile (5)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.13
org.typelevel : cats-core_2.12 jar 2.6.1
io.circe : circe-core_2.12 jar 0.13.0
io.circe : circe-generic_2.12 jar 0.13.0
io.circe : circe-parser_2.12 jar 0.13.0

test (2)

Group / Artifact Type Version
com.davegurnell : unindent_2.12 jar 1.6.0
org.scalameta : munit_2.12 jar 0.7.26

Project Modules

There are no modules declared in this project.

Spandoc

Write Pandoc filters in Scala. Very early release. Still in development.

Copyright 2016 Dave Gurnell. Licensed Apache 2.

Scala 2.12 Scala 2.13

Requirements

Spandoc requires:

  • Pandoc (tested with Pandoc 2.9.1.1);
  • Ammonite (to create Spandoc shell scripts).

Getting Started

Use Spandoc in an Ammonite and use it with Pandoc's --filter parameter:

echo 'Lorem ipsum' | pandoc --to=html --filter=my-filter.sc
# <p>LOREM IPSUM</p>

Here's an example script:

// Filename: my-filter.sc
#!/usr/bin/env amm

interp.load.ivy("com.davegurnell" %% "spandoc" % "<<VERSION>>")

@
import spandoc._, ast._, transform._

// An AST transform that uppercases inline text:
val uppercase = TopDown.inline {
  case Str(str) => Str(str.toUpperCase)
}

// Run the transform on stdin, printing the result to stdout:
transformStdin(uppercase)

How to Create Transforms

A transform is simply a function of the following type:

import spandoc.ast.Pandoc

type TransformFunc = Pandoc => Pandoc

Spandoc provides some helper classes to assist in the creation of transforms:

  • spandoc.transform.Transform is a class that breaks the transform down into smaller components: Block nodes, Inline nodes, and so on;

  • spandoc.transform.BottomUp implements Block and Inline transforms in a bottom-up traversal order that processes every node in the AST;

  • spandoc.transform.TopDown implements Block and Inline transforms in a top-down traversal order that allows you to shortcut transformation of subtrees.

You can create simple transforms using the methods on the companion objects of BottomUp and TopDown (as in the example above), or you can extend either type to create a more complex transform:

object transform extends BottomUp[cats.Id] {
  override def blockTransform = {
    // Change all ordered lists to bulleted lists:
    case OrderedList(_, items) => BulletList(items)
  }

  override def inlineTransform - {
    // Uppercase all body text:
    case Str(str) => Str(str.toUpperCase)
  }
}

Transforms can be monadic, which is typically useful to thread a State monad through the AST. See the examples directory for use cases like this.

Versions

Version
0.6.0
0.4.0
0.2.0