make dochack.nim compile again

This commit is contained in:
Araq
2018-08-14 00:09:46 +02:00
parent f91a181f58
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]) =
if x == nil: return
if x.nodeName == "A":
if x.nodeName == cstring"A":
items.add x
else:
for i in 0..<x.len:
@@ -99,19 +99,19 @@ proc isWhitespace(text: cstring): bool {.asmNoStackFrame.} =
""".}
proc isWhitespace(x: Element): bool =
x.nodeName == "#text" and x.textContent.isWhitespace or
x.nodeName == "#comment"
x.nodeName == cstring"#text" and x.textContent.isWhitespace or
x.nodeName == cstring"#comment"
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)
var i = 0
while i < x.len:
var nxt = i+1
while nxt < x.len and x[nxt].isWhitespace:
inc nxt
if nxt < x.len and x[i].nodeName == "LI" and x[i].len == 1 and
x[nxt].nodeName == "UL":
if nxt < x.len and x[i].nodeName == cstring"LI" and x[i].len == 1 and
x[nxt].nodeName == cstring"UL":
let e = TocEntry(heading: x[i][0], kids: @[], sortId: f.kids.len)
let it = x[nxt]
for j in 0..<it.len:
@@ -124,11 +124,11 @@ proc toToc(x: Element; father: TocEntry) =
father.kids.add f
elif isWhitespace(x):
discard
elif x.nodeName == "LI":
elif x.nodeName == cstring"LI":
var idx: seq[int] = @[]
for i in 0 ..< x.len:
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: @[],
sortId: father.kids.len)
let it = x[idx[1]]
@@ -147,9 +147,9 @@ proc tocul(x: Element): Element =
result = tree("UL")
for i in 0..<x.len:
let it = x[i]
if it.nodeName == "LI":
if it.nodeName == cstring"LI":
result.add it.clone
elif it.nodeName == "UL":
elif it.nodeName == cstring"UL":
result.add tocul(it)
proc getSection(toc: Element; name: cstring): Element =
@@ -223,7 +223,7 @@ proc groupBy*(value: cstring) {.exportc.} =
let ntoc = buildToc(tt, types, procs)
let x = toHtml(ntoc, isRoot=true)
alternative = tree("DIV", x)
if value == "type":
if value == cstring"type":
replaceById("tocRoot", alternative)
else:
replaceById("tocRoot", tree("DIV"))
@@ -236,7 +236,7 @@ var
template normalize(x: cstring): cstring = x.toLower.replace("_", "")
proc dosearch(value: cstring): Element =
if db.isNil:
if db.len == 0:
var stuff: Element
{.emit: """
var request = new XMLHttpRequest();
@@ -261,7 +261,7 @@ proc dosearch(value: cstring): Element =
var matches: seq[(Element, int)] = @[]
for i in 0..<db.len:
let c = contents[i]
if c == "Examples" or c == "PEG construction":
if c == cstring"Examples" or c == cstring"PEG construction":
# Some manual exclusions.
# Ideally these should be fixed in the index to be more
# descriptive of what they are.
@@ -288,7 +288,7 @@ proc search*() {.exportc.} =
proc wrapper() =
let elem = getElementById("searchInput")
let value = elem.value
if value != "":
if value.len != 0:
if oldtoc.isNil:
oldtoc = getElementById("tocRoot")
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: cstring): Element = cast[Element](document.createTextNode(s))
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")
appendChild(k, kid)
appendChild(parent, k)
@@ -260,7 +261,7 @@ proc table*(class="", kids: varargs[Element]): Element =
proc tr*(kids: varargs[Element]): Element =
result = tag("tr")
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
else:
result.add td(k)