Skip to content

Commit 8011d24

Browse files
authored
Merge pull request #185 from 12rambau/master
fix: escape the closing script when dumping the outcell
2 parents 9bae988 + 456001f commit 8011d24

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

jupyter_sphinx/ast.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,14 +388,17 @@ 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="", widget_views="", json_data=json.dumps(self["state"])
399+
load="", widget_views="", json_data=json_data
396400
)
397401

398-
399402
def cell_output_to_nodes(outputs, write_stderr, out_dir,
400403
thebe_config, inline=False):
401404
"""Convert a jupyter cell with outputs and filenames to doctree nodes.

0 commit comments

Comments
 (0)