-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhighlight.html
More file actions
65 lines (64 loc) · 1.83 KB
/
highlight.html
File metadata and controls
65 lines (64 loc) · 1.83 KB
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
64
65
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Highlight API</title>
</head>
<style>
:root {
background-color: #546E7A;
font-size: larger;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
padding: 1em;
}
::highlight(s-keyword) {
color: #ffd740;
}
::highlight(s-variables) {
color: white;
}
::highlight(s-value) {
color: #FF8A80;
}
::highlight(s-operator) {
color: #40C4FF;
}
</style>
</style>
<body>
<div id="answer">const answer = 42</div>
<script>
const container = document.getElementById("answer").childNodes[0];
const rangeKeyword = new StaticRange({
startContainer: container,
startOffset: 0,
endContainer: container,
endOffset: 5,
});
const rangeVariables = new StaticRange({
startContainer: container,
startOffset: 6,
endContainer: container,
endOffset: 12,
});
const rangeOperator = new StaticRange({
startContainer: container,
startOffset: 13,
endContainer: container,
endOffset: 14,
});
const rangeValue = new StaticRange({
startContainer: container,
startOffset: 15,
endContainer: container,
endOffset: 17,
});
CSS.highlights.set("s-keyword", new Highlight(rangeKeyword));
CSS.highlights.set("s-variables", new Highlight(rangeVariables));
CSS.highlights.set("s-operator", new Highlight(rangeOperator));
CSS.highlights.set("s-value", new Highlight(rangeValue));
</script>
</body>
</html>