-
Notifications
You must be signed in to change notification settings - Fork 2
/
jsonConvertAlignText.html
62 lines (53 loc) · 1.48 KB
/
jsonConvertAlignText.html
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
<!DOCTYPE html>
<!--
Created using JS Bin
http://jsbin.com
Copyright (c) 2017 by anonymous (http://jsbin.com/dojaremuni/1/edit)
Released under the MIT license: http://jsbin.mit-license.org
-->
<meta name="robots" content="noindex">
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<textarea id="source" name="" id="" cols="30" rows="10">[]</textarea>
<p id="convert">convert</p>
<p id="json">
</p>
<script id="jsbin-javascript">
let convertJSON = function(){
let importJSON = JSON.parse(document.querySelector("#source").value)
let i,j,k;
let parent,line,children;
let currentWord;
let exportJSON = []
for(i=0;i<importJSON.length;i++){
//for each text
parent=i;
children=0;
exportJSON.push([]);
for(j=0;j<importJSON[i].length;j++){
//for each line, TODO TEST FOR EMPTY LINE
exportJSON[i].push([]);
for(k=0;k<importJSON[i][j].length;k++){
currentWord = importJSON[i][j][k];
// if(currentWord.t){
currentWord.parent = parent;
children++;
currentWord.children = children
currentWord.pos = "["+(parent+1)+"]["+children+"]";
// }
exportJSON[i][j].push(currentWord);
}
}
}
document.querySelector("#json").innerHTML = JSON.stringify(exportJSON);
}
document.querySelector("#convert").addEventListener("click", convertJSON);
//convertJSON();
</script>
</body>
</html>