From 0795cbf4f10c820971da3a35d7c887dfcdd16354 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 Fixes #119 --- sphinx_material/__init__.py | 8 +++++++- sphinx_material/sphinx_material/theme.conf | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/sphinx_material/__init__.py b/sphinx_material/__init__.py index 93a64f9f8..108c140b5 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,8 @@ 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 =