forked from Mermade/widdershins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapiblueprint.js
37 lines (36 loc) · 927 Bytes
/
apiblueprint.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
function convert(api, options, callback) {
api = api.split('\r').join('');
var lines = api.split('\n');
var title = '';
var metadata = [];
var index = 0;
while ((lines[index].indexOf(':')>=0) && (index<lines.length)) {
metadata.push('> '+lines[index]+'\n');
lines[index] = '';
index++;
}
while (!lines[index].startsWith('# ') && !lines[index].startsWith('==') && (index<lines.length)) {
index++;
}
if (lines[index].startsWith('# ')) {
title = lines[index];
}
else {
title = lines[index-1];
}
lines.splice(index+1, 0, ...metadata);
api = lines.join('\n');
lines = [];
api = '\n'+api+'\n';
api = '---\ntitle: '+(title.replace('# ',''))+'\n'+`language_tabs:
toc_footers: []
includes: []
search: true
highlight_theme: darkula
---
` + api;
callback(null, api);
}
module.exports = {
convert : convert
};