Skip to content

Commit 456001f

Browse files
committed
docs: explaination on escaping script tag
1 parent 093e436 commit 456001f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

jupyter_sphinx/ast.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,15 @@ def __init__(self, rawsource="", *children, **attributes):
388388
super().__init__("", state=attributes["state"])
389389

390390
def html(self):
391+
392+
# escape </script> to avoid early closing of the tag in the html page
393+
json_data = json.dumps(self["state"]).replace("</script>", r"<\/script>")
394+
391395
# TODO: render into a separate file if 'html-manager' starts fully
392396
# parsing script tags, and not just grabbing their innerHTML
393397
# https://github.com/jupyter-widgets/ipywidgets/blob/master/packages/html-manager/src/libembed.ts#L36
394398
return ipywidgets.embed.snippet_template.format(
395-
load="",
396-
widget_views="",
397-
json_data=json.dumps(self["state"]).replace("</script>", r"<\/script>")
399+
load="", widget_views="", json_data=json_data
398400
)
399401

400402
def cell_output_to_nodes(outputs, write_stderr, out_dir,

0 commit comments

Comments
 (0)