-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamend-generated-markdown-files.js
44 lines (37 loc) · 1.07 KB
/
amend-generated-markdown-files.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
#!/usr/bin/env node
const rs = require(`replacestream`)
const fs = require(`fs`)
const path = require(`path`)
const args = require(`minimist`)(process.argv.slice(2))
const {_} = args
const [rawSource] = _
const dir = (x) => path.join(__dirname, x)
const source = dir(rawSource)
const rules = {
// wrap the table of contents heading with a .toc div
openTOC: rs(
`### Table of Contents`,
`<div class="toc">\n<h3>Table of Contents</h3>`
),
// prepend the first title with the ending of the .toc div
closeTOC: rs(
`## $`,
`</div><!--end .toc-->\n\n## $`
),
// singular is preferable
thereIsOnlyOneExample: rs(`**Examples**`, `**Example**`)
}
const {values} = Object
const amendGeneratedMarkdownFiles = (stream, rulez) => values(rulez)
.reduce(
(ze, rule) => ze.pipe(rule),
stream
).pipe(
process.stdout
)
// fs.createReadStream(source)
// .pipe(rules.openTOC)
// .pipe(rules.closeTOC)
// .pipe(rules.thereIsOnlyOneExample) // zero spoons, though
// .pipe(process.stdout)
amendGeneratedMarkdownFiles(fs.createReadStream(source), rules)