-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathmarkdown-magic.config.js
47 lines (44 loc) · 1.51 KB
/
markdown-magic.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
'use strict';
/**
* Add autogenerated stuff to our docs (`docs/index.md`)
* @see https://npm.im/markdown-magic
* @private
* @module
*/
const {execSync} = require('child_process');
const markdownToc = require('markdown-toc');
const path = require('path');
exports.transforms = {
usage: (content, options) => {
const {executable} = options;
const flag = options.flag || '--help';
const header = options.header || '\n```plain';
const footer = options.footer || '```\n';
const output = String(
execSync(`${process.execPath} ${executable} ${flag} -C`, {
cwd: path.join(__dirname, '..')
})
).trim();
return [header, output, footer].join('\n\n');
},
// we can't use the builtin `TOC` plugin in markdown-magic
// because it's simply not flexible enough; we can't pad with newlines,
// nor can we provide a custom filter. the custom filter would be required
// since the `TOC` plugin supplies its own which means we can't use the
// `maxdepth` option, which we need!
toc: (content, options, config) => {
const IGNORED_HEADINGS_REGEXP = /Features|Table of Contents/i;
return (
'\n' +
markdownToc(config.outputContent, {
bullets: options.bullets,
firsth1: false,
// if filter is supplied, maxdepth is apparently ignored,
// so we have to do it ourselves.
filter: (str, ele) => ele.lvl < 2 && !IGNORED_HEADINGS_REGEXP.test(str)
}).content +
'\n'
);
},
manifest: require('markdown-magic-package-json')
};