- Download Sonic Pi repo
- Add above to
/sonic-pi/etc/doc/tutorial
- Install pandoc, e.g.
brew install pandoc
- Run
node build.js
- Run
pandoc -o sonic-pi-tutorial.epub tutorial.md
Created
March 26, 2023 20:35
-
-
Save jamesporter/fc7902e481c32a12c3f310e762daaf73 to your computer and use it in GitHub Desktop.
Convert Sonic Pi Tutorial to epub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const path = require("path"); | |
const mds = fs.readdirSync("./").filter((f) => f.includes(".md")); | |
let contents = ` | |
--- | |
title: Sonic Pi Tutorial | |
author: Sam Aaron | |
... | |
`; | |
const titleRe = /^#{1,6}.*/; | |
mds.forEach((md) => { | |
const fileContents = String(fs.readFileSync(md)); | |
const processed = fileContents | |
.split("\n") | |
.map((line, i) => { | |
if (i === 0) { | |
return "# " + line; | |
} else if (titleRe.test(line)) { | |
return "#" + line; | |
} else { | |
return line; | |
} | |
}) | |
.join("\n"); | |
contents += processed; | |
contents += "\n\n"; | |
}); | |
fs.writeFileSync("tutorial.md", contents); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment