Skip to content

Commit

Permalink
Update Pandoc version
Browse files Browse the repository at this point in the history
- Pandoc and pandoc-crossref are latest
- Update some of the filters accordingly
- Update npm dependency
- Update CI to match
  • Loading branch information
noelwelsh committed Jan 22, 2024
1 parent 4f50d84 commit 5c8a3e7
Show file tree
Hide file tree
Showing 14 changed files with 712 additions and 696 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ jobs:
sudo initexmf --admin --set-config-value [MPM]AutoInstall=yes
- name: Setup Pandoc

run: |
curl -Ls https://github.com/jgm/pandoc/releases/download/2.17.1.1/pandoc-2.17.1.1-linux-amd64.tar.gz > /tmp/pandoc.tgz
curl -Ls https://github.com/jgm/pandoc/releases/download/3.1.11/pandoc-3.1.11-linux-amd64.tar.gz > /tmp/pandoc.tgz
tar zxvf /tmp/pandoc.tgz
mv pandoc-2.17.1.1/bin/pandoc /usr/local/bin/pandoc
mv pandoc-3.1.11/bin/pandoc /usr/local/bin/pandoc
curl -Ls https://github.com/lierdakil/pandoc-crossref/releases/download/v0.3.12.2a/pandoc-crossref-Linux.tar.xz > /tmp/pandoc-crossref.tgz
curl -Ls https://github.com/lierdakil/pandoc-crossref/releases/download/v0.3.17.0b/pandoc-crossref-Linux.tar.xz > /tmp/pandoc-crossref.tgz
tar xvf /tmp/pandoc-crossref.tgz
mv pandoc-crossref /usr/local/bin/pandoc-crossref
Expand Down
13 changes: 10 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,22 @@ lazy val epub = taskKey[Unit]("Build the ePub version of the book")
lazy val tex = taskKey[Unit]("Build the TeX debug build of the book")
lazy val json = taskKey[Unit]("Build the JSON AST debug build of the book")

