-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·51 lines (41 loc) · 1.26 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#! /usr/bin/env node
const markdownpdf = require('markdown-pdf');
const hljs = require('highlight.js');
const classy = require('remarkable-classy');
const path = require('path');
const fs = require('fs');
// setup default PDF options
const pdfOptions = {
cssPath: path.join(__dirname, 'main.css'),
paperBorder: '2cm',
runningsPath: path.join(__dirname, 'runnings.js'),
remarkable: {
html: true,
breaks: true,
plugins: [classy],
syntax: ['footnote', 'sup', 'sub'],
highlight: (str, lang) => {
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(lang, str).value;
} catch (err) {}
}
try {
return hljs.highlightAuto(str).value;
} catch (err) {}
return ''; // use external default escaping
}
}
};
// create a default config and read overrides from consumers package.json
const contents = fs.readFileSync(path.join(process.cwd(), 'package.json'));
const package = JSON.parse(contents.toString('utf8'));
const defaultConfig = {
file_in: 'input.md',
file_out: 'output.pdf'
};
const config = Object.assign(defaultConfig, package.coderdojo_workshop_options);
// convert markdown to pdf
markdownpdf(pdfOptions)
.from(config.file_in)
.to(config.file_out);