Skip to content

Commit f44028c

Browse files
add download button
1 parent c625572 commit f44028c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ <h2>Schemascii Source</h2><textarea id="schemascii" disabled></textarea>
6161
<h2>CSS</h2><textarea id="css" disabled></textarea>
6262
</div>
6363
</div>
64-
<h2>Result</h2>
64+
<h2>Result <button id="download">Download</button></h2>
6565
<div id="output"></div>
6666
<h2>Messages</h2>
6767
<pre id="console"></pre>

scripts/web_startup.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from pyodide.http import pyfetch as fetch, open_url as get
2-
from pyodide.ffi import create_proxy as event_handler
31
import asyncio
42
import functools
53
import sys
64
import re
75
import js
86
import json
97
import warnings
8+
from pyodide.http import pyfetch as fetch, open_url as get
9+
from pyodide.ffi import create_proxy as event_handler
1010
import micropip
1111

1212

@@ -57,13 +57,21 @@ async def switch_version():
5757
version = ver_switcher.value
5858
await micropip.install(versions_to_wheel_map[version])
5959

60+
@event_handler
61+
def download_svg():
62+
a = js.document.createElement("a")
63+
a.setAttribute("href", js.URL.createObjectURL(js.Blob.new([output.innerHTML], {"type": "application/svg+xml"})))
64+
a.setAttribute("download", f"schemascii_playground_{js.Date.new.toISOString()}_no_css.svg")
65+
a.click()
66+
6067
output = js.document.getElementById("output")
6168
css_box = js.document.getElementById("css")
6269
console = js.document.getElementById("console")
6370
source = js.document.getElementById("schemascii")
6471
style_elem = js.document.getElementById("custom-css")
6572
errors = js.document.getElementById("errors")
6673
ver_switcher = js.document.getElementById("version")
74+
download_button = js.document.getElementById("download")
6775

6876

6977
print("Loading all versions... ", end="")
@@ -93,6 +101,7 @@ async def switch_version():
93101

94102
css_box.addEventListener("input", sync_css)
95103
source.addEventListener("input", render_catch_warnings)
104+
download_button.addEventListener("click", download_svg)
96105

97106
source.removeAttribute("disabled")
98107
css_box.removeAttribute("disabled")

0 commit comments

Comments
 (0)