pdf := {
val cmdLineOptions =
Def.sequential(pdfSetup, mdoc.toTask(""), pdfPandoc).value
lazy val pdfCmd = taskKey[Unit](
"Run pandoc without running mdoc to create the PDF version of the book"
)

pdfCmd := {
val cmdLineOptions = pdfPandoc.value
val cmd = s"pandoc $cmdLineOptions"
println(cmd)
streams.value.log.info(cmd)
cmd.!
}

pdf := {
Def.sequential(pdfSetup, mdoc.toTask(""), pdfCmd).value
}

html := {
val cmdLineOptions =
Def.sequential(htmlSetup, mdoc.toTask(""), htmlPandoc).value
Expand Down
34 changes: 17 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"uglifyify": "2.6.0",
"lessc": "^1.0.2",
"underscore": "1.7.0",
"pandoc-filter": "0.1.6",
"pandoc-filter": "2.2.0",
"coffeescript": "^2.5.1"
},
"author": "Noel Welsh and Dave Gurnell"
Expand Down
108 changes: 56 additions & 52 deletions project/Pandoc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ object PandocTarget {
}

object Pandoc {

/** Create the command-line options without `pandoc` command */
def commandLineOptions(
pages: List[String],
target: PandocTarget,
usePandocCrossref: Boolean = true,
usePandocInclude: Boolean = true,
filenameStem: String = "scala-with-cats",
pagesDir: String = "target/pages",
srcDir: String = "src",
distDir: String = "dist",
tocDepth: Int = 3
pages: List[String],
target: PandocTarget,
usePandocCrossref: Boolean = true,
usePandocInclude: Boolean = true,
filenameStem: String = "scala-with-cats",
pagesDir: String = "target/pages",
srcDir: String = "src",
distDir: String = "dist",
tocDepth: Int = 3
): String = {
import PandocTarget._

Expand All @@ -36,21 +37,21 @@ object Pandoc {
val template = target match {
case Pdf | Tex => Some(s"--template=${srcDir}/templates/template.tex")
case Html => Some(s"--template=${srcDir}/templates/template.html")
case Epub => Some(s"--template=${srcDir}/templates/template.epub.html")
case Json => None
case Epub => Some(s"--template=${srcDir}/templates/template.epub.html")
case Json => None
}

val filters = target match {
case Pdf | Tex | Json =>
List(
s"--filter=pandoc-crossref",
s"--filter=${srcDir}/filters/pdf/unwrap-code.js",
s"--filter=${srcDir}/filters/pdf/merge-code.js",
// s"--filter=${srcDir}/filters/pdf/merge-code.js",
s"--filter=${srcDir}/filters/pdf/callout.js",
s"--filter=${srcDir}/filters/pdf/columns.js",
s"--filter=${srcDir}/filters/pdf/solutions.js",
s"--lua-filter=${srcDir}/filters/pdf/vector-images.lua",
s"--filter=${srcDir}/filters/pdf/listings.js",
s"--filter=${srcDir}/filters/pdf/listings.js"
)
case Html =>
List(
Expand All @@ -59,15 +60,15 @@ object Pandoc {
s"--filter=${srcDir}/filters/html/merge-code.js",
s"--filter=${srcDir}/filters/html/tables.js",
s"--filter=${srcDir}/filters/html/solutions.js",
s"--lua-filter=${srcDir}/filters/html/vector-images.lua",
s"--lua-filter=${srcDir}/filters/html/vector-images.lua"
)
case Epub =>
List(
s"--filter=pandoc-crossref",
s"--filter=${srcDir}/filters/epub/unwrap-code.js",
s"--filter=${srcDir}/filters/epub/merge-code.js",
s"--filter=${srcDir}/filters/epub/solutions.js",
s"--lua-filter=${srcDir}/filters/epub/vector-images.lua",
s"--lua-filter=${srcDir}/filters/epub/vector-images.lua"
)
}

Expand All @@ -79,64 +80,67 @@ object Pandoc {
s"--include-before-body=${srcDir}/templates/cover-notes.tex",
s"--pdf-engine=xelatex"
)
case Html =>
case Html =>
List(
s"--toc-depth=${tocDepth}",
s"--include-before-body=${srcDir}/templates/cover-notes.html",
s"--include-before-body=${srcDir}/templates/cover-notes.html"
)
case Epub =>
case Epub =>
List(
s"--toc-depth=${tocDepth}",
s"--css=${srcDir}/temp/epub.css",
s"--epub-cover-image=${srcDir}/covers/epub-cover.png",
s"--include-before-body=${srcDir}/templates/cover-notes.html",
s"--include-before-body=${srcDir}/templates/cover-notes.html"
)
case Json =>
case Json =>
Nil
}

val metadata = target match {
case Pdf | Tex => List(s"${srcDir}/meta/metadata.yaml", s"${srcDir}/meta/pdf.yaml")
case Html => List(s"${srcDir}/meta/metadata.yaml", s"${srcDir}/meta/html.yaml")
case Epub => List(s"${srcDir}/meta/metadata.yaml", s"${srcDir}/meta/epub.yaml")
case Json => List(s"${srcDir}/meta/metadata.yaml")
case Pdf | Tex =>
List(s"${srcDir}/meta/metadata.yaml", s"${srcDir}/meta/pdf.yaml")
case Html =>
List(s"${srcDir}/meta/metadata.yaml", s"${srcDir}/meta/html.yaml")
case Epub =>
List(s"${srcDir}/meta/metadata.yaml", s"${srcDir}/meta/epub.yaml")
case Json => List(s"${srcDir}/meta/metadata.yaml")
}

val options =
List(
List(output),
template.toList,
List(
"--from=markdown+grid_tables+multiline_tables+fenced_code_blocks+fenced_code_attributes+yaml_metadata_block+implicit_figures+header_attributes+definition_lists+link_attributes",
s"--variable=lib-dir:${srcDir}",
),
filters,
List(
"--top-level-division=chapter",
"--number-sections",
"--table-of-contents",
"--highlight-style tango",
"--standalone",
"--self-contained",
),
extras,
metadata,
relPages,
).flatten
List(output),
template.toList,
List(
"--from=markdown+grid_tables+multiline_tables+fenced_code_blocks+fenced_code_attributes+yaml_metadata_block+implicit_figures+header_attributes+definition_lists+link_attributes",
s"--variable=lib-dir:${srcDir}"
),
filters,
List(
"--top-level-division=chapter",
"--number-sections",
"--table-of-contents",
"--highlight-style tango",
"--standalone",
"--self-contained"
),
extras,
metadata,
relPages
).flatten

options.mkString(" ")
}

def commandLine(
pages: List[String],
target: PandocTarget,
usePandocCrossref: Boolean = true,
usePandocInclude: Boolean = true,
filenameStem: String = "scala-with-cats",
pagesDir: String = "target/pages",
srcDir: String = "src",
distDir: String = "dist",
tocDepth: Int = 3
pages: List[String],
target: PandocTarget,
usePandocCrossref: Boolean = true,
usePandocInclude: Boolean = true,
filenameStem: String = "scala-with-cats",
pagesDir: String = "target/pages",
srcDir: String = "src",
distDir: String = "dist",
tocDepth: Int = 3
): String = {

s"pandoc ${commandLineOptions(pages, target, usePandocCrossref, usePandocInclude, filenameStem, pagesDir, srcDir, distDir, tocDepth)}"
Expand Down
4 changes: 3 additions & 1 deletion src/filters/common/merge-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function mergeAll(blocks, accum = []) {
}

function createFilter() {
return function (type, value, format, meta) {
return function ({t: type, c: value}, format, meta) {
switch (type) {
case "Pandoc": {
const [meta, blocks] = value;
Expand Down Expand Up @@ -100,6 +100,8 @@ function createFilter() {
const [blocks] = value;
return pandoc.TableCell(mergeAll(blocks));
}

default: return value;
}
};
}
Expand Down
6 changes: 4 additions & 2 deletions src/filters/common/solutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,11 @@ function createFilter() {

// Tree walkin' ----------------------------------

return function (type, value, format, meta) {
return function ({t: type, c: value}, format, meta) {
// Hacity hack. Don't generate links in print books:
const createLinks = !meta.blackandwhiteprintable;
const createLinks =
typeof meta.blackandwhiteprintable === "undefined" ||
!meta.blackandwhiteprintable;

switch (type) {
case "Link": {
Expand Down
2 changes: 1 addition & 1 deletion src/filters/common/unwrap-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function unindent(text) {
}

function createFilter() {
return function filter(type, value, format, meta) {
return function filter({t: type, c: value}, format, meta) {
if (type !== "CodeBlock") {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/filters/common/vector-images.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const pandoc = require("pandoc-filter");

function createFilter(extension) {
return function (type, value, format, meta) {
return function ({t: type, c: value}, format, meta) {
if (type === "Image") {
const [caption, inline, [filename, prefix]] = value;

Expand Down
2 changes: 1 addition & 1 deletion src/filters/pdf/callout.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const pandoc = require("pandoc-filter");

function action(type, value, format, meta) {
function action({t: type, c: value}, format, meta) {
if (type === "Div") {
const [[ident, classes, kvs], body] = value;

Expand Down
2 changes: 1 addition & 1 deletion src/filters/pdf/code-wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const _ = require("underscore");
const pandoc = require("pandoc-filter");

function action(type, value, format, meta) {
function action({t: type, c: value}, format, meta) {
switch (type) {
case "CodeBlock":
const [[ident, classes, kvs], body] = value;
Expand Down
2 changes: 1 addition & 1 deletion src/filters/pdf/columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const _ = require("underscore");
const pandoc = require("pandoc-filter");

function action(type, value, format, meta) {
function action({t: type, c: value}, format, meta) {
if (type === "Div") {
const [[ident, classes, kvs], body] = value;

Expand Down
2 changes: 1 addition & 1 deletion src/filters/pdf/listings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const _ = require("underscore");
const pandoc = require("pandoc-filter");

function action(type, value, format, meta) {
function action({t: type, c: value}, format, meta) {
if (type === "CodeBlock") {
const [[ident, classes, kvs], body] = value;

Expand Down
Loading

0 comments on commit 5c8a3e7

Please sign in to comment.