-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkdown.html
More file actions
124 lines (103 loc) · 3.02 KB
/
Copy pathmarkdown.html
File metadata and controls
124 lines (103 loc) · 3.02 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Markdown</title>
<link rel="stylesheet" type="text/css" href="main.css">
<script src="/vendor/marked.js"></script>
<script src="/vendor/prettier.js"></script>
<script src="/vendor/prettier-markdown.js"></script>
<style>
header + .bar, h3 {
margin-bottom: 0.5em;
}
textarea + .bar {
margin-top: 0.5em;
}
textarea {
font-family: monospace;
}
select {
text-align: center;
}
iframe {
width: 100%;
min-height: 250px;
}
#source {
white-space: pre-wrap;
word-break: break-word;
font-family: monospace;
height: 250px;
overflow-y: auto;
margin-top: 0;
border: 1px solid light-dark(#dedede ,#3d3d3d);
}
</style>
</head>
<body>
<header>
<h1><a href="index.html">Tools</a></h1>
</header>
<main>
<header class="bar">
<h2>Markdown</h2>
</header>
<div class="bar">
<h3>Input</h3>
<button onclick="format()">Format</button>
</div>
<textarea placeholder="# hello world" rows="10" cols="50" id="input"></textarea>
<div class="bar">
<select id="mode">
<option value="source" selected>Convert</option>
<option value="preview">Preview</option>
</select>
</div>
<h3 id="heading">Output</h3>
<iframe id="preview" hidden></iframe>
<textarea id="source" rows="10" cols="50" readonly></textarea>
<noscript>
<small>This tool requires Javascript to work.</small>
</noscript>
</main>
<script>
const input = document.getElementById("input");
const mode = document.getElementById("mode");
const preview = document.getElementById("preview");
const source = document.getElementById("source");
const heading = document.getElementById("heading");
function render() {
const html = marked.parse(input.value);
if (mode.value == 'source') {
source.value = html;
source.hidden = false;
preview.hidden = true;
heading.innerText = "Output";
} else {
preview.srcdoc = html;
preview.hidden = false;
source.hidden = true;
heading.innerText = "Preview";
}
}
async function format() {
try {
input.value = await prettier.format(input.value, {
parser: 'markdown',
plugins: prettierPlugins
});
render();
} catch(e) {
alert(`Error: ${e.message}`);
}
}
input.addEventListener("input", render);
mode.addEventListener("change", render);
</script>
<script src="/vendor/instant-page.js" type="module"></script>
<script src="/offline.js"></script>
</body>
</html>