Skip to content

Instantly share code, notes, and snippets.

Created May 29, 2013 23:38
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
LeanPub Tool — Node.js script for sanitizing and compiling a book's manuscript. LeanPub uses multi-file book format and a special markdown markup (that confuses Marked app). I found that to convert to MS Word (for editing and other needs) this workflow is the best: 1. run leanpub-tool.js with node.js (node leanpub-tool.js) 2. open file in Marked…
var fs = require('fs');
//change these to YOUR filenames
//probably we can read it from Book.txt but I was too lazy to implement it :-) and somebody might want to compile only sertain parts of the book
var book =[
var sanitizeText = [
"I>## Note",
"T>## Tip",
"W>## Warning",
var str = '';
//read files
str += fs.readFileSync(chapter,'utf8');
//sanitize LeanPub specific Markdown tags
// console.log(text)
//this loops through while there is not matches
while (new RegExp (text).test(str)) {
str = str.replace(text,'','gm')
//write output to a file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment