Created
March 12, 2018 13:40
-
-
Save fujimura/09d4935a357d2da2932b20d4fd7aa47d to your computer and use it in GitHub Desktop.
markdown_to_html_slide_to_pdf.js
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 { execSync } = require("child_process"); | |
const path = require("path"); | |
const puppeteer = require("puppeteer"); | |
const htmlToPdf = async src => { | |
const browser = await puppeteer.launch(); | |
try { | |
const dest = `${path.basename(src)}.pdf`; | |
const page = await browser.newPage(); | |
await page.goto(`file://${src}`); | |
await page.pdf({ | |
path: dest, | |
width: 1024, | |
height: 768 | |
}); | |
return dest; | |
} finally { | |
browser.close() | |
} | |
}; | |
fs.watch("./", async (eventType, filename) => { | |
if (filename && path.extname(filename) == ".md") { | |
const f = `${path.basename(filename)}.html`; | |
console.log(eventType, filename, f); | |
execSync(`pandoc -t slidy -s ${filename} -o ${f}`); | |
const pdfPath = await htmlToPdf(path.resolve(f)); | |
execSync(`open ${pdfPath}`); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment