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)
| 182 | |
| 183 | |
| 184 | def _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 | |
| 207 | def display(*values, target=None, append=True): |
no test coverage detected