webstead: SVG rendering by extremely crude regexps

This commit is contained in:
Ben Harris 2025-09-14 19:37:56 +01:00
parent 1a49f8d120
commit 111484a4f1

View 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/, ""));
}
});
};
@ -23,5 +31,10 @@
<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>