Sphinx Design
Sphinx Design is a Sphinx extension that provides a rich set of directives and roles for creating modern, responsive, and visually appealing web components within your documentation. It offers features like cards, grids, dropdowns, tabs, and icon support. The library is actively maintained with frequent updates, often aligning with new Sphinx and Python releases, ensuring compatibility and introducing new design capabilities.
Warnings
- breaking Python version compatibility changes frequently with major `sphinx-design` releases. For example, v0.7.0 dropped support for Python 3.9 and 3.10.
- breaking Sphinx version compatibility is strictly managed. `sphinx-design` often drops support for older Sphinx versions while adding support for newer ones.
- gotcha Icon sets (Material Design Icons, Octicons) are periodically updated, which may change available icons or require updates to existing icon names.
- gotcha The `sd_custom_directives` configuration option, allowing definition of custom directives with default options, was introduced in v0.6.0. Users on older versions cannot use this feature.
Install
-
pip install sphinx-design
Imports
- sphinx_design
extensions = ['sphinx_design']
Quickstart
import os
def create_minimal_conf_py():
conf_content = '''
project = 'My Design Docs'
copyright = '2023, Author'
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx_design'
]
html_theme = 'furo'
'''
with open('conf.py', 'w') as f:
f.write(conf_content)
# In a real scenario, you'd then create an index.rst or index.md like this:
# with open('index.rst', 'w') as f:
# f.write('''
# My Design Docs
# ==============
#
# .. dropdown:: Click Me!
# :color: primary
#
# This is a dropdown content block.
#
# .. card:: Feature Card
# :shadow: lg
# :text-align: center
#
# A simple card to highlight information.
#
# :::{link-button} https://example.com
# Visit Example
# :::
# ''')
print("Generated conf.py with sphinx_design extension enabled.")
print("To use directives, add them to your .rst or .md files (e.g., dropdown, card, grid).")
if __name__ == '__main__':
create_minimal_conf_py()