Skip to content

Commit

Permalink
Wrap tables in scrollable div (pydata#1827)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabalafou authored and ivanov committed Jun 4, 2024
1 parent d9daaa5 commit ac840ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/pydata_sphinx_theme/assets/styles/content/_tables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ td {
--pst-color-text-base
); // ensure text and bullets are visible
}

.pst-scrollable-table-container {
// Put a scrollbar just below tables that are too wide to fit within the main
// column
overflow-x: auto;
}
8 changes: 8 additions & 0 deletions src/pydata_sphinx_theme/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,17 @@ def visit_table(self, node):
if "align" in node:
classes.append(f'table-{node["align"]}')

# put table within a scrollable container (for tables that are too wide)
self.body.append('<div class="pst-scrollable-table-container">')

tag = self.starttag(node, "table", CLASS=" ".join(classes), **atts)
self.body.append(tag)

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


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

0 comments on commit ac840ad

Please sign in to comment.