Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme option fo deactivating table handling #120

Merged
merged 1 commit into from Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/customization.rst
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
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
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 =