From ad16ca0ca6c068403fd359bcf9729db75b8321ac Mon Sep 17 00:00:00 2001 From: tdro Date: Sun, 22 Jan 2023 12:41:29 -0500 Subject: static/js/fixedsearch: Add license link Defang the inner . Can refactor this later --- assets/js/index.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'assets/js/index.js') diff --git a/assets/js/index.js b/assets/js/index.js index 8927f21..bcb4509 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -454,6 +454,11 @@ }); } } + function escape(text) { + const escaped = document.createElement("textarea"); + escaped.textContent = text; + return escaped.innerHTML; + } function search(term, data, options) { const results = fuzzysort.go(term, data, options); let items = ""; @@ -461,17 +466,17 @@ let separator = "—"; if (term.length === 0) separator = ""; items = ` -
  • - ${term} ${separator} No Results Found -
  • - `; +
  • + ${escape(term)} ${separator} No Results Found +
  • + `; dropdown.removeAttribute("hidden"); container.setAttribute("data-focus", ""); } else { dropdown.removeAttribute("hidden"); for(const string in results.slice(0, 10)){ const title = results[string].obj.title; - let highlight = fuzzysort.highlight(fuzzysort.single(term, title), "", ""); + let highlight = fuzzysort.highlight(fuzzysort.single(escape(term), escape(title)), "", ""); if (highlight === null) { highlight = title; } @@ -479,7 +484,7 @@
  • ${highlight}
  • - `; + `; } } dropdown.innerHTML = items; -- cgit v1.2.3