Mercurial
diff 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 |
line wrap: on
line diff
--- a/mrjunejune/src/tools/markdown_to_html/index.html Fri Jan 23 21:19:08 2026 -0800 +++ b/mrjunejune/src/tools/markdown_to_html/index.html Fri Jan 23 22:20:35 2026 -0800 @@ -68,34 +68,47 @@ </div> </div> {{/parts/footer.html}} - <script src="/markdown_to_html.js"></script> + <script src="/markdown_to_html_bin.js"></script> <script> - function convert() { - output.innerHTML = ''; - const markdown = input.value; - renderMarkdown(output, markdown); - } - input.addEventListener('input', convert); - - convert(); + // Wait for WASM module to be ready + Module.onRuntimeInitialized = () => { + // Get raw pointer so we can free it after use + const markdownToHtmlPtr = Module.cwrap('markdown_to_html', 'number', ['string']); + const markdownFree = Module.cwrap('markdown_free', null, ['number']); + + function convert() { + output.innerHTML = ''; + const markdown = input.value; + + // Get pointer, convert to string, then free the C memory + const ptr = markdownToHtmlPtr(markdown); + const html = Module.UTF8ToString(ptr); + markdownFree(ptr); + + output.innerHTML = html; + } - copy.addEventListener('click', () => { - const htmlBlob = new Blob([output.innerHTML], { type: 'text/html'}); - const textBlob = new Blob([output.innerText], { type: 'text/plain'}); - const data = [new ClipboardItem({ - 'text/html': htmlBlob, - 'text/plain': textBlob - })]; - navigator.clipboard.write(data).then(() => { - copy.textContent = "Copied!"; - setTimeout(() => { - copy.textContent = "Copy"; - copy.classList.remove('success'); - }, 1000); - }).catch(err => { - console.error('Failed to copy: ', err); + input.addEventListener('input', convert); + convert(); + + copy.addEventListener('click', () => { + const htmlBlob = new Blob([output.innerHTML], { type: 'text/html'}); + const textBlob = new Blob([output.innerText], { type: 'text/plain'}); + const data = [new ClipboardItem({ + 'text/html': htmlBlob, + 'text/plain': textBlob + })]; + navigator.clipboard.write(data).then(() => { + copy.textContent = "Copied!"; + setTimeout(() => { + copy.textContent = "Copy"; + copy.classList.remove('success'); + }, 1000); + }).catch(err => { + console.error('Failed to copy: ', err); + }); }); - }); + }; </script> </body> </html>