MCPcopy Index your code
hub / github.com/pyscript/pyscript / _write_to_dom

Function _write_to_dom

core/src/stdlib/pyscript/display.py:184–204  ·  view source on GitHub ↗

Given an `element` and a `value`, write formatted content to the referenced DOM element. If `append` is True, content is added to the existing content; otherwise, the existing content is replaced. Creates a wrapper `div` when appending multiple items to preserve structure.

(element, value, append)

Source from the content-addressed store, hash-verified

182
183
184def _write_to_dom(element, value, append):
185 """
186 Given an `element` and a `value`, write formatted content to the referenced
187 DOM element. If `append` is True, content is added to the existing content;
188 otherwise, the existing content is replaced.
189
190 Creates a wrapper `div` when appending multiple items to preserve
191 structure.
192 """
193 html_content, mime_type = _get_content_and_mime(value)
194 if not html_content.strip():
195 return
196 if append:
197 container = document.createElement("div")
198 element.append(container)
199 else:
200 container = element
201 if mime_type in ("application/javascript", "text/html"):
202 container.append(document.createRange().createContextualFragment(html_content))
203 else:
204 container.innerHTML = html_content
205
206
207def display(*values, target=None, append=True):

Callers 1

displayFunction · 0.85

Calls 2

_get_content_and_mimeFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected