Mercurial
comparison mrjunejune/test/snapshots/tools_markdown_to_html.snapshot @ 184:8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Fri, 23 Jan 2026 22:20:35 -0800 |
| parents | 1c0878eb17de |
| children |
comparison
equal
deleted
inserted
replaced
| 183:a8976a008a9d | 184:8c74204fd362 |
|---|---|
| 224 </div> | 224 </div> |
| 225 <div style="display: flex; align-items: center; justify-content: center; margin: 30px 0px;"> | 225 <div style="display: flex; align-items: center; justify-content: center; margin: 30px 0px;"> |
| 226 <small>© 2026 June Park</small> | 226 <small>© 2026 June Park</small> |
| 227 </div> | 227 </div> |
| 228 | 228 |
| 229 <script src="/markdown_to_html.js"></script> | 229 <script src="/markdown_to_html_bin.js"></script> |
| 230 <script> | 230 <script> |
| 231 function convert() { | 231 // Wait for WASM module to be ready |
| 232 output.innerHTML = ''; | 232 Module.onRuntimeInitialized = () => { |
| 233 const markdown = input.value; | 233 // Get raw pointer so we can free it after use |
| 234 renderMarkdown(output, markdown); | 234 const markdownToHtmlPtr = Module.cwrap('markdown_to_html', 'number', ['string']); |
| 235 } | 235 const markdownFree = Module.cwrap('markdown_free', null, ['number']); |
| 236 input.addEventListener('input', convert); | 236 |
| 237 | 237 function convert() { |
| 238 convert(); | 238 output.innerHTML = ''; |
| 239 | 239 const markdown = input.value; |
| 240 copy.addEventListener('click', () => { | 240 |
| 241 const htmlBlob = new Blob([output.innerHTML], { type: 'text/html'}); | 241 // Get pointer, convert to string, then free the C memory |
| 242 const textBlob = new Blob([output.innerText], { type: 'text/plain'}); | 242 const ptr = markdownToHtmlPtr(markdown); |
| 243 const data = [new ClipboardItem({ | 243 const html = Module.UTF8ToString(ptr); |
| 244 'text/html': htmlBlob, | 244 markdownFree(ptr); |
| 245 'text/plain': textBlob | 245 |
| 246 })]; | 246 output.innerHTML = html; |
| 247 navigator.clipboard.write(data).then(() => { | 247 } |
| 248 copy.textContent = "Copied!"; | 248 |
| 249 setTimeout(() => { | 249 input.addEventListener('input', convert); |
| 250 copy.textContent = "Copy"; | 250 convert(); |
| 251 copy.classList.remove('success'); | 251 |
| 252 }, 1000); | 252 copy.addEventListener('click', () => { |
| 253 }).catch(err => { | 253 const htmlBlob = new Blob([output.innerHTML], { type: 'text/html'}); |
| 254 console.error('Failed to copy: ', err); | 254 const textBlob = new Blob([output.innerText], { type: 'text/plain'}); |
| 255 const data = [new ClipboardItem({ | |
| 256 'text/html': htmlBlob, | |
| 257 'text/plain': textBlob | |
| 258 })]; | |
| 259 navigator.clipboard.write(data).then(() => { | |
| 260 copy.textContent = "Copied!"; | |
| 261 setTimeout(() => { | |
| 262 copy.textContent = "Copy"; | |
| 263 copy.classList.remove('success'); | |
| 264 }, 1000); | |
| 265 }).catch(err => { | |
| 266 console.error('Failed to copy: ', err); | |
| 267 }); | |
| 255 }); | 268 }); |
| 256 }); | 269 }; |
| 257 </script> | 270 </script> |
| 258 </body> | 271 </body> |
| 259 </html> | 272 </html> |