chiark / gitweb /
webstead: SVG rendering by extremely crude regexps
authorBen Harris <bjh21@bjh21.me.uk>
Sun, 14 Sep 2025 18:37:56 +0000 (19:37 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Tue, 13 Jan 2026 21:42:18 +0000 (21:42 +0000)
webstead.xhtml

index 50d61d8e9ad43c2b559498df306518759b2cd31b..29715405ccabbb00423e953582b74ba70e4c9436 100644 (file)
@@ -8,8 +8,16 @@
       document.getElementById("run").onclick = function(){
           Bedstead({
               arguments: document.getElementById("input").value.split(" "),
-              print: function(text) {
-                  document.getElementById("output").textContent = text;
+              print: function(charstring) {
+                  document.getElementById("output").textContent = charstring;
+                  document.getElementById("rendered")
+                      .setAttribute("d", charstring
+                                    .replaceAll(/<!--(?:[^-]|-[^-])*-->/g, "")
+                                    .replace(/^.* [hv]stem /, "")
+                                    .replace(/^/, "m ")
+                                    .replaceAll(/ rmoveto/g, "")
+                                    .replaceAll(/ rlineto/g, "m")
+                                    .replace(/ endchar/, ""));
               }
           });
       };
       <input type="button" id="run" value="Run!"/>
     </form>
     <p><code id="output"></code></p>
+    <div>
+      <svg width="600" height="1000"  xmlns="http://www.w3.org/2000/svg">
+        <path id="rendered" fill="currentColor"/>
+      </svg>
+    </div>
   </body>
 </html>