make dochack.nim compile again

This commit is contained in:
Araq 2018-08-14 00:09:46 +02:00
commit 741f95e2d6
2 changed files with 17 additions and 16 deletions

View file

@ -28,7 +28,7 @@ proc parentWith(x: Element; tag: cstring): Element =
proc extractItems(x: Element; items: var seq[Element]) = proc extractItems(x: Element; items: var seq[Element]) =
if x == nil: return if x == nil: return
if x.nodeName == "A": if x.nodeName == cstring"A":
items.add x items.add x
else: else:
for i in 0..<x.len: for i in 0..<x.len:
@ -99,19 +99,19 @@ proc isWhitespace(text: cstring): bool {.asmNoStackFrame.} =
""".} """.}
proc isWhitespace(x: Element): bool = proc isWhitespace(x: Element): bool =
x.nodeName == "#text" and x.textContent.isWhitespace or x.nodeName == cstring"#text" and x.textContent.isWhitespace or
x.nodeName == "#comment" x.nodeName == cstring"#comment"
proc toToc(x: Element; father: TocEntry) = proc toToc(x: Element; father: TocEntry) =
if x.nodeName == "UL": if x.nodeName == cstring"UL":
let f = TocEntry(heading: nil, kids: @[], sortId: father.kids.len) let f = TocEntry(heading: nil, kids: @[], sortId: father.kids.len)
var i = 0 var i = 0
while i < x.len: while i < x.len:
var nxt = i+1 var nxt = i+1
while nxt < x.len and x[nxt].isWhitespace: while nxt < x.len and x[nxt].isWhitespace:
inc nxt inc nxt
if nxt < x.len and x[i].nodeName == "LI" and x[i].len == 1 and if nxt < x.len and x[i].nodeName == cstring"LI" and x[i].len == 1 and
x[nxt].nodeName == "UL": x[nxt].nodeName == cstring"UL":
let e = TocEntry(heading: x[i][0], kids: @[], sortId: f.kids.len) let e = TocEntry(heading: x[i][0], kids: @[], sortId: f.kids.len)
let it = x[nxt] let it = x[nxt]
for j in 0..<it.len: for j in 0..<it.len:
@ -124,11 +124,11 @@ proc toToc(x: Element; father: TocEntry) =
father.kids.add f father.kids.add f
elif isWhitespace(x): elif isWhitespace(x):
discard discard
elif x.nodeName == "LI": elif x.nodeName == cstring"LI":
var idx: seq[int] = @[] var idx: seq[int] = @[]
for i in 0 ..< x.len: for i in 0 ..< x.len:
if not x[i].isWhitespace: idx.add i if not x[i].isWhitespace: idx.add i
if idx.len == 2 and x[idx[1]].nodeName == "UL": if idx.len == 2 and x[idx[1]].nodeName == cstring"UL":
let e = TocEntry(heading: x[idx[0]], kids: @[], let e = TocEntry(heading: x[idx[0]], kids: @[],
sortId: father.kids.len) sortId: father.kids.len)
let it = x[idx[1]] let it = x[idx[1]]
@ -147,9 +147,9 @@ proc tocul(x: Element): Element =
result = tree("UL") result = tree("UL")
for i in 0..<x.len: for i in 0..<x.len:
let it = x[i] let it = x[i]
if it.nodeName == "LI": if it.nodeName == cstring"LI":
result.add it.clone result.add it.clone
elif it.nodeName == "UL": elif it.nodeName == cstring"UL":
result.add tocul(it) result.add tocul(it)
proc getSection(toc: Element; name: cstring): Element = proc getSection(toc: Element; name: cstring): Element =
@ -223,7 +223,7 @@ proc groupBy*(value: cstring) {.exportc.} =
let ntoc = buildToc(tt, types, procs) let ntoc = buildToc(tt, types, procs)
let x = toHtml(ntoc, isRoot=true) let x = toHtml(ntoc, isRoot=true)
alternative = tree("DIV", x) alternative = tree("DIV", x)
if value == "type": if value == cstring"type":
replaceById("tocRoot", alternative) replaceById("tocRoot", alternative)
else: else:
replaceById("tocRoot", tree("DIV")) replaceById("tocRoot", tree("DIV"))
@ -236,7 +236,7 @@ var
template normalize(x: cstring): cstring = x.toLower.replace("_", "") template normalize(x: cstring): cstring = x.toLower.replace("_", "")
proc dosearch(value: cstring): Element = proc dosearch(value: cstring): Element =
if db.isNil: if db.len == 0:
var stuff: Element var stuff: Element
{.emit: """ {.emit: """
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
@ -261,7 +261,7 @@ proc dosearch(value: cstring): Element =
var matches: seq[(Element, int)] = @[] var matches: seq[(Element, int)] = @[]
for i in 0..<db.len: for i in 0..<db.len:
let c = contents[i] let c = contents[i]
if c == "Examples" or c == "PEG construction": if c == cstring"Examples" or c == cstring"PEG construction":
# Some manual exclusions. # Some manual exclusions.
# Ideally these should be fixed in the index to be more # Ideally these should be fixed in the index to be more
# descriptive of what they are. # descriptive of what they are.
@ -288,7 +288,7 @@ proc search*() {.exportc.} =
proc wrapper() = proc wrapper() =
let elem = getElementById("searchInput") let elem = getElementById("searchInput")
let value = elem.value let value = elem.value
if value != "": if value.len != 0:
if oldtoc.isNil: if oldtoc.isNil:
oldtoc = getElementById("tocRoot") oldtoc = getElementById("tocRoot")
let results = dosearch(value) let results = dosearch(value)

View file

@ -112,7 +112,8 @@ proc tree*(tag: string; attrs: openarray[(string, string)];
proc text*(s: string): Element = cast[Element](document.createTextNode(s)) proc text*(s: string): Element = cast[Element](document.createTextNode(s))
proc text*(s: cstring): Element = cast[Element](document.createTextNode(s)) proc text*(s: cstring): Element = cast[Element](document.createTextNode(s))
proc add*(parent, kid: Element) = proc add*(parent, kid: Element) =
if parent.nodeName == "TR" and (kid.nodeName == "TD" or kid.nodeName == "TH"): if parent.nodeName == cstring"TR" and (
kid.nodeName == cstring"TD" or kid.nodeName == cstring"TH"):
let k = document.createElement("TD") let k = document.createElement("TD")
appendChild(k, kid) appendChild(k, kid)
appendChild(parent, k) appendChild(parent, k)
@ -260,7 +261,7 @@ proc table*(class="", kids: varargs[Element]): Element =
proc tr*(kids: varargs[Element]): Element = proc tr*(kids: varargs[Element]): Element =
result = tag("tr") result = tag("tr")
for k in kids: for k in kids:
if k.nodeName == "TD" or k.nodeName == "TH": if k.nodeName == cstring"TD" or k.nodeName == cstring"TH":
result.add k result.add k
else: else:
result.add td(k) result.add td(k)