-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcode.js
More file actions
30 lines (25 loc) · 986 Bytes
/
code.js
File metadata and controls
30 lines (25 loc) · 986 Bytes
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
/*
* Federated Wiki : Code Plugin
*
* Licensed under the MIT license.
* https://github.com/fedwiki/wiki-plugin-code/blob/master/LICENSE.txt
*/
async function emit($item, item) {
if (!$("link[href='https://cdn.jsdelivr.net/npm/highlight.js@11/styles/github.min.css']").length) {
$('<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@11/styles/github.min.css">').appendTo("head")
}
if (!$("link[href='/plugins/code/code.css']").length) {
$('<link rel="stylesheet" href="/plugins/code/code.css">').appendTo("head")
}
window.HighlightJS = (await import('https://cdn.jsdelivr.net/npm/highlight.js@11/+esm')).HighlightJS
$item.html(`<pre class='hljs'><code class='hljs'>${HighlightJS.highlightAuto(item.text).value}</code></pre>`)
}
function bind($item, item) {
$item.on('dblclick', () => wiki.textEditor($item, item))
}
if (typeof window !== "undefined" && window !== null) {
window.plugins.code = {
emit: emit,
bind: bind
}
}