-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclojure_highlighter.js
73 lines (68 loc) · 2.63 KB
/
clojure_highlighter.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
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
71
72
73
import { tags, styleTags, defaultHighlightStyle } from "@codemirror/highlight";
import { LezerLanguage } from "@codemirror/language";
import { EditorState } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
import { parser } from "lezer-clojure";
let theme = EditorView.theme({
'.cm-content': { 'white-space': 'pre-wrap', padding: '10px 0', color: '#249292e'},
'&.cm-focused': { outline: 'none' },
'.cm-line': {
padding: '0 9px',
'line-height': '1.6',
'font-size': '16px',
'font-family': 'var(--code-font)'
},
'.cm-linenumber': {color: 'rgba(27, 31, 35, 0.3)'},
'.cm-matchingBracket': { 'border-bottom': '1px solid var(--teal-color)', color: 'inherit' },
'.cm-gutters': { background: '#fff', border: 'none' },
'.cm-gutterElement': { 'margin-left': '5px' },
'.cm-cursor': { visibility: 'hidden' },
'&.cm-focused .cm-cursor': { visibility: 'visible' },
'.cm-keyword': { color: '#d73a49'},
'.cm-atom': { color: '#005cc5'},
'.cm-number': { color: '#005cc5'},
'.cm-def': { color: '#d73a49'},
'.cm-variable': { color: '#24292e'},
'.cm-variable-2': {color: '#d73a49'},
'.cm-type': { color: '#6f42c1'},
'.cm-property': { color: '#005cc5'},
'.cm-comment': { color: '#6a737d'},
'.cm-string': { color: '005cc5'},
'.cm-string-2': { color: 'rgba(46,56,60,1)'},
'.cm-meta': { color: '#24292e'},
'.cm-qualifier': { color: '#6f42c1'},
'.cm-builtin': { color: '#6f42c1'},
'.cm-bracket': { color: '#24292e'},
'.cm-tag': { color: '#22863a'},
'.cm-attribute': { color: '#6f42c1'},
'.cm-attribute': { color: '#032f62'},
'.cm-string': { color: '032f62'},
'.cm-hr': { color: '24292e'},
'.cm-link': { color: '005cc5'},
'.cm-error': { color: '#d73a49'},
'.cm-invalidchar': { color: '#d73a49'}
});
let style = {
DefLike: tags.keyword,
"Operator/Symbol": tags.keyword,
"VarName/Symbol": tags.definition(tags.variableName),
Boolean: tags.atom,
"DocString/...": tags.emphasis,
"Discard!": tags.comment,
Number: tags.number,
StringContent: tags.string,
Keyword: tags.atom,
Nil: tags.null,
LineComment: tags.lineComment,
RegExp: tags.regexp,
"\"\\\"\"": tags.string,
};
let cljParser = parser.configure({props: [styleTags(style)]});
let syntax = LezerLanguage.define({parser: cljParser}, {languageData: {commentTokens: {line: ";;"}}});
let extensions = [EditorView.editable.of(false), theme, defaultHighlightStyle, [syntax]];
document.querySelectorAll("code.clj").forEach( elt => {
new EditorView({state: EditorState.create({doc: elt.innerText.trim(),
extensions: [extensions]}),
parent: elt});
elt.firstChild.remove();
});