Skip to content

Commit

Permalink
Merge pull request #120 from danwos/danwos_table_strip
Browse files Browse the repository at this point in the history
Theme option fo deactivating table handling
  • Loading branch information
bashtage authored Oct 6, 2021
2 parents 8aba3ac + 9c5df4a commit 6e0ef82
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion docs/customization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
========

Expand Down
9 changes: 8 additions & 1 deletion sphinx_material/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
ROOT_SUFFIX = "--page-root"

USER_TABLE_CLASSES = []
USER_TABLE_NO_STRIP_CLASSES = ["no-sphinx-material-strip"]


def setup(app):
Expand Down Expand Up @@ -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__))]
Expand Down Expand Up @@ -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"):
Expand Down
7 changes: 6 additions & 1 deletion sphinx_material/sphinx_material/theme.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
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 =

0 comments on commit 6e0ef82

Please sign in to comment.