-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (30 loc) · 889 Bytes
/
index.js
File metadata and controls
35 lines (30 loc) · 889 Bytes
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
'use strict';
const fs = require('fs');
const path = require('path');
const pug = require('pug');
const MarkdownIt = require('markdown-it');
const hljs = require('highlight.js');
module.exports = (markdown, config = {}) => {
const title = config.title || '';
const template = config.template || path.resolve(__dirname, './template.pug');
const markdownIt = new MarkdownIt({
langPrefix: 'hljs ',
highlight: (string, lang) => {
try {
if (lang) {
return hljs.highlight(lang, string).value;
}
return hljs.highlightAuto(string).value;
} catch (err) {
console.error(err);
}
return '';
}
});
return pug.renderFile(template, {
pretty: true,
title,
content: markdownIt.render(markdown),
flattenedDeps: fs.existsSync(path.join(__dirname, '..', 'primer-css', 'build', 'build.css'))
});
};