Skip to content

Commit

Permalink
Use findall from docutils only if it's available
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg committed Jun 12, 2022
1 parent bb3c355 commit 2365493
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/furo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,18 @@ class WrapTableAndMathInAContainerTransform(SphinxPostTransform):

def run(self, **kwargs: Any) -> None:
"""Perform the post-transform on `self.document`."""
for node in list(self.document.findall(nodes.table)):
get_nodes = (
self.document.findall # docutils 0.18+
if hasattr(self.document, "findall")
else self.document.traverse # docutils <= 0.17.x
)
for node in list(get_nodes(nodes.table)):
new_node = nodes.container(classes=["table-wrapper"])
new_node.update_all_atts(node)
node.parent.replace(node, new_node)
new_node.append(node)

for node in list(self.document.findall(nodes.math_block)):
for node in list(get_nodes(nodes.math_block)):
new_node = nodes.container(classes=["math-wrapper"])
new_node.update_all_atts(node)
node.parent.replace(node, new_node)
Expand Down

0 comments on commit 2365493

Please sign in to comment.