-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
219 lines (188 loc) · 7.27 KB
/
index.html
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<script type="importmap">
{
"imports": {
"@babel/runtime/helpers/extends": "../node_modules/@babel/runtime/helpers/esm/extends.js",
"@codemirror/autocomplete": "../node_modules/@codemirror/autocomplete/dist/index.js",
"@codemirror/commands": "../node_modules/@codemirror/commands/dist/index.js",
"@codemirror/lang-css": "../node_modules/@codemirror/lang-css/dist/index.js",
"@codemirror/lang-html": "../node_modules/@codemirror/lang-html/dist/index.js",
"@codemirror/lang-javascript": "../node_modules/@codemirror/lang-javascript/dist/index.js",
"@codemirror/language": "../node_modules/@codemirror/language/dist/index.js",
"@codemirror/lint": "../node_modules/@codemirror/lint/dist/index.js",
"@codemirror/search": "../node_modules/@codemirror/search/dist/index.js",
"@codemirror/state": "../node_modules/@codemirror/state/dist/index.js",
"@codemirror/theme-one-dark": "../node_modules/@codemirror/theme-one-dark/dist/index.js",
"@codemirror/view": "../node_modules/@codemirror/view/dist/index.js",
"@lezer/common": "../node_modules/@lezer/common/dist/index.js",
"@lezer/css": "../node_modules/@lezer/css/dist/index.js",
"@lezer/highlight": "../node_modules/@lezer/highlight/dist/index.js",
"@lezer/html": "../node_modules/@lezer/html/dist/index.js",
"@lezer/javascript": "../node_modules/@lezer/javascript/dist/index.js",
"@lezer/lr": "../node_modules/@lezer/lr/dist/index.js",
"@lume/element": "../node_modules/@lume/element/dist/index.js",
"@uiw/codemirror-theme-noctis-lilac": "../node_modules/@uiw/codemirror-theme-noctis-lilac/esm/index.js",
"@uiw/codemirror-themes": "../node_modules/@uiw/codemirror-themes/esm/index.js",
"classy-solid": "../node_modules/classy-solid/dist/index.js",
"code-mirror-element": "../dist/index.js",
"codemirror": "../node_modules/codemirror/dist/index.js",
"crelt": "../node_modules/crelt/index.js",
"lodash-es/": "../node_modules/lodash-es/",
"lowclass": "../node_modules/lowclass/dist/index.js",
"lowclass/": "../node_modules/lowclass/",
"solid-js": "../node_modules/solid-js/dist/solid.js",
"solid-js/html": "../node_modules/solid-js/html/dist/html.js",
"solid-js/web": "../node_modules/solid-js/web/dist/web.js",
"style-mod": "../node_modules/style-mod/src/style-mod.js",
"thememirror/": "../node_modules/thememirror/",
"w3c-keyname": "../node_modules/w3c-keyname/index.js"
}
}
</script>
<script type="module">
import 'code-mirror-element'
</script>
<style>
code-mirror {
/* If you don't give it a height, it'll take up full height of its parent by default. */
height: 100px;
}
</style>
<h2>Editor with minimal setup, just plain text:</h2>
<code-mirror content="Hello there! This is a plain text without any features, not even undo/redo!"></code-mirror>
<h2>Editor with CodeMirror's <code>basicSetup()</code> including autocomplete, with built-in html syntax.</h2>
<code-mirror
basic-setup
language="html"
content="
<h1>Hello there!</h1>
<p>This is HTML content, with basic features including autocomplete of HTML elements</p>
"
></code-mirror>
<h2>Editor with format as-written</h2>
<p>
Use <code>strip-indent="false"</code> and <code>trim="false"</code> if you wish to keep the spacing inside the
<code>content</code> attribute as-is:
</p>
<code-mirror
basic-setup
language="html"
strip-indent="false"
trim="false"
content="
<h1>Hello there!</h1>
<p>This is HTML content, with basic features including autocomplete of HTML elements</p>
"
></code-mirror>
<h2>Editor with built-in JavaScript syntax:</h2>
<code-mirror
basic-setup
language="js"
content="
if (true) {
console.log('Hello there!')
console.log('This is JavaScript content, with a basic setup including snippet autocompletion (try typing function then autocomplete).')
}
"
></code-mirror>
<h2>Editor with a <code><template></code></h2>
<p>
A <code><template></code> element can be used instead of a content attribute to make writing the code more
convenient. If the language is html, the content of the template will be taken as is. If the language is JS, the
content will be taken from the first script child of the template:
</p>
<code-mirror basic-setup language="js">
<template>
<script>
if (true) {
console.log('Hello there!')
console.log('This is JavaScript content, with a basic setup including snippet autocompletion.')
}
</script>
</template>
</code-mirror>
<h2>Editor with theme</h2>
<p>
The default theme is Noctis Lilac. Change the theme extension by supplying a theme via the
<code>theme</code> property. Here we supply the theme from <code>@codemirror/theme-one-dark</code>:
</p>
<code-mirror id="themedEditor" basic-setup language="html">
<template>
<h1>Hello there!</h1>
<p>This is HTML content, with basic features including autocomplete of HTML elements</p>
</template>
</code-mirror>
<script type="module">
import {oneDark} from '@codemirror/theme-one-dark'
const editor = document.getElementById('themedEditor')
editor.theme = oneDark
</script>
<h2>Editor with a custom CSS string</h2>
<p>
The `stylesheet` attribute accepts a string of CSS that gets applied inside the code-mirror element's ShadowRoot. This
is useful for overriding any of CodeMirror's default styles (or those of a theme you may have loaded). Here we
override the active line color:
</p>
<code-mirror
id="styled1"
basic-setup
language="html"
stylesheet="
.cm-activeLine {
background: hsla(0, 60%, 80%, 0.2) !important;
}
"
>
<template>
<h1>Hello there!</h1>
<p>This is HTML content, with basic features including autocomplete of HTML elements</p>
</template>
</code-mirror>
<script type="module">
import {oneDark} from '@codemirror/theme-one-dark'
const editor = document.getElementById('styled1')
editor.theme = oneDark
</script>
<h2>Editors with custom stylesheet instances</h2>
<p>
The `stylesheet` property accepts HTMLStyleSheet, HTMLLinkElement, and CSSStyleSheet instances. Here we show one
editor with a <style> element passed in, and one with a CSSStyleSheet passed in, both achieving the same effect
as the previous example. This can be useful for picking styles that already exist in the document and passing them
along, or importing CSS modules and passing those along, for example.
</p>
<code-mirror id="styled2" basic-setup language="html">
<template>
<h1>Hello there!</h1>
<p>This is HTML content, with basic features including autocomplete of HTML elements</p>
</template>
</code-mirror>
<script type="module">
import {oneDark} from '@codemirror/theme-one-dark'
const editor = document.getElementById('styled2')
editor.theme = oneDark
const style = document.createElement('style')
style.textContent = /*css*/ `
.cm-activeLine {
background: hsla(0, 60%, 80%, 0.2) !important;
}
`
editor.stylesheet = style
</script>
<br />
<code-mirror id="styled3" basic-setup language="html">
<template>
<h1>Hello there!</h1>
<p>This is HTML content, with basic features including autocomplete of HTML elements</p>
</template>
</code-mirror>
<script type="module">
import {oneDark} from '@codemirror/theme-one-dark'
const editor = document.getElementById('styled3')
editor.theme = oneDark
const style = new CSSStyleSheet()
style.replaceSync(/*css*/ `
.cm-activeLine {
background: hsla(0, 60%, 80%, 0.2) !important;
}
`)
editor.stylesheet = style
</script>