@@ -60,6 +60,27 @@ def is_root_document(document: docutils.nodes.document, app: Sphinx) -> bool:
60
60
return app .project .path2doc (document ["source" ]) == app .config .master_doc
61
61
62
62
63
+ def is_cell (node : nodes .Node ) -> bool :
64
+ return (
65
+ isinstance (node , nodes .container )
66
+ and node .attributes .get ("nb_element" ) == "cell_code"
67
+ )
68
+
69
+
70
+ def is_input_cell (node : nodes .Node ) -> bool :
71
+ return (
72
+ isinstance (node , nodes .container )
73
+ and node .attributes .get ("nb_element" ) == "cell_code_source"
74
+ )
75
+
76
+
77
+ def is_output_cell (node : nodes .Node ) -> bool :
78
+ return (
79
+ isinstance (node , nodes .container )
80
+ and node .attributes .get ("nb_element" ) == "cell_code_output"
81
+ )
82
+
83
+
63
84
class LatexRootDocTransforms (SphinxTransform ):
64
85
"""Arrange the toctrees and sections in the required structure.
65
86
@@ -113,11 +134,7 @@ def check_dependency(cls) -> bool:
113
134
except ImportError :
114
135
return False
115
136
major , minor = __version__ .split ("." )[0 :2 ]
116
- if major == "0" and minor in (
117
- "11" ,
118
- "12" ,
119
- "13" ,
120
- ): # TODO: fetch this from pyproject.toml?
137
+ if major == "0" and minor in ("15" ): # TODO: fetch this from pyproject.toml?
121
138
return True
122
139
else :
123
140
logger .warning (
@@ -127,16 +144,14 @@ def check_dependency(cls) -> bool:
127
144
return False
128
145
129
146
def apply (self , ** kwargs : Any ) -> None :
130
- from myst_nb .nodes import CellInputNode , CellNode , CellOutputNode
131
-
132
- for node in self .document .traverse (CellNode ):
147
+ for node in self .document .traverse (is_cell ):
133
148
if "tag_hide-cell" in node ["classes" ]:
134
149
replace_node_cls (node , HiddenCellNode , True )
135
150
if "tag_hide-input" in node ["classes" ]:
136
- for input_node in node .traverse (CellInputNode ):
151
+ for input_node in node .traverse (is_input_cell ):
137
152
replace_node_cls (input_node , HiddenCellNode , True )
138
153
if "tag_hide-output" in node ["classes" ]:
139
- for output_node in node .traverse (CellOutputNode ):
154
+ for output_node in node .traverse (is_output_cell ):
140
155
replace_node_cls (output_node , HiddenCellNode , True )
141
156
142
157
@@ -425,14 +440,13 @@ class CodeBlockTransforms(SphinxPostTransform):
425
440
def apply (self ):
426
441
if isinstance (self .env .app .builder , builders .latex .LaTeXBuilder ):
427
442
"""Wrapping myst_nb code cell nodes with nodes of this extension."""
428
- from myst_nb .nodes import CellInputNode , CellOutputNode
429
443
430
- for node in self .document .traverse (CellOutputNode ):
444
+ for node in self .document .traverse (is_input_cell ):
431
445
celloutput = CellOutput ()
432
446
celloutput .append (node .deepcopy ())
433
447
node .replace_self (celloutput )
434
448
435
- for node in self .document .traverse (CellInputNode ):
449
+ for node in self .document .traverse (is_output_cell ):
436
450
cellinput = CellInput ()
437
451
cellinput .append (node .deepcopy ())
438
452
node .replace_self (cellinput )
0 commit comments