Skip to content

Commit c07a84e

Browse files
Handle new sphx-gallery format (#1599)
After the update to Sphinx, Sphinx Gallery now outputs a different format for generated code blocks, where the code block is now part of an entirely separate element and no longer nested in `rst-class` directive. This PR adds a fix to be able to handle both the new and old `sphx-glr-script-out` formats. It has been tested on #1592 .
1 parent c6c2db3 commit c07a84e

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/filter_directives.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ def filter_directives(key, value, format, _):
1818
return []
1919
elif "rst-class" in classes:
2020
metadata = body[0]
21-
content = body[1]
2221
rst_class_type = metadata.get("c")[0].get("c")
2322
if rst_class_type == "sphx-glr-script-out":
24-
return content
23+
if len(body) == 1:
24+
# This is the new format for sphx-glr-script-out.
25+
# Just discard this block.
26+
return []
27+
return body[1]
2528
else:
2629
return
2730
else:

lib/filter_tables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ def filter_tables(key, value, format, _):
7070
[[_, classes, _], body] = value
7171
if "rst-class" in classes:
7272
metadata = body[0]
73-
content = body[1]
7473
rst_class_type = metadata.get("c")[0].get("c")
7574
if rst_class_type == "docstable":
7675
caption = []
76+
content = body[1]
7777
if len(body) > 2:
7878
caption.append(body[2])
7979
return make_markdown_table(content.get("c"), caption)

0 commit comments

Comments
 (0)