Skip to content

Commit b63ec19

Browse files
added dynamic theming
1 parent 97261a2 commit b63ec19

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@ Attributes
3434
- `src` - load an external source file
3535
- `style` - CSS styling (default `height:100%;width:100%;`)
3636
- `mode` - the language you want to use
37+
- `theme` - the codemirror theme you want to use
3738
- `viewport-margin`<sup>1</sup> - sets the `viewportMargin` option of the CodeMirrror editor instance (default `10`)
3839
- `readonly` - sets the codemirror's "readOnly" configuration attribute to true, you may set `readonly="nocursor"` if you want to disable the cursor and not let the user copy the text inside
3940

4041
*<sup>1</sup>Setting `viewport-margin` to `infinity` will auto-resize the editor to its contents. To see this in action, check out the [CodeMirror Auto-Resize Demo](https://codemirror.net/demo/resize.html).*
4142

4243
### Basic Usage
4344

44-
all language modes are dynamically loaded, and the css is dynamically loaded, you don't need to add any additional files for them
45+
all language modes/themes are dynamically loaded, and the css is dynamically loaded, you don't need to add any additional files for them
46+
47+
**JavaScript example**
4548

4649
```html
4750
<script type="module" src="https://cdn.jsdelivr.net/gh/vanillawc/wc-code/index.js"></script>
@@ -54,6 +57,8 @@ all language modes are dynamically loaded, and the css is dynamically loaded, yo
5457
</wc-code>
5558
```
5659

60+
**Python Example**
61+
5762
```html
5863
<script type="module" src="https://cdn.jsdelivr.net/gh/vanillawc/wc-code/index.js"></script>
5964
<p>Python code example here</p>
@@ -65,3 +70,18 @@ all language modes are dynamically loaded, and the css is dynamically loaded, yo
6570
</script>
6671
</wc-code>
6772
```
73+
74+
**Theme Example**
75+
```html
76+
<script type="module" src="https://cdn.jsdelivr.net/gh/vanillawc/wc-code/index.js"></script>
77+
<p>Python code example here</p>
78+
<wc-code mode="python" theme="monokai">
79+
<script type="wc-content">
80+
a = 1
81+
b = 5
82+
print(a, b, a+b)
83+
</script>
84+
</wc-code>
85+
```
86+
87+
see https://codemirror.net/theme/ for a list of supported themes

dev/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<h1>JavaScript</h1>
1010
<p>JavaScript code example here</p>
1111
<!-- web component examples go here -->
12-
<wc-code mode="javascript">
12+
<wc-code mode="javascript" theme="monokai">
1313
<script type="wc-content">
1414
const resp = await fetch("https://sv443.net/jokeapi/v2/joke/Any?blacklistFlags=nsfw,racist,sexist&format=txt");
1515
const text = await resp.text();

0 commit comments

Comments
 (0)