Mercurial
comparison mrjunejune/src/tools/markdown_to_html/index.html @ 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 | be91a73d801a |
| children | 4c725fde6999 |
comparison
equal
deleted
inserted
replaced
| 183:a8976a008a9d | 184:8c74204fd362 |
|---|---|
| 66 </div> | 66 </div> |
| 67 <div id="output"></div> | 67 <div id="output"></div> |
| 68 </div> | 68 </div> |
| 69 </div> | 69 </div> |
| 70 {{/parts/footer.html}} | 70 {{/parts/footer.html}} |
| 71 <script src="/markdown_to_html.js"></script> | 71 <script src="/markdown_to_html_bin.js"></script> |
| 72 <script> | 72 <script> |
| 73 function convert() { | 73 // Wait for WASM module to be ready |
| 74 output.innerHTML = ''; | 74 Module.onRuntimeInitialized = () => { |
| 75 const markdown = input.value; | 75 // Get raw pointer so we can free it after use |
| 76 renderMarkdown(output, markdown); | 76 const markdownToHtmlPtr = Module.cwrap('markdown_to_html', 'number', ['string']); |
| 77 } | 77 const markdownFree = Module.cwrap('markdown_free', null, ['number']); |
| 78 input.addEventListener('input', convert); | |
| 79 | |
| 80 convert(); | |
| 81 | 78 |
| 82 copy.addEventListener('click', () => { | 79 function convert() { |
| 83 const htmlBlob = new Blob([output.innerHTML], { type: 'text/html'}); | 80 output.innerHTML = ''; |
| 84 const textBlob = new Blob([output.innerText], { type: 'text/plain'}); | 81 const markdown = input.value; |
| 85 const data = [new ClipboardItem({ | 82 |
| 86 'text/html': htmlBlob, | 83 // Get pointer, convert to string, then free the C memory |
| 87 'text/plain': textBlob | 84 const ptr = markdownToHtmlPtr(markdown); |
| 88 })]; | 85 const html = Module.UTF8ToString(ptr); |
| 89 navigator.clipboard.write(data).then(() => { | 86 markdownFree(ptr); |
| 90 copy.textContent = "Copied!"; | 87 |
| 91 setTimeout(() => { | 88 output.innerHTML = html; |
| 92 copy.textContent = "Copy"; | 89 } |
| 93 copy.classList.remove('success'); | 90 |
| 94 }, 1000); | 91 input.addEventListener('input', convert); |
| 95 }).catch(err => { | 92 convert(); |
| 96 console.error('Failed to copy: ', err); | 93 |
| 94 copy.addEventListener('click', () => { | |
| 95 const htmlBlob = new Blob([output.innerHTML], { type: 'text/html'}); | |
| 96 const textBlob = new Blob([output.innerText], { type: 'text/plain'}); | |
| 97 const data = [new ClipboardItem({ | |
| 98 'text/html': htmlBlob, | |
| 99 'text/plain': textBlob | |
| 100 })]; | |
| 101 navigator.clipboard.write(data).then(() => { | |
| 102 copy.textContent = "Copied!"; | |
| 103 setTimeout(() => { | |
| 104 copy.textContent = "Copy"; | |
| 105 copy.classList.remove('success'); | |
| 106 }, 1000); | |
| 107 }).catch(err => { | |
| 108 console.error('Failed to copy: ', err); | |
| 109 }); | |
| 97 }); | 110 }); |
| 98 }); | 111 }; |
| 99 </script> | 112 </script> |
| 100 </body> | 113 </body> |
| 101 </html> | 114 </html> |