-
Notifications
You must be signed in to change notification settings - Fork 1
/
Concept Map Text Version 0.2.html
164 lines (139 loc) · 6.51 KB
/
Concept Map Text Version 0.2.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<html>
<h3>Textual Concept Map</h3>
<b>Concept as node from // link type // node to<b><br><i>Refresh page when changed</i><br>
<textarea id="myTextarea" rows="21" cols="100">
Climate Change // is a // Force Of Nature
Force of Nature // affects // Climate Change
Nature // reacts to // Climate Change
Climate Change // is caused by // Natural Causes
Natural Causes // are a // Force of Nature
Climate Change // is caused by // Human Activities
Human Activities // such as // Population Increase
Human Activities // such as // Burning Fossil Fuels
Rising Sea Levels // are evidence for // Climate Change
Melting Ice Caps // are evidence for // Climate Change
Warming Oceans // are evidence for // Climate Change
Warming Oceans // impact // Animal Habitat
Climate Change // can be managed by // Changing Behavior
Climate Change // can be managed by // Environmental Policies
Environmental Policies // such as // Carbon Taxes
Environmental Policies // such as // Political Sanctions
Climate Change // should be further // Researched
Changing Behavior // such as // Recycling
Changing Behavior // will assist // Carbon Reduction
Carbon Reduction // will stop // Melting Ice Caps
Recycling // hinders // Carbon Reduction
</textarea>
<p>
<b>Generated Obsidian Markdown </b><i>cut and paste a new Obsidian Note</i><br>
<textarea id="resultTextarea" rows="20" cols="100">
</textarea>
<head>
<script>
// Main
var concepts = document.getElementById("myTextarea").value;
var lines = concepts.split("\n");
var output_lines = [];
nodes = [];
for (let index = 0; index < lines.length; index++) {
var line = lines[index];
if (line == "") continue;
var chunks = line.split(" // ");
nodeLine = "- $NODENAME";
linkLine = "> - $LINKTYPE [[#^$BLOCKREF|$NODENAME]]"
linkLine_unknown_node = "> - $LINKTYPE *$NODENAME*"
blockref = "^$NODENAMELOWERCASE"
if (chunks.length == 3) {
for (let j = 0; j < chunks.length; j++) {
if (j == 0) {nodeFrom = chunks[j];}
if (j == 1) {linkForward = chunks[j];}
if (j == 1) {linkBackward = chunks[j];}
if (j == 2) {nodeTo = chunks[j];}
if (j == 2) {
nodes.push(
{
"nodefrom":nodeFrom,
"link":linkForward,
"nodeto":nodeTo
}
);
// nodes.push(
// {
// "nodefrom":nodeTo,
// "link":linkForward,
// "nodeto":nodeFrom
// }
// );
}
}
}
}
// create node index
var nodenames=[];
for (let index = 0; index < nodes.length; index++) {
nodenames.push(nodes[index]["nodefrom"]);
//
}
let unique_nodenames = [...new Set(nodenames)];
nodes.sort((a,b) => (a.nodefrom > b.nodefrom) ? 1 : ((b.nodefrom > a.nodefrom) ? -1 : 0))
// process nodes for output
outputLines = ""
var first = true
var lastnodefrom = ""
for (let index = 0; index < nodes.length; index++) {
var nodeFrom = nodes[index]["nodefrom"].trim();
var linkType = nodes[index]["link"].trim();
var nodeTo = nodes[index]["nodeto"].trim();
var lastNodeFromLowercase = lastnodefrom.toLowerCase().replace(/ /g,"");
var nodeFromLowercase = nodeFrom.toLowerCase().replace(/ /g,"");
var nodeToLowercase = nodeTo.toLowerCase().replace(/ /g,"");
if (nodeFrom != lastnodefrom) {
if (first == true) {
first = false
} else {
outputLines += "\n"+blockref
.replace("$NODENAMELOWERCASE",lastNodeFromLowercase)
.replace(" ","")
+"\n\n";
}
outputLines += nodeLine
.replace("$NODENAME",nodeFrom)
+"\n";
if (nodenames.indexOf(nodeTo) == -1) {
outputLines += linkLine_unknown_node
.replace("$LINKTYPE",linkType)
.replace("$NODENAME",nodeTo)
.replace(" ","")
+"\n";
} else {
outputLines += linkLine
.replace("$LINKTYPE",linkType)
.replace("$BLOCKREF",nodeToLowercase)
.replace("$NODENAME",nodeTo)
.replace(" ","")+"\n";
}
}
if (nodeFrom == lastnodefrom) {
if (nodenames.indexOf(nodeTo) == -1) {
outputLines += linkLine_unknown_node
.replace("$LINKTYPE",linkType)
.replace("$NODENAME",nodeTo)
+"\n";
} else {
outputLines += linkLine
.replace("$LINKTYPE",linkType)
.replace("$BLOCKREF",nodeToLowercase)
.replace("$NODENAME",nodeTo)+"\n";
}
}
// if (index == nodes.length) {
// outputLines += "\n"+blockref.replace("$NODENAMELOWERCASE",nodeFromLowercase).replace(" ","")+"\n\n";
// }
lastnodefrom = nodeFrom
}
document.getElementById("resultTextarea").value = outputLines;
</script>
</head>
<body>
</body>
</html>