File tree Expand file tree Collapse file tree 3 files changed +90
-5
lines changed Expand file tree Collapse file tree 3 files changed +90
-5
lines changed Original file line number Diff line number Diff line change @@ -6,12 +6,18 @@ import data from './data.json'
6
6
const store = new ReplStore ()
7
7
8
8
// TODO make dynamic
9
- const preference = ' composition'
9
+ const preference = document .documentElement .classList .contains (
10
+ ' prefer-composition'
11
+ )
12
+ ? ' composition'
13
+ : ' options'
10
14
11
- window .addEventListener (' hashchange' , () => {
12
- const newHash = ___location .hash .slice (1 )
13
- store .setFiles (data[newHash][preference])
14
- })
15
+ function updateExample () {
16
+ const hash = ___location .hash .slice (1 )
17
+ store .setFiles (data[hash][preference])
18
+ }
19
+
20
+ window .addEventListener (' hashchange' , updateExample)
15
21
</script >
16
22
17
23
<template >
Original file line number Diff line number Diff line change
1
+ <script >
2
+ import marked from ' marked'
3
+
4
+ export default {
5
+ data : () => ({
6
+ input: ' # hello'
7
+ }),
8
+ computed: {
9
+ output () {
10
+ return marked (this .input , { sanitize: true })
11
+ }
12
+ },
13
+ methods: {
14
+ update: debounce (function (e ) {
15
+ this .input = e .target .value
16
+ }, 100 )
17
+ }
18
+ }
19
+
20
+ function debounce (fn , delay ) {
21
+ let handle
22
+ return (... args ) => {
23
+ if (handle) clearTimeout (handle)
24
+ handle = setTimeout (() => {
25
+ fn (... args)
26
+ }, delay)
27
+ }
28
+ }
29
+ </script >
30
+
31
+ <template >
32
+ <div id =" editor" >
33
+ <textarea class =" input" :value =" input" @input =" update" ></textarea >
34
+ <div class =" output" v-html =" output" ></div >
35
+ </div >
36
+ </template >
37
+
38
+ <style >
39
+ body {
40
+ margin : 0 ;
41
+ height : 100% ;
42
+ font-family : ' Helvetica Neue' , Arial , sans-serif ;
43
+ color : #333 ;
44
+ }
45
+
46
+ #editor {
47
+ height : 100vh ;
48
+ display : flex ;
49
+ }
50
+
51
+ .input ,
52
+ .output {
53
+ overflow : auto ;
54
+ width : 50% ;
55
+ height : 100% ;
56
+ box-sizing : border-box ;
57
+ padding : 0 20px ;
58
+ }
59
+
60
+ .input {
61
+ border : none ;
62
+ border-right : 1px solid #ccc ;
63
+ resize : none ;
64
+ outline : none ;
65
+ background-color : #f6f6f6 ;
66
+ font-size : 14px ;
67
+ font-family : ' Monaco' , courier , monospace ;
68
+ padding : 20px ;
69
+ }
70
+
71
+ code {
72
+ color : #f66 ;
73
+ }
74
+ </style >
Original file line number Diff line number Diff line change
1
+ {
2
+ "imports" : {
3
+ "marked" :
" https://unpkg.com/[email protected] /lib/marked.esm.js"
4
+ }
5
+ }
You can’t perform that action at this time.
0 commit comments