From 9c5df4a49df4fc09d8a5bcf46517b7af5dca0ee2 Mon Sep 17 00:00:00 2001 From: Daniel Woste Date: Thu, 23 Sep 2021 09:16:52 +0200 Subject: [PATCH] Theme option fo deactivating table handling Allows the user to define table classes, which deactivates the complete table handling by sphinx-material for this specific table. * Adds table_no_strip to theme.conf * Sets default value to no-sphinx-material-strip * Adds docs on customization page Fixes #119 --- docs/customization.rst | 5 ++++- sphinx_material/__init__.py | 9 ++++++++- sphinx_material/sphinx_material/theme.conf | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/customization.rst b/docs/customization.rst index ecf8dc0e6..02bc5cd16 100644 --- a/docs/customization.rst +++ b/docs/customization.rst @@ -103,7 +103,10 @@ Configuration Options ``table_classes`` A list of classes to **not strip** from tables. All other classes are stripped, and the default table has no class attribute. Custom table classes need to provide the full style for the table. - +``table_no_strip`` + A list of classes to deactivate the complete table handling by sphinx-material for this specific table, + so that all set table classes are kept. + Default value: ``no-sphinx-material-strip``. Sidebars ======== diff --git a/sphinx_material/__init__.py b/sphinx_material/__init__.py index 93a64f9f8..c00b8c9d0 100644 --- a/sphinx_material/__init__.py +++ b/sphinx_material/__init__.py @@ -22,6 +22,7 @@ ROOT_SUFFIX = "--page-root" USER_TABLE_CLASSES = [] +USER_TABLE_NO_STRIP_CLASSES = ["no-sphinx-material-strip"] def setup(app): @@ -150,6 +151,10 @@ def update_table_classes(app, config): if table_classes: USER_TABLE_CLASSES.extend(table_classes) + table_no_strip_classes = config.html_theme_options.get("table_no_strip") + if table_no_strip_classes: + USER_TABLE_NO_STRIP_CLASSES.extend(table_no_strip_classes) + def html_theme_path(): return [os.path.dirname(os.path.abspath(__file__))] @@ -228,7 +233,9 @@ def walk_contents(tags): def table_fix(body_text, page_name="md-page-root--link"): # This is a hack to skip certain classes of tables - ignore_table_classes = {"highlighttable", "longtable", "dataframe"} + ignore_table_classes = {"highlighttable", "longtable", "dataframe"} | set( + USER_TABLE_NO_STRIP_CLASSES + ) try: body = BeautifulSoup(body_text, features="html.parser") for table in body.select("table"): diff --git a/sphinx_material/sphinx_material/theme.conf b/sphinx_material/sphinx_material/theme.conf index 8d4fb59cf..c77b5e4fc 100644 --- a/sphinx_material/sphinx_material/theme.conf +++ b/sphinx_material/sphinx_material/theme.conf @@ -109,4 +109,9 @@ version_json = "versions.json" # Table classes to _not_ strip. Must be a list. Classes on this list are *not* # removed from tables. All other classes are removed, and only tables with outclasses # are styled by default. -table_classes = \ No newline at end of file +table_classes = + +# Table classes, which deactivates the overall class striping. If one of the configured +# classes is set, **all** table classes are kept. +# This is different to "table_classes", which only keeps the configured classes. +table_no_strip =