mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-18 17:08:32 +00:00
fix doc search(escape HTML code) (#15433)
* use release version * fix doc search
This commit is contained in:
@@ -267,6 +267,19 @@ var
|
||||
|
||||
template normalize(x: cstring): cstring = x.toLower.replace("_", "")
|
||||
|
||||
proc escapeCString(x: var cstring) =
|
||||
var s = ""
|
||||
for c in x:
|
||||
case c
|
||||
of '&': s.add("&")
|
||||
of '<': s.add("<")
|
||||
of '>': s.add(">")
|
||||
of '"': s.add(""")
|
||||
of '\'': s.add("'")
|
||||
of '/': s.add("/")
|
||||
else: s.add(c)
|
||||
x = s.cstring
|
||||
|
||||
proc dosearch(value: cstring): Element =
|
||||
if db.len == 0:
|
||||
var stuff: Element
|
||||
@@ -305,6 +318,7 @@ proc dosearch(value: cstring): Element =
|
||||
matches.sort(proc(a, b: auto): int = b[1] - a[1])
|
||||
for i in 0 ..< min(matches.len, 29):
|
||||
matches[i][0].innerHTML = matches[i][0].getAttribute("data-doc-search-tag")
|
||||
escapeCString(matches[i][0].innerHTML)
|
||||
ul.add(tree("LI", cast[Element](matches[i][0])))
|
||||
if ul.len == 0:
|
||||
result.add tree("B", text"no search results")
|
||||
|
||||
Reference in New Issue
Block a user