-
Notifications
You must be signed in to change notification settings - Fork 4
/
use-highlight-element.html
63 lines (60 loc) · 2.64 KB
/
use-highlight-element.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.14.2/styles/solarized-dark.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/highlight.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/highlightjs-line-numbers.js@2.8.0/dist/highlightjs-line-numbers.min.js"></script>
<script src="./highlightjs-highlight-lines.js"></script>
<script>
var generateCodeWithoutNumbers = function(code) {
code.innerHTML = 'hljs.highlightElement(code);\nhljs.highlightLinesElement(code, [{start: 2, end: 2, color: \'yellow\'}], false); /* the last argument is `has_numbers` */';
hljs.highlightElement(code);
hljs.highlightLinesElement(code, [{start: 2, end: 2, color: 'yellow'}], false);
};
var generateCodeWithNumbers = function(code) {
code.innerHTML = 'hljs.highlightElement(code);\nhljs.lineNumbersBlock(code);\nhljs.highlightLinesElement(code, [{start: 3, end: 3, color: \'yellow\'}], true); /* the last argument is `has_numbers` */';
hljs.highlightElement(code);
hljs.lineNumbersBlock(code);
hljs.highlightLinesElement(code, [{start: 3, end: 3, color: 'yellow'}], true);
};
</script>
<style>
/* for block of numbers */
td.hljs-ln-numbers {
text-align: center;
color: #ccc;
border-right: 1px solid #999;
vertical-align: top;
padding-right: 5px;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
td.hljs-ln-code {
padding-left: 10px;
}
code {
white-space: pre-wrap;
overflow: auto;
}
</style>
</head>
<body>
<h1>highlightjs-highlight-lines.js Examples using hljs.highlightBlock</h1>
<h2>Example 1 (without numbers)</h2>
<input type="button" value="generate code!" onclick="generateCodeWithoutNumbers(document.getElementById('without-numbers'));"/>
<pre>
<code id="without-numbers"></code>
</pre>
<h2>Example 2 (with numbers)</h2>
<input type="button" value="generate code!" onclick="generateCodeWithNumbers(document.getElementById('with-numbers'));"/>
<pre>
<code id="with-numbers"></code>
</pre>
</body>
</html>