From 852350bd7d0f3ac30328f8f81fc6ac70e08905f9 Mon Sep 17 00:00:00 2001 From: Daniel Woste Date: Tue, 24 Aug 2021 12:52:23 +0200 Subject: [PATCH] Adds "needs_table_classe" config option Fixes #305 --- docs/changelog.rst | 4 ++++ docs/configuration.rst | 21 ++++++++++++++++--- sphinxcontrib/needs/css/common.css | 23 ++++++--------------- sphinxcontrib/needs/directives/needtable.py | 2 ++ sphinxcontrib/needs/layout.py | 5 ++++- sphinxcontrib/needs/needs.py | 3 +++ 6 files changed, 37 insertions(+), 21 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 3d31cc4ce..58ff75939 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -18,6 +18,10 @@ License (`#344 `_) * Improvement: Providing :ref:`needs_warnings_always_warn` to raise sphinx-warnings for each not passed :ref:`needs_warnings`. (`#344 `_) +* 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 c8d41a2a3..2bebf7d85 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -993,7 +993,7 @@ Due to the nature of sphinx logging, a sphinx-warning may be printed wherever in needs_warnings_always_warn ~~~~~~~~~~~~~~~~~~~~~~~~~~ -This option if set to ``True``, will allow to log not passed :ref:`needs_warnings` into a given file if using your sphinx build +This option if set to ``True``, will allow to log not passed :ref:`needs_warnings` into a given file if using your sphinx build command with ``-w``. Default: ``False``. @@ -1004,10 +1004,10 @@ For example, set this option to True: needs_warnings_always_warn = True -Using sphinx build command ``sphinx-build -M html {srcdir} {outdir} -w error.log``, all the not passed :ref:`needs_warnings` will be +Using sphinx build command ``sphinx-build -M html {srcdir} {outdir} -w error.log``, all the not passed :ref:`needs_warnings` will be logged into file error.log as you specified. -If use ``sphinx-build -M html {srcdir} {outdir} -W -w error.log``, the first not passed :ref:`needs_warnings` will stop the build and +If use ``sphinx-build -M html {srcdir} {outdir} -W -w error.log``, the first not passed :ref:`needs_warnings` will stop the build and be logged into the file error.log. .. _needs_layouts: @@ -1206,6 +1206,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']`` + Removed options --------------- 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..fa3bbb4f5 100644 --- a/sphinxcontrib/needs/layout.py +++ b/sphinxcontrib/needs/layout.py @@ -155,7 +155,10 @@ def __init__(self, app, need, layout, node, style=None, fromdocname=None): else: self.fromdocname = fromdocname - classes = ["need", "needs_grid_" + self.layout["grid"], "needs_layout_" + self.layout_name] + # 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 01f088786..bc022c33b 100644 --- a/sphinxcontrib/needs/needs.py +++ b/sphinxcontrib/needs/needs.py @@ -206,6 +206,9 @@ def setup(app): app.add_config_value("needs_external_needs", [], "html") + # 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(