-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdemo.js
87 lines (70 loc) · 1.31 KB
/
demo.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// BROWSER DEMO
import { fixIndent } from "./indent.js";
const inputContainer = document.querySelector(".editor.input");
const outputContainer = document.querySelector(".editor.output");
const defaultInput = `
;; multi-arity function
(defn foo
([a b]
(+ a b))
([a b c]
(+ a b c)))
;; cond pairs
(cond
foo
bar
baz
qux)
;; ns requires
(ns example.foo
(:require [example.bar :as bar]
[example.baz :as baz]))
;; one-space
(->> foo
(bar)
(baz))
;; two-space
(->> foo
(bar)
(baz))
;; arg-alignment
(->> foo
(bar)
(baz))
;; arbitrary arg alignment
(assoc foo :bar bar
:baz baz)
;; hiccups
[:div {:style {:background "#FFF"
:color "#000"}}
[:h1 "title"]
[:ul
[:li "item 1"]
[:li "item 2"]
[:li "item 3"]]]
(comment
(foo bar
baz)
)
#_(defn foo []
(println "HI"))
`.trim();
const cmInput = CodeMirror(inputContainer, {
mode: "clojure",
theme: "github"
});
const cmOutput = CodeMirror(outputContainer, {
mode: "clojure",
theme: "github",
readOnly: true
});
cmInput.on("changes", () => {
const text = cmInput.getValue();
const result = fixIndent(text);
if (result.success) {
cmOutput.setValue(result.text);
} else {
cmOutput.setValue(JSON.stringify(result.error));
}
});
cmInput.setValue(defaultInput);