Skip to content

Commit ac840ad

Browse files
gabalafouivanov
authored andcommitted
Wrap tables in scrollable div (pydata#1827)
Fixes pydata#1824
1 parent d9daaa5 commit ac840ad

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/pydata_sphinx_theme/assets/styles/content/_tables.scss

+6
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,9 @@ td {
5555
--pst-color-text-base
5656
); // ensure text and bullets are visible
5757
}
58+
59+
.pst-scrollable-table-container {
60+
// Put a scrollbar just below tables that are too wide to fit within the main
61+
// column
62+
overflow-x: auto;
63+
}

src/pydata_sphinx_theme/translator.py

+8
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,17 @@ def visit_table(self, node):
8181
if "align" in node:
8282
classes.append(f'table-{node["align"]}')
8383

84+
# put table within a scrollable container (for tables that are too wide)
85+
self.body.append('<div class="pst-scrollable-table-container">')
86+
8487
tag = self.starttag(node, "table", CLASS=" ".join(classes), **atts)
8588
self.body.append(tag)
8689

90+
def depart_table(self, node):
91+
"""Custom depart_table method to close the scrollable div we add in visit_table."""
92+
super().depart_table(node)
93+
self.body.append("</div>\n")
94+
8795

8896
def setup_translators(app: Sphinx):
8997
"""Add bootstrap HTML functionality if we are using an HTML translator.

0 commit comments

Comments
 (0)