From 44829f13d18e676917fc6e7b7ae62d4bac625cd7 Mon Sep 17 00:00:00 2001 From: Matthias Geier Date: Wed, 24 Nov 2021 22:15:22 +0100 Subject: [PATCH] Escape tags in JSON data --- src/nbsphinx.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/nbsphinx.py b/src/nbsphinx.py index b16977c7..07cf5168 100644 --- a/src/nbsphinx.py +++ b/src/nbsphinx.py @@ -795,7 +795,12 @@ def replace_attachments(text): 'save_attachments': save_attachments, 'replace_attachments': replace_attachments, 'get_output_type': _get_output_type, - 'json_dumps': json.dumps, + 'json_dumps': lambda s: re.sub( + r'<(/script)', + r'<\\\1', + json.dumps(s), + flags=re.IGNORECASE, + ), 'basename': os.path.basename, 'dirname': os.path.dirname, })