| 1 | <!DOCTYPE html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta charset="utf-8"> |
| 5 | <title>Turndown Demo</title> |
| 6 | <meta name="viewport" content="width=device-width"> |
| 7 | <style> |
| 8 | * { |
| 9 | -webkit-box-sizing: border-box; |
| 10 | -moz-box-sizing: border-box; |
| 11 | box-sizing: border-box; |
| 12 | } |
| 13 | |
| 14 | body { |
| 15 | margin: 0 auto; |
| 16 | font-family: courier, monospace, sans-serif; |
| 17 | line-height: 1.3125; |
| 18 | color: #333; |
| 19 | } |
| 20 | |
| 21 | header { |
| 22 | padding: 0.5em; |
| 23 | background-color: #fff; |
| 24 | text-align: center; |
| 25 | } |
| 26 | |
| 27 | footer { |
| 28 | font-size: 0.875em; |
| 29 | text-align: center; |
| 30 | color: #666; |
| 31 | } |
| 32 | |
| 33 | h1, |
| 34 | label[for="input"], |
| 35 | label[for="output"] { |
| 36 | margin: 0; |
| 37 | font-size: 1em; |
| 38 | font-weight: 700; |
| 39 | letter-spacing: 0.0625em; |
| 40 | text-transform: uppercase; |
| 41 | } |
| 42 | |
| 43 | label[for="input"], |
| 44 | label[for="output"] { |
| 45 | font-weight: 400; |
| 46 | } |
| 47 | |
| 48 | .source-link { |
| 49 | font-size: 0.875em; |
| 50 | } |
| 51 | |
| 52 | .row:before, |
| 53 | .row:after { |
| 54 | content: " "; |
| 55 | display: table; |
| 56 | } |
| 57 | |
| 58 | .row:after { |
| 59 | clear: both; |
| 60 | } |
| 61 | |
| 62 | .row { |
| 63 | *zoom: 1; |
| 64 | } |
| 65 | |
| 66 | .col, |
| 67 | .form-group { |
| 68 | padding: 0 0.5em; |
| 69 | } |
| 70 | |
| 71 | @media (min-width: 36em) { |
| 72 | .col { |
| 73 | float: left; |
| 74 | width: 50%; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | textarea { |
| 79 | width: 100%; |
| 80 | height: 36em; |
| 81 | margin: 0; |
| 82 | padding: 0.5em; |
| 83 | overflow: auto; |
| 84 | border: 1px solid; |
| 85 | background-color: #fff; |
| 86 | font-family: inherit; |
| 87 | font-size: inherit; |
| 88 | line-height: inherit; |
| 89 | color: inherit; |
| 90 | } |
| 91 | |
| 92 | #input { |
| 93 | background-color: #333; |
| 94 | color: #fff; |
| 95 | border: none; |
| 96 | } |
| 97 | |
| 98 | select { |
| 99 | display: block; |
| 100 | width: 100%; |
| 101 | font-size: inherit; |
| 102 | } |
| 103 | |
| 104 | .form-group { |
| 105 | display: inline-block; |
| 106 | } |
| 107 | |
| 108 | .form-group label { |
| 109 | font-size: 0.875em; |
| 110 | } |
| 111 | </style> |
| 112 | <script src="https://unpkg.com/turndown/dist/turndown.js"></script> |
| 113 | </head> |
| 114 | <body> |
| 115 | <header> |
| 116 | <h1>turndown</h1> |
| 117 | <a class="source-link" href="https://github.com/mixmark-io/turndown">Source on GitHub</a> |
| 118 | </header> |
| 119 | <div class="row"> |
| 120 | <div class="col"> |
| 121 | <label for="input">HTML</label> |
| 122 | <textarea cols="100" rows=10 id="input"><h1>Turndown Demo</h1> |
| 123 | |
| 124 | <p>This demonstrates <a href="https://github.com/mixmark-io/turndown">turndown</a> – an HTML to Markdown converter in JavaScript.</p> |
| 125 | |
| 126 | <h2>Usage</h2> |
| 127 | |
| 128 | <pre><code class="language-js">var turndownService = new TurndownService() |
| 129 | console.log( |
| 130 | turndownService.turndown('&lt;h1&gt;Hello world&lt;/h1&gt;') |
| 131 | )</code></pre> |
| 132 | |
| 133 | <hr /> |
| 134 | |
| 135 | <p>It aims to be <a href="http://commonmark.org/">CommonMark</a> |
| 136 | compliant, and includes options to style the output. These options include:</p> |
| 137 | |
| 138 | <ul> |
| 139 | <li>headingStyle (setext or atx)</li> |
| 140 | <li>horizontalRule (*, -, or _)</li> |
| 141 | <li>bullet (*, -, or +)</li> |
| 142 | <li>codeBlockStyle (indented or fenced)</li> |
| 143 | <li>fence (` or ~)</li> |
| 144 | <li>emDelimiter (_ or *)</li> |
| 145 | <li>strongDelimiter (** or __)</li> |
| 146 | <li>linkStyle (inlined or referenced)</li> |
| 147 | <li>linkReferenceStyle (full, collapsed, or shortcut)</li> |
| 148 | </ul></textarea> |
| 149 | </div> |
| 150 | <div class="col"> |
| 151 | <label for="output">Markdown</label> |
| 152 | <textarea readonly cols="100" rows=10 id="output"></textarea> |
| 153 | </div> |
| 154 | </div> |
| 155 | |
| 156 | <div class="row"> |
| 157 | <form method="get" action="/turndown" id="options"> |
| 158 | <div class="form-group"> |
| 159 | <label for="headingStyle">Heading style</label> |
| 160 | <select name="headingStyle" id="headingStyle"> |
| 161 | <option value="setext">setext</option> |
| 162 | <option value="atx">atx</option> |
| 163 | </select> |
| 164 | </div> |
| 165 | |
| 166 | <div class="form-group"> |
| 167 | <label for="hr">Horizontal rule</label> |
| 168 | <select name="hr" id="hr"> |
| 169 | <option value="* * *">* * *</option> |
| 170 | <option value="- - -">- - -</option> |
| 171 | <option value="_ _ _">_ _ _</option> |
| 172 | </select> |
| 173 | </div> |
| 174 | |
| 175 | <div class="form-group"> |
| 176 | <label for="bulletListMarker">Bullet</label> |
| 177 | <select name="bulletListMarker" id="bulletListMarker"> |
| 178 | <option value="*">*</option> |
| 179 | <option value="-">-</option> |
| 180 | <option value="+">+</option> |
| 181 | </select> |
| 182 | </div> |
| 183 | |
| 184 | <div class="form-group"> |
| 185 | <label for="codeBlockStyle">Code block style</label> |
| 186 | <select name="codeBlockStyle" id="codeBlockStyle"> |
| 187 | <option value="indented">indented</option> |
| 188 | <option value="fenced">fenced</option> |
| 189 | </select> |
| 190 | </div> |
| 191 | |
| 192 | <div class="form-group"> |
| 193 | <label for="fence">Fence</label> |
| 194 | <select name="fence" id="fence"> |
| 195 | <option value="```">```</option> |
| 196 | <option value="~~~">~~~</option> |
| 197 | </select> |
| 198 | </div> |
| 199 | |
| 200 | <div class="form-group"> |
| 201 | <label for="emDelimiter">Em delimiter</label> |
| 202 | <select name="emDelimiter" id="emDelimiter"> |
| 203 | <option value="_">_</option> |
| 204 | <option value="*">*</option> |
| 205 | </select> |
| 206 | </div> |
| 207 | |
| 208 | <div class="form-group"> |
| 209 | <label for="strongDelimiter">Strong delimiter</label> |
| 210 | <select name="strongDelimiter" id="strongDelimiter"> |
| 211 | <option value="**">**</option> |
| 212 | <option value="__">__</option> |
| 213 | </select> |
| 214 | </div> |
| 215 | |
| 216 | <div class="form-group"> |
| 217 | <label for="linkStyle">Link style</label> |
| 218 | <select name="linkStyle" id="linkStyle"> |
| 219 | <option value="inlined">inlined</option> |
| 220 | <option value="referenced">referenced</option> |
| 221 | </select> |
| 222 | </div> |
| 223 | |
| 224 | <div class="form-group"> |
| 225 | <label for="linkReferenceStyle">Link reference style</label> |
| 226 | <select name="linkReferenceStyle" id="linkReferenceStyle"> |
| 227 | <option value="full">full</option> |
| 228 | <option value="collapsed">collapsed</option> |
| 229 | <option value="shortcut">shortcut</option> |
| 230 | </select> |
| 231 | </div> |
| 232 | </form> |
| 233 | </div> |
| 234 | |
| 235 | <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> |
| 236 | <script> |
| 237 | ;(function () { |
| 238 | var input = document.getElementById('input') |
| 239 | var output = document.getElementById('output') |
| 240 | var optionsForm = document.getElementById('options') |
| 241 | var turndownService = new window.TurndownService(options()) |
| 242 | |
| 243 | input.addEventListener('input', update) |
| 244 | |
| 245 | optionsForm.addEventListener('change', function () { |
| 246 | turndownService = new window.TurndownService(options()) |
| 247 | update() |
| 248 | }) |
| 249 | |
| 250 | update() |
| 251 | |
| 252 | function update () { |
| 253 | output.value = turndownService.turndown(input.value) |
| 254 | } |
| 255 | |
| 256 | function options () { |
| 257 | var opts = {} |
| 258 | var inputs = optionsForm.getElementsByTagName('select') |
| 259 | for (var i = 0; i < inputs.length; i++) { |
| 260 | var input = inputs[i] |
| 261 | opts[input.name] = input.value |
| 262 | } |
| 263 | return opts |
| 264 | } |
| 265 | })() |
| 266 | </script> |
| 267 | </body> |
| 268 | </html> |