-
-
Notifications
You must be signed in to change notification settings - Fork 148
/
Copy pathklipse_reveal.js
41 lines (34 loc) · 1.2 KB
/
klipse_reveal.js
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
{
const langToSelectorName = {
clojure: 'selector',
javascript: 'selector_eval_js',
python: 'selector_eval_python_client',
scheme: 'selector_eval_scheme',
ruby: 'selector_eval_ruby',
};
let jsSrc = (lang) => {
if (lang === 'clojure') {
return 'https://storage.googleapis.com/app.klipse.tech/plugin/js/klipse_plugin.js'
}
return 'https://storage.googleapis.com/app.klipse.tech/plugin/js/klipse_plugin.js'
}
let createIFrame = (lang,src) => {
let selectorName = langToSelectorName[lang];
return `<iframe sandbox="allow-scripts" height="100px" width="100%" srcdoc='
<pre><code class="klipse">${src}</code></pre>
<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">
<script>
window.klipse_settings = {
${selectorName}: ".klipse"
};
</script>
<script src="${jsSrc(lang)}"></script>
'>
</iframe>`
};
let klipsify = (elem) => {
elem.innerHTML = createIFrame(elem.dataset.language, elem.innerHTML);
return elem;
}
document.querySelectorAll('klipse-snippet').forEach(x => klipsify(x))
}