8000 fix error when trying to output to non existing element · sudhircw/pyscript@3c2ca6d · GitHub
[go: up one dir, main page]

Skip to content

Commit 3c2ca6d

Browse files
committed
fix error when trying to output to non existing element
1 parent a6955b1 commit 3c2ca6d

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

pyscriptjs/examples/bokeh.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<h1>Bokeh Example</h1>
2424
<div id="myplot"></div>
2525

26-
<py-script>
26+ 10000
<py-script id="mycode">
2727
import json
2828
import pyodide
2929

pyscriptjs/examples/bokeh_interactive.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<h1>Bokeh Example</h1>
2424
<div id="myplot"></div>
2525

26-
<py-script>
26+
<py-script id="my">
2727
import asyncio
2828
import json
2929
import pyodide

pyscriptjs/src/components/pyrepl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export class PyRepl extends BaseEvalElement {
188188
this.errorElement = this.outputElement;
189189
}
190190
}
191-
191+
192192

193193
this.appendChild(mainDiv);
194194
this.editor.focus();

pyscriptjs/src/components/pyscript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export class PyScript extends BaseEvalElement {
247247
}
248248

249249
getSourceFromElement(): string {
250-
return this.code;
250+
return htmlDecode(this.code);
251251
}
252252
}
253253

pyscriptjs/src/interpreter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class PyScript:
2222
if append:
2323
child = document.createElement('div');
2424
element = document.querySelector(f'#{element_id}');
25+
if not element:
26+
return
2527
exec_id = exec_id or element.childElementCount + 1
2628
element_id = child.id = f"{element_id}-{exec_id}";
2729
element.appendChild(child);
@@ -34,11 +36,9 @@ class PyScript:
3436
img_str = 'data:image/png;base64,' + base64.b64encode(buf.read()).decode('UTF-8')
3537
document.getElementById(element_id).innerHTML = f'<div><img id="plt" src="{img_str}"/></div>'
3638
elif hasattr(value, "startswith") and value.startswith("data:image"):
37-
console.log(f"DATA/IMAGE: {value}")
3839
document.getElementById(element_id).innerHTML = f'<div><img id="plt" src="{value}"/></div>'
3940
else:
4041
document.getElementById(element_id).innerHTML = value;
41-
console.log(f"ELSE: {append} ==> {element_id} --> {value}")
4242
4343
@staticmethod
4444
def run_until_complete(f):

0 commit comments

Comments
 (0)
0