import karax proc findNodeWith(x: Element; tag, content: cstring): Element = if x.nodeName == tag and x.textContent == content: return x for i in 0.. y: return 1 return 0 else: # ensure sorting is stable: return a.sortId - b.sortId ) for k in x.kids: let y = toHtml(k) if y != nil: ul.add tree("LI", y) if ul.len != 0: result.add ul if result.len == 0: result = nil proc containsWord(a, b: cstring): bool {.asmNoStackFrame.} = {.emit: """ var escaped = `b`.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); return new RegExp("\\b" + escaped + "\\b").test(`a`); """.} proc isWhitespace(text: cstring): bool {.asmNoStackFrame.} = {.emit: """ return !/[^\s]/.test(`text`); """.} proc isWhitespace(x: Element): bool = x.nodeName == "#text" and x.textContent.isWhitespace or x.nodeName == "#comment" proc toToc(x: Element; father: TocEntry) = if x.nodeName == "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": let e = TocEntry(heading: x[i][0], kids: @[], sortId: f.kids.len) let it = x[nxt] for j in 0..", "text/html"); `stuff` = doc.documentElement; """.} db = stuff.getElementsByClass"reference external" contents = @[] for ahref in db: contents.add ahref.textContent.normalize let ul = tree("UL") result = tree("DIV") result.setClass"search_results" var matches: seq[(Element, int)] = @[] let key = value.normalize for i in 0.. int: a[1] - b[1] for i in 0..min(