8000 [FIX] output management cleanups (#464) · TutorExilius/pyscript@eaacd45 · GitHub
[go: up one dir, main page]

Skip to content

Commit eaacd45

Browse files
marianoweberMariano Weberpre-commit-ci[bot]
authored
[FIX] output management cleanups (pyscript#464)
* return on \n before empty div is appended * use appendOutput with out.write * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: Mariano Weber <info@uiremotely.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 5d733ab commit eaacd45

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

pyscriptjs/src/components/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export class BaseEvalElement extends HTMLElement {
152152
Element = pyodide.globals.get('Element');
153153
}
154154
const out = Element(this.outputElement.id);
155-
out.write.callKwargs(output, { append: true });
155+
out.write.callKwargs(output, { append: this.appendOutput });
156156

157157
this.outputElement.hidden = false;
158158
this.outputElement.style.display = 'block';
@@ -179,7 +179,7 @@ export class BaseEvalElement extends HTMLElement {
179179
const out = Element(this.errorElement.id);
180180

181181
addClasses(this.errorElement, ['bg-red-200', 'p-2']);
182-
out.write.callKwargs(err, { append: true });
182+
out.write.callKwargs(err, { append: this.appendOutput });
183183

184184
this.errorElement.children[this.errorElement.children.length - 1].setAttribute('error', '');
185185
this.errorElement.hidden = false;

pyscriptjs/src/pyscript.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ def write(self, value, append=False):
153153

154154
out_element_id = self.id
155155

156+
html, mime_type = format_mime(value)
157+
if html == "\n":
158+
return
159+
156160
if append:
157161
child = document.createElement("div")
158162
exec_id = self.element.childElementCount + 1
@@ -161,13 +165,10 @@ def write(self, value, append=False):
161165

162166
out_element = document.querySelector(f"#{out_element_id}")
163167

164-
html, mime_type = format_mime(value)
165168
if mime_type in ("application/javascript", "text/html"):
166169
script_element = document.createRange().createContextualFragment(html)
167170
out_element.appendChild(script_element)
168171
else:
169-
if html == "\n":
170-
return
171172
out_element.innerHTML = html
172173

173174
def clear(self):

0 commit comments

Comments
 (0)
0