-
Notifications
You must be signed in to change notification settings - Fork 879
/
index.html
268 lines (231 loc) · 6.31 KB
/
index.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Turndown Demo</title>
<meta name="viewport" content="width=device-width">
<style>
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
margin: 0 auto;
font-family: courier, monospace, sans-serif;
line-height: 1.3125;
color: #333;
}
header {
padding: 0.5em;
background-color: #fff;
text-align: center;
}
footer {
font-size: 0.875em;
text-align: center;
color: #666;
}
h1,
label[for="input"],
label[for="output"] {
margin: 0;
font-size: 1em;
font-weight: 700;
letter-spacing: 0.0625em;
text-transform: uppercase;
}
label[for="input"],
label[for="output"] {
font-weight: 400;
}
.source-link {
font-size: 0.875em;
}
.row:before,
.row:after {
content: " ";
display: table;
}
.row:after {
clear: both;
}
.row {
*zoom: 1;
}
.col,
.form-group {
padding: 0 0.5em;
}
@media (min-width: 36em) {
.col {
float: left;
width: 50%;
}
}
textarea {
width: 100%;
height: 36em;
margin: 0;
padding: 0.5em;
overflow: auto;
border: 1px solid;
background-color: #fff;
font-family: inherit;
font-size: inherit;
line-height: inherit;
color: inherit;
}
#input {
background-color: #333;
color: #fff;
border: none;
}
select {
display: block;
width: 100%;
font-size: inherit;
}
.form-group {
display: inline-block;
}
.form-group label {
font-size: 0.875em;
}
</style>
<script src="https://unpkg.com/turndown/dist/turndown.js"></script>
</head>
<body>
<header>
<h1>turndown</h1>
<a class="source-link" href="https://github.com/mixmark-io/turndown">Source on GitHub</a>
</header>
<div class="row">
<div class="col">
<label for="input">HTML</label>
<textarea cols="100" rows=10 id="input"><h1>Turndown Demo</h1>
<p>This demonstrates <a href="https://github.com/mixmark-io/turndown">turndown</a> – an HTML to Markdown converter in JavaScript.</p>
<h2>Usage</h2>
<pre><code class="language-js">var turndownService = new TurndownService()
console.log(
turndownService.turndown('&lt;h1&gt;Hello world&lt;/h1&gt;')
)</code></pre>
<hr />
<p>It aims to be <a href="http://commonmark.org/">CommonMark</a>
compliant, and includes options to style the output. These options include:</p>
<ul>
<li>headingStyle (setext or atx)</li>
<li>horizontalRule (*, -, or _)</li>
<li>bullet (*, -, or +)</li>
<li>codeBlockStyle (indented or fenced)</li>
<li>fence (` or ~)</li>
<li>emDelimiter (_ or *)</li>
<li>strongDelimiter (** or __)</li>
<li>linkStyle (inlined or referenced)</li>
<li>linkReferenceStyle (full, collapsed, or shortcut)</li>
</ul></textarea>
</div>
<div class="col">
<label for="output">Markdown</label>
<textarea readonly cols="100" rows=10 id="output"></textarea>
</div>
</div>
<div class="row">
<form method="get" action="/turndown" id="options">
<div class="form-group">
<label for="headingStyle">Heading style</label>
<select name="headingStyle" id="headingStyle">
<option value="setext">setext</option>
<option value="atx">atx</option>
</select>
</div>
<div class="form-group">
<label for="hr">Horizontal rule</label>
<select name="hr" id="hr">
<option value="* * *">* * *</option>
<option value="- - -">- - -</option>
<option value="_ _ _">_ _ _</option>
</select>
</div>
<div class="form-group">
<label for="bulletListMarker">Bullet</label>
<select name="bulletListMarker" id="bulletListMarker">
<option value="*">*</option>
<option value="-">-</option>
<option value="+">+</option>
</select>
</div>
<div class="form-group">
<label for="codeBlockStyle">Code block style</label>
<select name="codeBlockStyle" id="codeBlockStyle">
<option value="indented">indented</option>
<option value="fenced">fenced</option>
</select>
</div>
<div class="form-group">
<label for="fence">Fence</label>
<select name="fence" id="fence">
<option value="```">```</option>
<option value="~~~">~~~</option>
</select>
</div>
<div class="form-group">
<label for="emDelimiter">Em delimiter</label>
<select name="emDelimiter" id="emDelimiter">
<option value="_">_</option>
<option value="*">*</option>
</select>
</div>
<div class="form-group">
<label for="strongDelimiter">Strong delimiter</label>
<select name="strongDelimiter" id="strongDelimiter">
<option value="**">**</option>
<option value="__">__</option>
</select>
</div>
<div class="form-group">
<label for="linkStyle">Link style</label>
<select name="linkStyle" id="linkStyle">
<option value="inlined">inlined</option>
<option value="referenced">referenced</option>
</select>
</div>
<div class="form-group">
<label for="linkReferenceStyle">Link reference style</label>
<select name="linkReferenceStyle" id="linkReferenceStyle">
<option value="full">full</option>
<option value="collapsed">collapsed</option>
<option value="shortcut">shortcut</option>
</select>
</div>
</form>
</div>
<footer><p>Turndown is copyright © 2017 <a href="http://www.domchristie.co.uk/">Dom Christie</a> and is released under the MIT license</p></footer>
<script>
;(function () {
var input = document.getElementById('input')
var output = document.getElementById('output')
var optionsForm = document.getElementById('options')
var turndownService = new window.TurndownService(options())
input.addEventListener('input', update)
optionsForm.addEventListener('change', function () {
turndownService = new window.TurndownService(options())
update()
})
update()
function update () {
output.value = turndownService.turndown(input.value)
}
function options () {
var opts = {}
var inputs = optionsForm.getElementsByTagName('select')
for (var i = 0; i < inputs.length; i++) {
var input = inputs[i]
opts[input.name] = input.value
}
return opts
}
})()
</script>
</body>
</html>