diff --git a/docs/changelog.rst b/docs/changelog.rst index 14611048a..d6e9c096e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -24,6 +24,9 @@ License (`#342 `_) * Improvement: Added option ``json_path`` for :ref:`needs_external_needs` to support external needs from local ``needs.json`` files. (`#339 `_) +* Improvement: Providing :ref:`needs_table_classes` to allow to set custom table css classes, to better support + themes like ReadTheDocs. + (`#305 `_) 0.7.1 ----- diff --git a/docs/configuration.rst b/docs/configuration.rst index d067c1389..ac872aa74 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -1209,6 +1209,21 @@ keys: The related css class definition must be done by the user, e.g. by :ref:`own_css`. (*optional*) (*default*: ``external_link``) +.. _needs_table_classes: + +needs_table_classes +~~~~~~~~~~~~~~~~~~~ +.. versionadded:: 0.7.2 + +Allows to define custom CSS classes, which get set for the HTML tables of ``need`` and ``needtable``. +This may be needed to avoid custom table handling of some specific Sphinx theme like ReadTheDocs. + +.. code-block:: rst + + needs_table_classes = ['my_custom_class', 'another_class'] + +Default: ``['rtd-exclude-wy-table']`` + .. _needs_builder_filter: diff --git a/sphinxcontrib/needs/css/common.css b/sphinxcontrib/needs/css/common.css index bb6e72356..756df8d9a 100644 --- a/sphinxcontrib/needs/css/common.css +++ b/sphinxcontrib/needs/css/common.css @@ -4,23 +4,6 @@ table.need td { white-space: normal; } -/* Needed for RTD theme. -Manipulates it for EVERY table, so also none sphinx-needs tables -Another solution would be to use JS, to address only divs, which have a sphinx-needs table as child.*/ -div.wy-table-responsive { - overflow: unset; - margin-bottom: unset; -} - /* Bringing Head and content columns align*/ - /*solution from https://datatables.net/forums/discussion/comment/72586/#Comment_72586*/ -/*table.dataTable,*/ -/*table.dataTable thead th,*/ -/*table.dataTable tbody td {*/ -/* -webkit-box-sizing: content-box;*/ -/* -moz-box-sizing: content-box;*/ -/* box-sizing: content-box;*/ -/*}*/ - table.NEEDS_TABLE { display: block; overflow-x: auto; @@ -44,6 +27,12 @@ table.need tr.footer div.line-block { margin-bottom: 0; } +/* START CUSTOM ReadTheDocs theming css START */ +div.dataTables_scrollHeadInner > table.rtd-exclude-wy-table { + margin-bottom: 0px; +} +/* END CUSTOM ReadTheDocs theming css START */ + .toggle .header { display: block; clear: both; diff --git a/sphinxcontrib/needs/directives/needtable.py b/sphinxcontrib/needs/directives/needtable.py index f8a349728..3fa38b2ac 100644 --- a/sphinxcontrib/needs/directives/needtable.py +++ b/sphinxcontrib/needs/directives/needtable.py @@ -135,6 +135,8 @@ def process_needtables(app, doctree, fromdocname): # Prepare table classes = ["NEEDS_{style}".format(style=style)] + classes.extend(app.config.needs_table_classes) + content = nodes.table(classes=classes) tgroup = nodes.tgroup() diff --git a/sphinxcontrib/needs/layout.py b/sphinxcontrib/needs/layout.py index 5cbcba493..e5bc3b2a2 100644 --- a/sphinxcontrib/needs/layout.py +++ b/sphinxcontrib/needs/layout.py @@ -155,7 +155,9 @@ def __init__(self, app, need, layout, node, style=None, fromdocname=None): else: self.fromdocname = fromdocname + # For ReadTheDocs Theme we need to add 'rtd-exclude-wy-table'. classes = ["need", "needs_grid_" + self.layout["grid"], "needs_layout_" + self.layout_name] + classes.extend(app.config.needs_table_classes) self.style = style or self.need["style"] or getattr(self.app.config, "needs_default_style", None) diff --git a/sphinxcontrib/needs/needs.py b/sphinxcontrib/needs/needs.py index ecd340999..e0ec19947 100644 --- a/sphinxcontrib/needs/needs.py +++ b/sphinxcontrib/needs/needs.py @@ -208,6 +208,9 @@ 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]) + # Define nodes app.add_node(Need, html=(html_visit, html_depart), latex=(latex_visit, latex_depart)) app.add_node(