-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpug.config.js
51 lines (46 loc) · 1.24 KB
/
pug.config.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
const emoji = require('node-emoji');
const { marked } = require('marked');
const { markedHighlight } = require('marked-highlight');
const Prism = require('prismjs');
const path = require('path');
const { name, version } = require('./package.json');
const renderer = new marked.Renderer();
const originalLink = renderer.link;
renderer.link = function link(token) {
let { href } = token;
if (/^(?!\/\/|\w+:)/.test(href)) {
const parts = path.parse(href);
const url = new URL(href, 'http://invalid/');
href = path.join(parts.dir, `${parts.name}.pug${url.hash}`);
}
token.href = href;
return originalLink.call(this, token);
};
marked.use(
markedHighlight({
highlight(code, lang) {
return Prism.highlight(code, Prism.languages[lang], lang);
},
}),
);
marked.use({
mangle: false,
headerIds: false,
});
module.exports = {
rootDir: 'examples/',
filters: {
highlight: (code) =>
Prism.highlight(code, Prism.languages.javascript, 'javascript'),
packageInclude: (text) =>
text.replace(/from '(..\/)+src';$/gm, `from '${name}';`),
markdown: (text) =>
marked(
text.replace(/:([\w\d_-]+):/g, (m, code) => emoji.get(code) || m),
{ renderer },
),
},
locals: {
version,
},
};