blob: a80ef88e53f2e7a4b5ce66fd654c446c147e6adb (
plain)
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
|
/* eslint-disable no-console */
const unified = require('unified');
const markdown = require('remark-parse');
const stringify = require('remark-stringify');
const fs = require('fs');
module.exports = function() {
const processor = unified()
.use(markdown, {commonmark: true})
.use(stringify);
const ast = processor.parse(fs.readFileSync('./CHANGELOG.md'));
const changelog = [];
changelog.push(processor.stringify(ast.children[0]));
// start at 1 so we get the first anchor tag
// and can break on the second
for (let i = 1; i < ast.children.length; i++) {
let item = processor.stringify(ast.children[i]);
if (/^<a name="/.test(item)) {
break;
}
if (/^###/.test(item)) {
item = '\n' + item + '\n';
}
changelog.push(item);
}
return changelog.join('\n');
};
|