-
Notifications
You must be signed in to change notification settings - Fork 0
/
codemirror.js
executable file
·37 lines (35 loc) · 1.16 KB
/
codemirror.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
import {EditorState, basicSetup} from "@codemirror/basic-setup"
import {EditorView, ViewUpdate, keymap} from "@codemirror/view"
import {oneDarkTheme} from "@codemirror/theme-one-dark";
import {defaultTabBinding} from "@codemirror/commands"
import {html} from "@codemirror/lang-html"
import {css} from "@codemirror/lang-css"
import {javascript} from "@codemirror/lang-javascript"
$(document).ready(function () {
$('.codemirror').each(function(){
if ($(this).hasClass('htmlEditor')) {
editor(this, html());
} else if ($(this).hasClass('cssEditor')) {
editor(this, css());
} else if ($(this).hasClass('jsEditor')) {
editor(this, javascript());
}
});
function editor(div, type) {
return new EditorView({
state: EditorState.create({
extensions: [
basicSetup,
keymap.of([defaultTabBinding]),
type,
//oneDarkTheme,
EditorView.updateListener.of((EditorView) => {
$(div).find('textarea').text(EditorView.state.doc.toString());
})
],
doc: $(div).find('code').text()
}),
parent: document.querySelector("#" + $(div).attr('id'))
});
}
});