Skip to content

Commit

Permalink
⟦lexicon.html⟧: Adding function ⟦with_escaped_html⟧ for escaping poss…
Browse files Browse the repository at this point in the history
…ible HTML code in lexicon fields; refactoring a bit the table generation code to reduce redundancy.
  • Loading branch information
Ntsekees committed Nov 30, 2023
1 parent d1b4156 commit f96661f
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lexicon.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@
<br /><br />
<div id="content">(LEXICON NOT YET LOADED!)</div>
<script type="text/javascript">
function with_escaped_html(text) {
return text.replace(/[&<>"']/g, function(ch) {
switch (ch) {
case '&': return '&amp;';
case '<': return '&lt;';
case '>': return '&gt;';
case '"': return '&quot;';
default: return '&#039;';
/* '&apos;' in another option in HTML5, but is absent from
HTML4. */
}
});
}
function compare(a, b) {
if(a === "") {
return 1;
Expand All @@ -66,14 +79,11 @@
});
s = "";
lexicon.forEach((e, i, l) => {
s += "<tr>\n";
s += "<td>" + e.morpheme + "</td>\n";
s += "<td>" + e.type + "</td>\n";
s += "<td>" + e.subtype + "</td>\n";
s += "<td>" + e.eng + "</td>\n";
s += "<td>" + e.tags + "</td>\n";
s += "<td>" + e.predilex_id + "</td>\n";
s += "</tr>\n";
entries = [
e.morpheme, e.type, e.subtype, e.eng, e.tags, e.predilex_id];
entries = entries.map(
ε => "<td>" + with_escaped_html(ε) + "</td>\n");
s += "<tr>\n" + entries.join("") + "</tr>\n";
});
content =
"<table cellspacing='2px'>\n<thead>\n<td>Morpheme</td>" +
Expand Down

0 comments on commit f96661f

Please sign in to comment.