summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2022-04-13 11:51:20 +0200
committerTom Smeding <tom@tomsmeding.com>2022-04-13 11:58:20 +0200
commit1e790de760e1921fc079f9609e370296fc1d94c4 (patch)
treeb22a6c43b31a07352da2eb7ad1a0e251b9b46bf3
parentbaabe0c348009ee32069d79ad1a0febeab17631e (diff)
unicode: Properly report unknown codepoints
-rw-r--r--modules/unicode/index.html37
-rw-r--r--modules/unicode/unicode.js6
2 files changed, 34 insertions, 9 deletions
diff --git a/modules/unicode/index.html b/modules/unicode/index.html
index 7b385ef..cb2beaa 100644
--- a/modules/unicode/index.html
+++ b/modules/unicode/index.html
@@ -18,6 +18,14 @@ body {
.invisible {
display: none;
}
+#notfound_container {
+ margin-top: 15px;
+}
+code {
+ background-color: #eee;
+ padding: 3px;
+ border-radius: 5px;
+}
</style>
<script>
function do_lookup(override) {
@@ -68,16 +76,25 @@ function handleResponse(json, input) {
index_container.classList.add("invisible");
}
- var keys = ["codepoints", "search"];
+ setTableRows("codepoints", json.codepoints);
+ setTableRows("search", json.search);
+
+ if (json.notfound.length > 0) {
+ document.getElementById("notfound_container").classList.remove("invisible");
+ document.getElementById("notfound").innerText = json.notfound;
+ } else {
+ document.getElementById("notfound_container").classList.add("invisible");
+ document.getElementById("notfound").innerText = "";
+ }
+}
- for (var i = 0; i < keys.length; i++) {
- document.getElementById(keys[i] + "_num").innerHTML = "(" + json[keys[i]].length + ")";
+function setTableRows(key, rows) {
+ document.getElementById(key + "_num").innerHTML = "(" + rows.length + ")";
- elem = document.getElementById(keys[i]);
- elem.innerHTML = "";
- for (var j = 0; j < json[keys[i]].length; j++) {
- elem.appendChild(makeCodepointDiv(json[keys[i]][j]));
- }
+ var elem = document.getElementById(key);
+ elem.innerHTML = "";
+ for (var j = 0; j < rows.length; j++) {
+ elem.appendChild(makeCodepointDiv(rows[j]));
}
}
@@ -122,6 +139,10 @@ window.addEventListener("load", function() {
<!-- <pre id="json"></pre><br> -->
+ <div id="notfound_container" class="invisible">
+ These were not found, perhaps the server needs to be update its unicode table? <code id="notfound"></code>
+ </div>
+
<div id="index_container" class="invisible">
<h3>Codepoint <span id="index_input"></span></h3>
<div id="index" class="table"></div>
diff --git a/modules/unicode/unicode.js b/modules/unicode/unicode.js
index 113ea83..ee83179 100644
--- a/modules/unicode/unicode.js
+++ b/modules/unicode/unicode.js
@@ -114,14 +114,18 @@ module.exports = function (app, io, moddir) {
app.get("/unicode/lookup/:query", (req, res) => {
const codepoints = [];
+ let notfound = "";
for (let codepoint of req.params.query) {
codepoint = codepoint.codePointAt(0);
- codepoints.push(lookupCode(codepoint));
+ const result = lookupCode(codepoint);
+ if (result != null) codepoints.push(result);
+ else notfound += String.fromCodePoint(codepoint);
}
res.json({
index: recogniseIndex(req.params.query) || undefined,
codepoints: codepoints,
+ notfound: notfound,
search: searchDescription(req.params.query),
});
});