Skip to content

Commit 633fcc8

Browse files
committed
use the more elegant [...].forEach() instead of the for-loop
1 parent d0da008 commit 633fcc8

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

js/math-code.js

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
(function() {
2-
var i, text, code, codes = document.getElementsByTagName('code');
3-
for (i = 0; i < codes.length;) {
4-
code = codes[i];
5-
if (code.parentNode.tagName !== 'PRE' && code.childElementCount === 0) {
6-
text = code.textContent;
7-
if (/^\$[^$]/.test(text) && /[^$]\$$/.test(text)) {
8-
text = text.replace(/^\$/, '\\(').replace(/\$$/, '\\)');
9-
code.textContent = text;
10-
}
11-
if (/^\\\((.|\s)+\\\)$/.test(text) || /^\\\[(.|\s)+\\\]$/.test(text) ||
12-
/^\$(.|\s)+\$$/.test(text) ||
13-
/^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) {
14-
code.outerHTML = code.innerHTML; // remove <code></code>
15-
continue;
16-
}
17-
}
18-
i++;
1+
[...document.getElementsByTagName('code')].forEach(code => {
2+
if (code.parentNode.tagName === 'PRE' || code.childElementCount > 0) return;
3+
const text = code.textContent;
4+
if (/^\$[^$]/.test(text) && /[^$]\$$/.test(text)) {
5+
text = text.replace(/^\$/, '\\(').replace(/\$$/, '\\)');
6+
code.textContent = text;
197
}
20-
})();
8+
if (/^\\\((.|\s)+\\\)$/.test(text) || /^\\\[(.|\s)+\\\]$/.test(text) ||
9+
/^\$(.|\s)+\$$/.test(text) ||
10+
/^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) {
11+
code.outerHTML = code.innerHTML; // remove <code></code>
12+
}
13+
});

0 commit comments

Comments
 (0)