Sphinx Panels
sphinx-panels is a Sphinx extension that enables creating responsive panel layouts in reStructuredText or MyST Markdown. It allows arranging content into cards, grids, and more, leveraging Bootstrap-like CSS. The current version is 0.6.0, with releases occurring intermittently based on feature development and bug fixes.
Common errors
-
WARNING: Unknown directive type "panel".
cause The `sphinx_panels` extension has not been enabled in your Sphinx project's `conf.py` file.fixAdd `'sphinx_panels'` to the `extensions` list in your Sphinx `conf.py` file. -
Invalid option block for 'grid' directive: not a block sequence. (or similar for syntax errors)
cause Incorrect option syntax for a `grid`, `panel`, or other `sphinx-panels` directive, especially if migrating from older versions (pre-0.3.0).fixCheck the official `sphinx-panels` documentation for the correct option syntax for your version. Ensure options are correctly indented and formatted (e.g., `key: value` for structured options). -
Panels are not rendering correctly, appearing unstyled, or stacking vertically instead of in a grid.
cause The CSS files for `sphinx-panels` might not be loading correctly, or there are significant CSS conflicts with your chosen Sphinx theme.fixVerify that `sphinx-panels` is correctly enabled in `conf.py`. Use your browser's developer tools to check if `sphinx-panels` CSS files are being loaded and if there are any console errors related to CSS. If theme conflicts are suspected, consider adding custom CSS overrides or testing with a default theme like `alabaster` or `furo`.
Warnings
- breaking Prior to v0.2.0, sphinx-panels underwent a 'Major Revamp'. The CSS classes and internal structure for panels were significantly different. Existing `.. panel::` directives or custom CSS relying on pre-0.2.0 structure may break.
- breaking In v0.3.0, the option syntax for directives like `.. panel::` or `.. grid::` was improved. Older, less explicit syntax might no longer be parsed correctly, leading to build failures or incorrect rendering.
- gotcha Some Sphinx themes may have CSS rules that conflict with `sphinx-panels`, especially regarding button styling or general layout, leading to unexpected rendering or overridden styles.
Install
-
pip install sphinx-panels
Imports
- Extension activation
from sphinx_panels import ...
extensions = ['sphinx_panels']
Quickstart
# conf.py
project = 'My Panel Project'
copyright = '2024, Your Name'
extensions = [
'sphinx.ext.autodoc',
'sphinx_panels' # Enable the extension
]
html_theme = 'alabaster'
# example.rst (or .md if using MyST)
# .. grid:: 1 2 2 3
# :gutter: 2
#
# .. grid-item-card:: Card Title 1
# :shadow: sm
#
# This is the content for the first card.
#
# .. grid-item-card:: Card Title 2
# :shadow: sm
#
# This is the content for the second card.
#
# .. grid-item-card:: Card Title 3
# :shadow: sm
#
# This is the content for the third card.