mirror of
https://github.com/public-apis/public-apis.git
synced 2025-05-12 16:46:47 +02:00
Add Markdown condense script
This commit is contained in:
parent
5214187d8d
commit
1ed2e11c18
1 changed files with 61 additions and 0 deletions
61
build/condenseMd.js
Normal file
61
build/condenseMd.js
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
fs = require('fs')
|
||||||
|
|
||||||
|
function setupMd(filename, anchor) {
|
||||||
|
fs.readFile(filename, 'utf8', function (err,text) {
|
||||||
|
if (err) {
|
||||||
|
return console.log(err);
|
||||||
|
}
|
||||||
|
var lines = text.split("\n");
|
||||||
|
var cur_line = 0;
|
||||||
|
var line = ""
|
||||||
|
var table_name = "";
|
||||||
|
var col_num = 0;
|
||||||
|
var cols = [];
|
||||||
|
var rows = [];
|
||||||
|
|
||||||
|
function read_line() {
|
||||||
|
return lines[cur_line++];
|
||||||
|
}
|
||||||
|
var arr = [];
|
||||||
|
while (true) {
|
||||||
|
var cols = [];
|
||||||
|
var rows = [];
|
||||||
|
while (line.indexOf(anchor) == -1 && cur_line != lines.length) {
|
||||||
|
line = read_line();
|
||||||
|
}
|
||||||
|
if (cur_line == lines.length) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
table_name = line.split(anchor)[1];
|
||||||
|
read_line()
|
||||||
|
read_line()
|
||||||
|
while (true) {
|
||||||
|
line = read_line()
|
||||||
|
if (line.length < 2 || cur_line == lines.length) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if (line.startsWith("|")) {
|
||||||
|
arr.push(line + table_name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
console.log(anchor + " entries")
|
||||||
|
console.log("API | Description | Auth | HTTPS | Link | Section")
|
||||||
|
console.log("|---|---|---|---|---|---|")
|
||||||
|
for (i = 0; i < arr.length; i++) {
|
||||||
|
console.log(arr[i])
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.argv.length < 3) {
|
||||||
|
console.log("No .md file passed!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (process.argv.length < 4) {
|
||||||
|
anchorText = "###";
|
||||||
|
} else {
|
||||||
|
anchorText = process.argv[3];
|
||||||
|
}
|
||||||
|
setupMd(process.argv[2].toString(), anchorText);
|
Loading…
Add table
Add a link
Reference in a new issue