add d2-svg id on generation

This commit is contained in:
Bernard Xie 2023-01-03 15:01:21 -08:00
parent 070b50a6e2
commit dfd66232fc
No known key found for this signature in database
GPG key ID: 3C3E0036CE0F892C
2 changed files with 3 additions and 4 deletions

View file

@ -74,6 +74,7 @@ func setViewbox(writer io.Writer, diagram *d2target.Diagram, pad int) (width int
// TODO background stuff. e.g. dotted, grid, colors
fmt.Fprintf(writer, `<?xml version="1.0" encoding="utf-8"?>
<svg
id="d2-svg"
style="background: white;"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
width="%d" height="%d" viewBox="%d %d %d %d">`, w, h, tl.X-pad, tl.Y-pad, w, h)

View file

@ -1,10 +1,8 @@
window.addEventListener("DOMContentLoaded", () => {
const svgEl = document.querySelector("svg");
const svgID = "d2-svg";
svgEl.setAttribute("id", svgID);
if (document.documentElement.getAttribute("id") !== svgID) {
if (document.documentElement.getAttribute("id") !== "d2-svg") {
return;
}
const svgEl = document.documentElement;
let width = parseInt(svgEl.getAttribute("width"), 10);
let height = parseInt(svgEl.getAttribute("height"), 10);
let ratio;