-
Notifications
You must be signed in to change notification settings - Fork 3
/
preview.html
102 lines (89 loc) · 1.94 KB
/
preview.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
<html>
<head>
<style>
html, body {
padding: 0;
margin: 0;
}
body {
display: flex;
}
textarea,
#preview {
height: 100%;
resize:none;
box-sizing: border-box;
}
textarea {
flex-grow: 1;
}
#preview {
background-color: rgb(27, 40, 56);
overflow-y: auto;
width: 700px;
}
#content {
width: 630px;
margin: 0 auto;
color: #acb2b8;
word-wrap: break-word;
line-height: 20px;
font-size: 14px;
padding: 20px 0;
white-space: pre-wrap;
font-family: Arial, Helvetica, Verdana, sans-serif;
}
#content img {
max-width: 100%;
}
#content a {
color: #FFF;
text-decoration: none;
}
#content a:hover {
color: #5aa9d6;
}
#content h1 {
color: #5aa9d6;
font-size: inherit;
font-weight: normal;
margin: 0;
padding: 0;
}
#content .spoiler {
background: #000;
color: rgba(0, 0, 0, 0);
display: inline-block;
padding: 0 8px;
}
#content .spoiler:hover {
color: #FFF;
}
</style>
</head>
<body>
<textarea onkeyup="onTextChange(this.value)"></textarea>
<div id="preview">
<pre id="content"></pre>
</div>
<script>
let id = 0;
const $content = document.getElementById('content');
function onTextChange(text) {
clearTimeout(id);
id = setTimeout(() => {
let parsed = text
.replace(/\[img]([^[]*)\[\/img]/g, '<img src="$1" />')
.replace(/\[url=([^\]]*)]([^[]*)\[\/url]/g, '<a href="$1">$2</a>')
.replace(/\[h1]([^[]*)\[\/h1]/g, '<h1>$1</h1>')
.replace(/\[spoiler]([^[]*)\[\/spoiler]/g, '<span class="spoiler">$1</span>')
.replace(/(\/h1>)(\r\n|\n)/g, "$1")
//.replace(/\r\n/g, '<br />')
//.replace(/\n/g, '<br />');
console.log('->', parsed);
$content.innerHTML = parsed;
}, 500);
}
</script>
</body>
</html>