Skip to content

Commit

Permalink
Hide words in angle brackets (fixes #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
haukex committed Jul 14, 2024
1 parent ef07a9a commit 02ee08d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
color: var(--text-light);
/*font-weight: lighter;*/
}
.hidden {
display: none;
}
#search_term {
width: 100%;
}
Expand Down
6 changes: 6 additions & 0 deletions src/js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ async function loadDict() :Promise<string[]> {
}
}

// we want to display annotations like `{f}` or `[comp.]` in different formatting
const annotationRe = /\{[^}]+\}|\[[^\]]+\]/g
// words in angle brackets are common misspellings or other cross-references that should be hidden from view
const hideRe = /&lt;.+?&gt;/g

// when the HTML page has finished loading:
window.addEventListener('DOMContentLoaded', async () => {
Expand Down Expand Up @@ -250,12 +253,15 @@ window.addEventListener('DOMContentLoaded', async () => {
td0.innerHTML = td0.innerHTML.replaceAll(whatRe, '<strong>$&</strong>')
// and apply special formatting to annotations:
.replaceAll(annotationRe, '<span class="annotation">$&</span>')
// and certain words should not be displayed at all:
.replaceAll(hideRe, '<span class="hidden">$&</span>')
tr.appendChild(td0)
// right <td>, English
const td1 = document.createElement('td')
td1.innerText = en.trim()
td1.innerHTML = td1.innerHTML.replaceAll(whatRe, '<strong>$&</strong>')
.replaceAll(annotationRe, '<span class="annotation">$&</span>')
.replaceAll(hideRe, '<span class="hidden">$&</span>')
// the "feedback" button on each result
if (!i && ENABLE_FEEDBACK) {
const fbIcon = document.createElement('div')
Expand Down

0 comments on commit 02ee08d

Please sign in to comment.