Skip to content

Fix html repr in untrusted notebooks (plain text fallback) #4053

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

Merged
merged 4 commits into from
May 20, 2020

Conversation

benbovy
Copy link
Member

@benbovy benbovy commented May 12, 2020

This is not very elegant (actually plain text repr is already included in the notebook as text/plain mime type but it is ignored when text/html mime type is present), but it seems to work. I haven't found a better workaround.

I don't really know if this can be properly tested (I only added a basic test).

Steps to test this fix:

  • To "untrust" a notebook: open an existing notebook with a simple editor, manually edit one output cell with a xarray object repr, and save the ipynb file.
  • Open this notebook with the Notebook app, you should see the plain text repr.

benbovy added 4 commits May 12, 2020 09:15
The PRE element is not displayed when CSS is injected.

When CSS is not injected (untrusted notebook), the PRE element
is shown but not the DIV container used for the HTML repr.
Prevent showing those when fallback to plain text repr.

A title tag is already present in the HTML label elements.
@shoyer
Copy link
Member

shoyer commented May 12, 2020

I tested this out exporting a notebook to Github:
https://gist.github.com/shoyer/6ee36acd164116fee4681f6237ca5249

Here's what I see:
image

Somehow we get both text and malformed HTML? :(

It's definitely still an improvement over what we had before, though.

@benbovy
Copy link
Member Author

benbovy commented May 12, 2020

Mmm it looks like Github's notebook renderer removes the hidden attribute of the xr-wrap div in addition to removing CSS. That's unfortunate.

I tested this workaround in jupyterlab, classic notebook and nbviewer. It works as expected. I haven't tested other front-ends (Colab, vscode, etc.).

@shoyer
Copy link
Member

shoyer commented May 12, 2020

I sent a support request to GitHub asking for supporting the hidden attribute. We'll see if we get a response!

Copy link
Member

@shoyer shoyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully GitHub will fix their rendering issue, but this is a step in the right direction!

@dcherian
Copy link
Contributor

Thanks @benbovy

@dcherian dcherian merged commit cb90d55 into pydata:master May 20, 2020
@dcherian
Copy link
Contributor

just confirmed that the fallback works perfectly. Thanks @benbovy !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

expanded HTML repr when opening notebook
3 participants