PluginProbe
Highlighting Code Block / 1.2.4
Highlighting Code Block v1.2.4
2.2.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.4.0 All 41 releases
highlighting-code-block / src / js / hcb_script.js

hcb_script.js in Highlighting Code Block 1.2.4, at src/js/hcb_script.js

39 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 document.addEventListener('DOMContentLoaded', function () {
2 // Token customize
3 const keyToken = document.querySelectorAll('.token.keyword');
4 for (let i = 0; i < keyToken.length; i++) {
5 const elem = keyToken[i];
6
7 const defArr = ['function', 'def', 'class'];
8 if (-1 !== defArr.indexOf(elem.textContent)) {
9 elem.classList.add('def');
10 } else if ('this' === elem.textContent) {
11 elem.classList.add('this');
12 }
13 }
14
15 // Line highlighter position.
16 const lineHighlighter = document.querySelectorAll('.line-highlight');
17 for (let i = 0; i < lineHighlighter.length; i++) {
18 const elem = lineHighlighter[i];
19 if (!elem.parentNode.classList.contains('line-numbers')) {
20 const dataStart = elem.getAttribute('data-start');
21
22 const topPosEm = (dataStart - 1) * 1.5; //line-heightの値
23
24 // Line highlighterの位置がずれるので桁数に応じて微調節 -> ずれなくなった?
25 // if (5 < dataStart) {
26 // topPosEm = topPosEm - dataStart * 0.02;
27 // }
28 // if (10 < dataStart) {
29 // topPosEm = topPosEm - dataStart * 0.01;
30 // }
31 // if (20 < dataStart) {
32 // topPosEm = topPosEm - dataStart * 0.001;
33 // }
34
35 elem.style.top = topPosEm + 'em';
36 }
37 }
38 });
39