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

Add custom HTML/CSS for galleries #706

Merged
merged 5 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/a-normal-rst-file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ __ https://www.sphinx-doc.org/en/master/usage/restructuredtext/

.. note::

The notes regarding LaTeX in :ref:`/subdir/gallery.ipynb`
The notes regarding LaTeX in :ref:`/gallery/gallery-with-nested-documents.ipynb`
and :ref:`/subdir/toctree.ipynb` also apply here!

The following example gallery was created using:
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
'nbsphinx',
'sphinxcontrib.bibtex', # for bibliographic references
'sphinxcontrib.rsvgconverter', # for SVG->PDF conversion in LaTeX output
'sphinx_gallery.load_style', # load CSS for gallery (needs SG >= 0.6)
'sphinx_last_updated_by_git', # get "last updated" from Git
'sphinx_codeautolink', # automatic links from code to documentation
'sphinx.ext.intersphinx', # links to other Sphinx projects (e.g. NumPy)
Expand Down Expand Up @@ -37,6 +36,7 @@
nbsphinx_thumbnails = {
'gallery/thumbnail-from-conf-py': 'gallery/a-local-file.png',
'gallery/*-rst': 'images/notebook_icon.png',
'orphan': '_static/favicon.svg',
}

# This is processed by Jinja2 and inserted before each notebook
Expand Down
3 changes: 1 addition & 2 deletions doc/configuration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@
" for [SVG->PDF conversion in LaTeX output](markdown-cells.ipynb#SVG-support-for-LaTeX)\n",
"* `'sphinx_copybutton'`\n",
" for [adding \"copy to clipboard\" buttons](https://sphinx-copybutton.readthedocs.io/)\n",
" to all text/code boxes\n",
"* `'sphinx_gallery.load_style'` to load CSS styles for [thumbnail galleries](subdir/gallery.ipynb)"
" to all text/code boxes"
]
},
{
Expand Down
1 change: 0 additions & 1 deletion doc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pandas
sphinxcontrib-bibtex>=2.1
sphinxcontrib-svg2pdfconverter
ipywidgets
sphinx-gallery<0.11 # https://github.com/spatialaudio/nbsphinx/issues/655
jupytext
sphinx-last-updated-by-git
sphinx-codeautolink
Expand Down
43 changes: 9 additions & 34 deletions doc/subdir/gallery.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,16 @@
"you can create thumbnail galleries from a list of Jupyter notebooks\n",
"(or other Sphinx source files).\n",
"\n",
"`nbsphinx` does *not* provide any gallery styles,\n",
"but you can easily use the styles from Sphinx-Gallery\n",
"by installing it:\n",
"\n",
" python3 -m pip install sphinx-gallery\n",
"\n",
"... and loading the styles in your `conf.py` with:\n",
"\n",
"```python\n",
"extensions = [\n",
" 'nbsphinx',\n",
" 'sphinx_gallery.load_style',\n",
" # more extensions, if needed ...\n",
"]\n",
"```\n",
"\n",
"You'll need Sphinx-Gallery version 0.6 or higher.\n",
"\n",
"<div class=\"alert alert-info\">\n",
"\n",
"Note\n",
"\n",
"Sphinx-Gallery has changed its CSS classes in version 0.11\n",
"in an incompatible way (see [issue #655](https://github.com/spatialaudio/nbsphinx/issues/655)).\n",
"To restore the intended look, update your dependencies\n",
"to an older version:\n",
"\n",
" sphinx-gallery<0.11\n",
"\n",
"</div>\n",
"\n",
"However, you can also create your own CSS styles if you prefer\n",
"(then you don't need to install Sphinx-Gallery).\n",
"You can load your CSS files with\n",
"`nbsphinx` provides CSS styles for galleries,\n",
"but like all styles you can tweak them\n",
"with your own CSS files loaded via\n",
"[html_css_files](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_css_files).\n",
"If you want to disable all the original styling,\n",
"you can create a file named `nbsphinx-gallery.css` somewhere in your\n",
"[html_static_path](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_static_path),\n",
"which will replace the original CSS file\n",
"(adding it to `html_css_files` is not necessary in this case,\n",
"because it is automatically added by `nbsphinx`).\n",
"\n",
"The following sections present\n",
"two different ways of creating thumbnail galleries\n",
Expand Down
10 changes: 8 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# "import" __version__
__version__ = 'unknown'
with Path('src/nbsphinx.py').open() as f:
with Path('src/nbsphinx/__init__.py').open() as f:
for line in f:
if line.startswith('__version__'):
exec(line)
Expand All @@ -14,7 +14,13 @@
name='nbsphinx',
version=__version__,
package_dir={'': 'src'},
py_modules=['nbsphinx'],
packages=['nbsphinx'],
package_data={'nbsphinx': [
'_static/nbsphinx-code-cells.css_t',
'_static/nbsphinx-gallery.css',
'_static/nbsphinx-no-thumbnail.svg',
'_static/nbsphinx-broken-thumbnail.svg',
]},
python_requires='>=3.6',
install_requires=[
'docutils',
Expand Down
Loading