-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (39 loc) · 1.11 KB
/
index.js
File metadata and controls
44 lines (39 loc) · 1.11 KB
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
import init, { parse } from "./pkg/markdown_parser.js";
const input = document.getElementById("input");
const output = document.getElementById("output");
input.addEventListener("keydown", function (e) {
if (e.key == "Tab") {
e.preventDefault();
var start = this.selectionStart;
var end = this.selectionEnd;
// Set textarea value to: text before caret + two spaces + text after caret
this.value =
this.value.substring(0, start) + " " + this.value.substring(end);
// Move caret past both inserted spaces
this.selectionStart = this.selectionEnd = start + 2;
}
});
init().then(() => {
input.addEventListener("keyup", () => {
const renderedHtml = parse(input.value);
const dangerousPatterns = [
"<script",
"javascript:",
"data:",
"vbscript:",
"onerror=",
"onload=",
"onclick=",
"onmouseover=",
];
if (
dangerousPatterns.some((pattern) =>
renderedHtml.toLowerCase().includes(pattern),
)
) {
output.innerHTML = "Cannot render script tag!";
return;
}
output.innerHTML = renderedHtml;
});
});