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

Dark theme broken when notebook contains widgets in metadata #1506

Closed
cnydw opened this issue Jan 26, 2021 · 2 comments · Fixed by jupyter-widgets/ipywidgets#3342
Closed

Comments

@cnydw
Copy link

cnydw commented Jan 26, 2021

I followed the guide on https://blog.jupyter.org/the-templating-system-of-nbconvert-6-47ea781eacd2 to convert my notebooks to HTML with dark theme, using

jupyter nbconvert xleaflet.ipynb --to html --HTMLExporter.theme=dark

However some of the converted notebooks have the dark theme style for about 0.5 second, then the HTML page turns to the white theme automatically.
After some investigation I found out that it's only happening to the notebooks with widgets state in the metadata, which makes nbconvert add the following code snippet to the HTML page,

<script>
(function() {
function addWidgetsRenderer() {
var mimeElement = document.querySelector('script[type="application/vnd.jupyter.widget-view+json"]');
var scriptElement = document.createElement('script');
var widgetRendererSrc = '{{ widgets_cdn_url }}@jupyter-widgets/html-manager@{{ html_manager_semver_range }}/dist/embed-amd.js';
var widgetState;
// Fallback for older version:
try {
widgetState = mimeElement && JSON.parse(mimeElement.innerHTML);
if (widgetState && (widgetState.version_major < 2 || !widgetState.version_major)) {
widgetRendererSrc = '{{ widgets_cdn_url }}jupyter-js-widgets@*/dist/embed.js';
}
} catch(e) {}
scriptElement.src = widgetRendererSrc;
document.body.appendChild(scriptElement);
}
document.addEventListener('DOMContentLoaded', addWidgetsRenderer);
}());
</script>

which in turn breaks the dark theme by updating the CSS properties.

Nbconvert version:

6.0.7

@italodamato
Copy link

I have the same issue. Did you find a workaround? @cnydw

@martinRenou
Copy link
Member

I suspect this is an issue with ipywidgets itself: jupyter-widgets/ipywidgets#3340, we should probably close this issue

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 a pull request may close this issue.

3 participants