-
Notifications
You must be signed in to change notification settings - Fork 5
/
parse.html
48 lines (42 loc) · 1.54 KB
/
parse.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
<div id=result>working</div>
<script type=module>
const site = `http://ward.dojo.fed.wiki/assets/pages/exports-from-opm/`
const file = `Modeling%20Learning%20System.html`
const text = await fetch(`${site}/${file}`).then(res => res.text())
const tree = [] // [{summary:string, details:[tree, ...]}]
// Build the Tree
const div = document.createElement('div')
div.innerHTML = text
let here = div.firstElementChild
while(here.innerText != 'OPL spec.') {
if (here.tagName == 'B') {
console.log(here.innerText)
tree.push({summary:here.innerText,details:[]})}
if (here.tagName == 'P') {
console.log(' ',here.innerText.slice(0,60))
tree[tree.length-1].details.push({summary:here.innerText.split(/ /)[0],details:statement(here.firstElementChild)})}
here = here.nextElementSibling
}
console.log(tree)
function statement(where) {
const branch = []
while(where) {
if (where.tagName == 'FONT') {
const color = where.getAttribute('color')
const text = where.innerText
branch.push({summary:`<font color=${color}>${text}</font>`})}
where = where.nextElementSibling}
return branch
}
// Print the Tree
window.result.innerHTML = tree
.map(B => details(B.summary, B.details
.map(P => details(P.summary,P.details
.map(FONT => `${FONT.summary}`)
.join("<br>")))
.join("")))
.join("")
function details(summary,details) {
return `<details><summary>${summary}</summary><div style="margin-left:1em;">${details}</div></details>`
}
</script>