@@ -53,6 +53,12 @@ def clean_pycon(source: str) -> Tuple[str, str]:
53
53
return source , '\n ' .join (clean_lines )
54
54
55
55
56
+ def clean_ipython (source : str ) -> Tuple [str , str ]:
57
+ """Clean up IPython syntax to pure Python."""
58
+ from IPython .core .inputtransformer2 import TransformerManager
59
+ return source , TransformerManager ().transform_cell (source )
60
+
61
+
56
62
class CodeBlockAnalyser (nodes .SparseNodeVisitor ):
57
63
"""Transform literal blocks of Python with links to reference documentation."""
58
64
@@ -70,7 +76,10 @@ def __init__(
70
76
relative_path = Path (self .document ['source' ]).relative_to (source_dir )
71
77
self .current_document = str (relative_path .with_suffix ('' ))
72
78
self .global_preface = global_preface
73
- self .custom_blocks = {'pycon' : clean_pycon }
79
+ self .custom_blocks = {
80
+ 'pycon' : clean_pycon ,
81
+ 'ipython3' : clean_ipython ,
82
+ }
74
83
self .custom_blocks .update (custom_blocks )
75
84
self .valid_blocks = ('py' , 'python' ) + tuple (self .custom_blocks .keys ())
76
85
self .title_stack = []
@@ -230,7 +239,7 @@ def link_html(
230
239
text = document .read_text ('utf-8' )
231
240
soup = BeautifulSoup (text , 'html.parser' )
232
241
233
- block_types = {'python' , 'pycon' } | set (custom_blocks .keys ())
242
+ block_types = {'python' , 'pycon' , 'ipython3' } | set (custom_blocks .keys ())
234
243
classes = [f'highlight-{ t } ' for t in block_types ] + ['doctest' ]
235
244
classes += search_css_classes
236
245
0 commit comments