Closed Sillocan closed 1 year ago
You could've just uploaded the sample project as a zip file. That way I can download it, build it, and examine the HTML output myself.
We removed the nbsphinx
(& numpy
) stuff (in this repo) that was inherited from sphinx-material because it took an unreasonably long time to build and required some Linux-specific dependencies (IIRC)...
Fair point. I didn't even think of that for some reason. I'm attaching a zip. It does require a few odd things like pandoc, so I added a Dockerfile if desired. Should just be able to run docker-compose up
.
Update: On our instance of readthedocs, we don't get the text scrolling off the screen. So, that's probably not a big deal. But, unfortunately we do still get the extra line.
docker compose up
doesn't work for me. I'm not a proficient docker user, but it isn't completely foreign to me...
After installing pandoc (locally in windows in the user space - not global space for all users), I still can't build the sample.
At first glance, the output in the OP looks like a it might be suffering from the same problem that #46 had (which required a monkeypatch on sphinx to resolve). I just need to inspect the HTML to verify my suspicion. Do you have a link to your RTD project? Maybe I can inspect the HTML from there.
I finally got it to build with WSL Ubuntu (had to install pandoc from apt
since their release assets didn't include my WSL architecture, amd64)...
Still not sure what exactly is going on, but my suspicion seem to be right on track. The code snippets use an odd structure of <pre>
and <code>
elements. This isn't well supported in the mkdocs-material CSS (which we inherit with intentionally minimal alterations). Still investigating though.
Unfortunately it's a corporate edition. I can most likely dump to html if that would be helpful.
EDIT: Ah, glad to see you got it building.
Yeah so the really long text running off the screen is because it is structured as
<pre>super long text.................</pre>
where the theme's CSS expects this to be
<pre><code>super long text.................</code></pre>
But that doesn't explain why the input line numbers/statements appear as separate code blocks. I feel like it is supposed to be treated as a <table>
, but something is preventing that...
So far, this is pointing to a required patch in whatever extension is generating these specific HTML segments; it certainly isn't sphinx-immaterial
, so I'm guessing it is nbsphinx
.
There is a jupyter notebook extension for mkdocs that is specifically tested to work with mkdocs-material. It might be helpful to compare.
With a little tweaking to the HTML about the execution number (had to remove <code>
around [n]:
) and some CSS
.nbinput.docutils.container,
.nboutput.docutils.container {
display: flex;
}
.nbinput > .input_area ,
.nboutput > .output_area {
overflow: auto;
}
.nboutput > .prompt.empty.docutils.container {
padding: 0 2.25ex;
}
I was able to achieve this:
The CSS code is an easy fix, but we'll have to monkeypatch the nbsphinx
output to remove the <code>
tags around the execution numbers. The more I explore this, the more it feels extremely "hacky" (not robust); I'm sure there are other elements produced by nbsphinx
that the issue's sample doesn't use...
The mkdocs extension doesn't seem to support dark scheme very well. Try it on this demo page
Looks like nbsphinx uses a jinja template macro that inject a RST directive which adds the code elements around the "execution count". My first impression is that it isn't an easy monkey patch to produce.
Maybe we could elevate this to nbsphinx with a requested option to only add <pre></pre>
tags around execution count instead of <pre><code></code></pre>
.
Potentially another option would be to add a CSS rule to make <pre><code></code></pre>
work as the extension expects, but not sure how feasible that would be.
Seen as how the <pre>
vs <pre><code>
is similar to how production lists were broken, I'm very open to adjusting the theme CSS. But, both cases seem rather specific, so the adjusted CSS would have to be very selective. Also, I'm not sure if that would allow us repeal the monkeypatch solution for #46 as well.
There's also the inherited theme JS that attaches the copy-to-clipboard button on any <pre>
element that has a <code>
element within.
I just re-ran the sample with updates from nbsphinx (v0.9.1) and the only remaining issue is a rogue "copy-to-clipboard" icon injected by the theme JS for the execution count.
pip list
outputSo, I think this issue now only needs a special CSS rule to not display the injected copy button for nbsphinx execution count numbers:
.nbinput > .prompt > .highlight .md-clipboard.md-icon {
display: none;
}
But maybe we need to alter the theme JS. I'm not enthusiastic about this approach because the nbsphinx ext (technically in beta) could change output structure at anytime; this is evident by the fact that the original concerns in the OP have been satisfied in nbsphinx since v0.9.0 release.
Just to re-iterate, the real problem here exists in nbsphinx code https://github.com/spatialaudio/nbsphinx/blob/f1d3f728f979d77d0e1d356b3d51a2336a94f6dc/src/nbsphinx/__init__.py#L704-L705
where nodes.literal_block
generates a <pre><code>[n]:</code></pre>
which triggers our theme JS to inject a copy-to-clipboard button. But a <pre>[n]:</pre>
would be more desirable to avoid triggering the theme JS about the copy button.
This issue's full resolution is pending spatialaudio/nbsphinx#737.
I also raised some other issues about nbsphinx's CSS colors not compatible with both dark and light schemes (spatialaudio/nbsphinx#734 and spatialaudio/nbsphinx#733).
This issue can be closed now as we shouldn't need to compensate for nbsphinx. Keep in mind that there are other Jupyter notebook extensions for Sphinx, namely the more experimental myst-nb extension. I suspect other formatting issues might arise depending on the doc author's choice of extensions. We'll just have to address them appropriately as feedback is reported.
Please use nbsphinx v0.9.1 or newer with this theme.
Hi, I tried adding a jupyter notebook via
nbsphinx
to my docs usingsphinx-immaterial
as the theme. Unfortunately the formatting appears to be a bit broken in comparison to other themes such assphinx-material
. For some reason the input goes onto a separate line from the block indicator, and the output ends up trailing off the screen.I've created a minimal example below and am adding some screenshots with a comparison. I'm not sure if I am doing something wrong or if there is a formatting issue in the theme.
sphinx-immaterial
sphinx-material
Commands I am running:
File structure
``` README.md docs/ conf.py index.rst requirements.txt cookbooks/ cookbook.ipynb ``` README.md ```md ``` docs/conf.py ```python import os project = "Demo bug" master_doc = "index" sphinx_immaterial_external_resource_cache_dir = os.path.abspath("./.cache/external_resources") extensions = [ "m2r2", "sphinx.ext.autosectionlabel", "sphinx_immaterial", "sphinx_panels", "nbsphinx", "IPython.sphinxext.ipython_console_highlighting", "IPython.sphinxext.ipython_directive", ] html_theme = "sphinx_immaterial" html_theme_options = html_theme_options if "html_theme_options" in globals() else {} html_theme_options = { **html_theme_options, "icon": { "repo": "fontawesome/brands/gitlab", }, "repo_url": "https://foobar", "edit_uri": "edit/main/docs", "repo_name": "foo", "repo_type": "gitlab", "features": [ "navigation.expand", # "navigation.tabs", # "toc.integrate", "navigation.sections", # "navigation.instant", # "header.autohide", "navigation.top", "navigation.tracking", "search.highlight", "search.share", "toc.follow", "toc.sticky", "content.tabs.link", "announce.dismiss", ], "palette": [ { "media": "(prefers-color-scheme: light)", "scheme": "default", "primary": "indigo", "accent": "light-blue", "toggle": { "icon": "material/weather-sunny", "name": "Switch to dark mode", }, }, { "media": "(prefers-color-scheme: dark)", "scheme": "slate", "primary": "blue-grey", "accent": "light-blue", "toggle": { "icon": "material/weather-night", "name": "Switch to light mode", }, }, ], } ``` docs/index.rst ```rst .. mdinclude:: ../README.md .. toctree:: :caption: Cookbook :hidden: NotebookSee https://github.com/jbms/sphinx-immaterial/issues/218#issuecomment-1433922153 for a zipped sample project