diff 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
line wrap: on
line diff
--- a/mrjunejune/test/snapshots/tools_markdown_to_html.snapshot	Fri Jan 23 21:19:08 2026 -0800
+++ b/mrjunejune/test/snapshots/tools_markdown_to_html.snapshot	Fri Jan 23 22:20:35 2026 -0800
@@ -226,34 +226,47 @@
   <small>&copy; 2026 June Park</small>
 </div>
 
-    <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>