Skip to content

Commit

Permalink
Adds "needs_table_classe" config option
Browse files Browse the repository at this point in the history
Fixes #305
  • Loading branch information
danwos committed Aug 25, 2021
1 parent 997b203 commit e7dce70
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ License
(`#342 <https://github.com/useblocks/sphinxcontrib-needs/issues/342>`_)
* Improvement: Added option ``json_path`` for :ref:`needs_external_needs` to support external needs from local ``needs.json`` files.
(`#339 <https://github.com/useblocks/sphinxcontrib-needs/issues/339>`_)
* Improvement: Providing :ref:`needs_table_classes` to allow to set custom table css classes, to better support
themes like ReadTheDocs.
(`#305 <https://github.com/useblocks/sphinxcontrib-needs/issues/305>`_)

0.7.1
-----
Expand Down
15 changes: 15 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 6 additions & 17 deletions sphinxcontrib/needs/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions sphinxcontrib/needs/directives/needtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 2 additions & 0 deletions sphinxcontrib/needs/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions sphinxcontrib/needs/needs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit e7dce70

Please sign in to comment.