-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathhtml_editor.lua
70 lines (60 loc) · 1.77 KB
/
html_editor.lua
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
66
67
68
69
70
Description="Theme tokens highlight"
Categories = {"html"}
function themeUpdate()
if (HL_OUTPUT == HL_FORMAT_HTML or HL_OUTPUT == HL_FORMAT_XHTML) then
Injections[#Injections+1]=".hl { transition: box-shadow .2s; }"
Injections[#Injections+1]=".highlight { box-shadow: 0 0 0 2pt Highlight; }"
end
end
function syntaxUpdate(desc)
if (HL_OUTPUT ~= HL_FORMAT_HTML and HL_OUTPUT ~= HL_FORMAT_XHTML) then
return
end
HeaderInjection=[=[
<script type="text/javascript">
/* <![CDATA[ */
function highlight(q, state) {
unhighlight();
const matches = document.querySelectorAll(q);
matches.forEach(function(userItem) {
if (state) {
userItem.classList.add("highlight");
} else {
userItem.classList.remove("highlight");
}
});
}
function unhighlight() {
document.querySelectorAll(".highlight").forEach(function(userItem) {
userItem.classList.remove("highlight");
});
}
function handleClick(event) {
for (let value of event.target.classList.values()) {
if (value == "hl" || value == "highlight") {
continue;
}
console.log(value);
window.webkit.messageHandlers.nativeProcess.postMessage({name: "select-theme-token", "token-class": value});
break;
}
}
document.addEventListener("DOMContentLoaded", function() {
console.log("JS ready");
window.webkit.messageHandlers.nativeProcess.postMessage({name: "domready"});
});
/* ]]> */
</script>
]=]
FooterInjection=[=[
<script type="text/javascript">
/* <![CDATA[ */
document.querySelectorAll("span.hl").forEach(function(item) { item.addEventListener('click', handleClick); });
/* ]]> */
</script>
]=]
end
Plugins={
{ Type="lang", Chunk=syntaxUpdate },
{ Type="theme", Chunk=themeUpdate }
}