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 =