Skip to content

Commit 6e0ef82

Browse files
authored
Merge pull request #120 from danwos/danwos_table_strip
Theme option fo deactivating table handling
2 parents 8aba3ac + 9c5df4a commit 6e0ef82

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

docs/customization.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ Configuration Options
103103
``table_classes``
104104
A list of classes to **not strip** from tables. All other classes are stripped, and the default
105105
table has no class attribute. Custom table classes need to provide the full style for the table.
106-
106+
``table_no_strip``
107+
A list of classes to deactivate the complete table handling by sphinx-material for this specific table,
108+
so that all set table classes are kept.
109+
Default value: ``no-sphinx-material-strip``.
107110
Sidebars
108111
========
109112

sphinx_material/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
ROOT_SUFFIX = "--page-root"
2323

2424
USER_TABLE_CLASSES = []
25+
USER_TABLE_NO_STRIP_CLASSES = ["no-sphinx-material-strip"]
2526

2627

2728
def setup(app):
@@ -150,6 +151,10 @@ def update_table_classes(app, config):
150151
if table_classes:
151152
USER_TABLE_CLASSES.extend(table_classes)
152153

154+
table_no_strip_classes = config.html_theme_options.get("table_no_strip")
155+
if table_no_strip_classes:
156+
USER_TABLE_NO_STRIP_CLASSES.extend(table_no_strip_classes)
157+
153158

154159
def html_theme_path():
155160
return [os.path.dirname(os.path.abspath(__file__))]
@@ -228,7 +233,9 @@ def walk_contents(tags):
228233

229234
def table_fix(body_text, page_name="md-page-root--link"):
230235
# This is a hack to skip certain classes of tables
231-
ignore_table_classes = {"highlighttable", "longtable", "dataframe"}
236+
ignore_table_classes = {"highlighttable", "longtable", "dataframe"} | set(
237+
USER_TABLE_NO_STRIP_CLASSES
238+
)
232239
try:
233240
body = BeautifulSoup(body_text, features="html.parser")
234241
for table in body.select("table"):

sphinx_material/sphinx_material/theme.conf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,9 @@ version_json = "versions.json"
109109
# Table classes to _not_ strip. Must be a list. Classes on this list are *not*
110110
# removed from tables. All other classes are removed, and only tables with outclasses
111111
# are styled by default.
112-
table_classes =
112+
table_classes =
113+
114+
# Table classes, which deactivates the overall class striping. If one of the configured
115+
# classes is set, **all** table classes are kept.
116+
# This is different to "table_classes", which only keeps the configured classes.
117+
table_no_strip =

0 commit comments

Comments
 (0)