@@ -92,6 +92,19 @@ def dot_wasm_html(
9292 <script type="module">
9393 (async () => {{
9494 const target = document.getElementById("{ container_id } ");
95+ const setTargetHtml = (markup) => {{
96+ if (target) {{
97+ target.innerHTML = markup;
98+ }}
99+ }};
100+ if (!target) {{
101+ return;
102+ }}
103+ const decodeBase64Utf8 = (encoded) => {{
104+ const binary = atob(encoded);
105+ const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
106+ return new TextDecoder("utf-8").decode(bytes);
107+ }};
95108 const resizeFrameToContent = () => {{
96109 try {{
97110 let h = target ? target.scrollHeight : 0;
@@ -107,7 +120,7 @@ def dot_wasm_html(
107120 window.frameElement.style.height = `${{h}}px`;
108121 }}
109122 }} catch (_err) {{
110- // best effort only
123+ /* best effort only */
111124 }}
112125 }};
113126 try {{
@@ -117,15 +130,15 @@ def dot_wasm_html(
117130 throw new Error("Graphviz WASM module does not expose Graphviz.load()");
118131 }}
119132 const graphviz = await Graphviz.load();
120- const dot = atob ("{ dot_string_base64 } ");
133+ const dot = decodeBase64Utf8 ("{ dot_string_base64 } ");
121134 const svg = await graphviz.dot(dot, "svg", "dot");
122- target.innerHTML = svg;
135+ setTargetHtml( svg) ;
123136 resizeFrameToContent();
124137 requestAnimationFrame(resizeFrameToContent);
125138 setTimeout(resizeFrameToContent, 50);
126139 }} catch (error) {{
127- target.innerHTML = "<pre style='white-space:pre-wrap;color:#b00020'>Graph rendering failed: " +
128- String(error) + "</pre>";
140+ setTargetHtml( "<pre style='white-space:pre-wrap;color:#b00020'>Graph rendering failed: " +
141+ String(error) + "</pre>") ;
129142 resizeFrameToContent();
130143 }}
131144 }})();
0 commit comments