-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdataToMD.js
78 lines (70 loc) · 1.93 KB
/
dataToMD.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function initialIsCapital(word) {
return word[0] !== word[0].toLowerCase();
}
var listone = [];
for (let item of $("tbody").children) {
if (item.firstChild.innerHTML !== '<a target="text" href="../format.html#col-num">№</a>') {
listone.push(item);
}
}
var listtwo = [];
for (let item of listone) {
listtwo.push(item.cells);
}
var listthree = [];
for (let item of listtwo) {
let ginger = [];
for (let elem of item) {
if (elem.innerText !== "" && elem.innerText !== "—") {
ginger.push(elem.innerText);
}
}
listthree.push(ginger);
}
var result = JSON.stringify(listthree);
var result = JSON.parse(result);
var bigMD = "";
var flag = false;
var index = "";
for (let arr of result) {
// is a title
if (arr.length === 1) {
// is a subtitle
if (!initialIsCapital(arr[0])) {
arr[0] = arr[0].replace(" & ", "-and-");
bigMD += "\n#### " + arr[0] + "\n";
index += " * [" + arr[0] + "](#" + arr[0] + ")\n";
}
else {
arr[0] = arr[0].replace(" & ", "-and-");
bigMD += "\n## " + arr[0];
index += "* [" + arr[0] + "](#" + arr[0] + ")\n";
}
flag = true;
}
// is an element
else {
// first element of a table
if (flag) {
flag = false;
bigMD += "\n\n| Number | Code | Emoji | CLDR Short Name |\n" + "|:---|:---:|:---:|---:|\n";
}
// is a new element
if (arr.length === 5) {
arr.splice(3, 1);
}
bigMD += "| ";
for (var i = 0; i < arr.length; i += 1) {
if (i === 3) {
arr[i] = arr[i].replace("⊛ ", "");
bigMD += "`:" + arr[i] + ":` |\n";
}
else {
bigMD += arr[i] + " | ";
}
}
}
}
bigMD = index + "<br><br><br>" + bigMD;
// print .md code in console
console.log(bigMD);