Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot generate .html from ipynb with Jupyter state JSON including </script> #8433

Closed
cscheid opened this issue Jan 25, 2024 · 0 comments · Fixed by #8434
Closed

Cannot generate .html from ipynb with Jupyter state JSON including </script> #8433

cscheid opened this issue Jan 25, 2024 · 0 comments · Fixed by #8434
Assignees
Labels
bug Something isn't working jupyter
Milestone

Comments

@cscheid
Copy link
Collaborator

cscheid commented Jan 25, 2024

#7968 (reply in thread)

The problem, specifically, is that pyvista is emitting a widget state that includes the specific string </script>. We are following the recommended approach here: https://ipywidgets.readthedocs.io/en/7.x/embedding.html which is to create a script tag and embed the JSON text.

We do that. Unfortunately, this widget state cannot have the </script> string, because that causes the outer <script type="application/vnd.jupyter.widget-state+json"> to close.

In my original comment, I wrote:

If ipywidgets allows us to emit this JSON in an escaped way so that it can have the string </script> in it, then we can fix the bug on our side (but I can't see a way to do that in the documentation). But unfortunately this looks like something we can't fix on our side.

But I think I know a way around it. Here's a funny way to create a script tag with the string </script> inside it:

<html>
<head>
    <script>
        const scriptTag = document.createElement('script');
        scriptTag.type = "application/json";
        scriptTag.innerText = JSON.stringify({
            "src": "<script></" + "script>"
        });
        document.head.appendChild(scriptTag);
    </script>
</head>
<body>
</body>
</html>

So we can adapt this to create a script tag that self-expands into a JSON script tag that safely contains the string </script>.

@cscheid cscheid added bug Something isn't working jupyter labels Jan 25, 2024
@cscheid cscheid added this to the v1.5 milestone Jan 25, 2024
@cscheid cscheid self-assigned this Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working jupyter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant