Skip to content

Commit 73cb2a3

Browse files
New highlighting ⁋ractice
1 parent 80bd627 commit 73cb2a3

File tree

5 files changed

+596
-11
lines changed

5 files changed

+596
-11
lines changed

newpoly.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ body{
5959
position:relative;
6060
padding:5px;
6161
}
62+
mark{
63+
border-radius:2px;
64+
padding:2px;
65+
background-color: rgba(91, 197, 219, 0.282);
66+
color:white;
67+
}
6268
.hv{
6369
padding:5px;
6470
font-family: sans-serif;

newpoly.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,23 @@ function getCookie(cname) {
2121
}
2222
// Underli holds all underlined vars (pre-cookie)
2323
let underli = []
24-
function underline(elem){
25-
if(elem.style.textDecoration == "underline"){
26-
elem.style.textDecoration = "none";
27-
underli.splice(underli.indexOf(elem),1)
28-
clean(underli,"arr")
29-
jsoSET(underli)
30-
}else{
31-
elem.style.textDecoration = "underline";
32-
underli.push(elem)
33-
clean(underli,"arr")
34-
jsoSET(underli)
24+
function underline(elem) {
25+
// Target the innerHTML of the button, not the button element
26+
if (elem.firstChild && elem.firstChild.tagName === "MARK") {
27+
// Unwrap the <mark>
28+
const mark = elem.firstChild;
29+
elem.innerHTML = mark.innerHTML;
30+
underli.splice(underli.indexOf(elem), 1);
31+
} else {
32+
// Wrap all inner content in <mark>
33+
elem.innerHTML = `<mark>${elem.innerHTML}</mark>`;
34+
underli.push(elem);
3535
}
36+
clean(underli, "arr");
37+
jsoSET(underli);
3638
}
39+
40+
3741
// send each line of a array to html (array, htmlElem)
3842
function clean(un,arr){
3943
let arra = document.getElementById(arr);

0 commit comments

Comments
 (0)