Skip to content

Commit

Permalink
Adds specific handling for material theme
Browse files Browse the repository at this point in the history
Fixes #306
  • Loading branch information
danwos committed Sep 23, 2021
1 parent 38f3fe2 commit 7019e0f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
21 changes: 20 additions & 1 deletion docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,26 @@ This may be needed to avoid custom table handling of some specific Sphinx theme
needs_table_classes = ['my_custom_class', 'another_class']
Default: ``['rtd-exclude-wy-table']``
Default: ``['rtd-exclude-wy-table', 'no-sphinx-material-strip']``
This classes are not set for needtables using the ``table`` style, which is using the normal Sphinx table layout
and therefore must be handled by themes.
The following themes support the following table classes to deactivate their specific handling:
.. list-table::
- * Theme
* Class
- * ReadTheDocs
* ``rtd-exclude-wy-table``
- * Sphinx-Material
* ``no-sphinx-material-strip``
.. hint::
The deactivation of theme specific table handling is quite a new feature in most themes.
Please be sure to use the newest theme version or even the nightly build.
.. _needs_builder_filter:
Expand Down
2 changes: 2 additions & 0 deletions sphinxcontrib/needs/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,5 @@
NEEDEXTEND_NOT_ALLOWED_OPTIONS = ["id"]

NEEDS_PROFILING = [x.upper() for x in os.environ.get("NEEDS_PROFILING", "").split(",")]

NEEDS_TABLES_CLASSES = ["rtd-exclude-wy-table", "no-sphinx-material-strip"]
8 changes: 7 additions & 1 deletion sphinxcontrib/needs/directives/needtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def process_needtables(app, doctree, fromdocname):
if not app.config.needs_include_needs:
# Ok, this is really dirty.
# If we replace a node, docutils checks, if it will not lose any attributes.
# If we replace a node, docutils checks, if it will not lose any attributes.
# But this is here the case, because we are using the attribute "ids" of a node.
# However, I do not understand, why losing an attribute is such a big deal, so we delete everything
# before docutils claims about it.
Expand All @@ -142,7 +143,12 @@ def process_needtables(app, doctree, fromdocname):

# Prepare table
classes = ["NEEDS_{style}".format(style=style)]
classes.extend(app.config.needs_table_classes)

# Only add the theme specific "do not touch this table" class, if we use a style which
# care about table layout and styling. The normal "TABLE" style is using the Sphinx default table
# css classes and therefore must be handled by the themes.
if style != "TABLE":
classes.extend(app.config.needs_table_classes)

content = nodes.table(classes=classes)
tgroup = nodes.tgroup()
Expand Down
3 changes: 2 additions & 1 deletion sphinxcontrib/needs/needs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
NEED_DEFAULT_OPTIONS,
NEEDEXTEND_NOT_ALLOWED_OPTIONS,
NEEDFLOW_CONFIG_DEFAULTS,
NEEDS_TABLES_CLASSES,
)
from sphinxcontrib.needs.directives.need import (
Need,
Expand Down Expand Up @@ -213,7 +214,7 @@ def setup(app):
app.add_config_value("needs_builder_filter", "is_external==False", "html", types=[str])

# Additional classes to set for needs and needtable.
app.add_config_value("needs_table_classes", ["rtd-exclude-wy-table"], "html", types=[list])
app.add_config_value("needs_table_classes", NEEDS_TABLES_CLASSES, "html", types=[list])

# Define nodes
app.add_node(Need, html=(html_visit, html_depart), latex=(latex_visit, latex_depart))
Expand Down

0 comments on commit 7019e0f

Please sign in to comment.