@@ -853,6 +853,79 @@ def apply(self):
853853                    node .parent .insert (node .parent .index (node ) +  1 , cell_node )
854854
855855
856+ class  DocstringTransform (SphinxTransform ):
857+    """ 
858+     Transform sections in Sage docstring for better rendering. 
859+ 
860+     The following are tests: 
861+ 
862+     AUTHORS: 
863+ 
864+     - Alice 
865+     - Bob 
866+ 
867+     INPUT: 
868+ 
869+     - one 
870+     - two 
871+ 
872+     OUTPUT: 
873+ 
874+     three 
875+ 
876+     OUTPUT: three 
877+ 
878+     EXAMPLE:: 
879+ 
880+         sage: 1 + 2 
881+         3 
882+ 
883+     EXAMPLES:: 
884+ 
885+         sage: 1 + 2 
886+         3 
887+ 
888+     EXAMPLE: 
889+ 
890+     We show that `1 + 2 = 3`:: 
891+ 
892+         sage: 1 + 2 
893+         3 
894+ 
895+     EXAMPLES: 
896+ 
897+     We show that `1 + 2 = 3`:: 
898+ 
899+         sage: 1 + 2 
900+         3 
901+ 
902+     """ 
903+     default_priority  =  800 
904+ 
905+     def  apply (self ):
906+         for  node  in  self .document .traverse (nodes .paragraph ):
907+             if  isinstance (node .children [0 ], nodes .Text ) and  node .children [0 ].astext ().strip () ==  'AUTHORS:' :
908+                 list_node  =  node .next_node (siblings = True , descend = False )
909+                 if  isinstance (list_node , nodes .bullet_list ):
910+                     new_node  =  nodes .admonition (classes = ['authors' ], admonitionclass = 'authors' )
911+                     node .replace_self (new_node )
912+                     node  =  new_node 
913+                     admonition_title  =  nodes .title ()
914+                     admonition_title .append (nodes .Text ('Authors' ))
915+                     node .insert (0 , admonition_title )
916+                     node .append (list_node )
917+                     node .parent .remove (list_node )
918+             for  section  in  ['INPUT' , 'OUTPUT' , 'EXAMPLES' , 'EXAMPLE' ]:
919+                 if  isinstance (node .children [0 ], nodes .Text ) and  node .children [0 ].astext ().startswith (f'{ section }  :' ):
920+                     parent  =  node .parent 
921+                     index  =  parent .index (node )
922+                     parent .remove (node )
923+                     parent .insert (index , nodes .Text (node .children [0 ].astext ()[len (f'{ section }  :' ):]))
924+                     acronym_node  =  nodes .acronym ()
925+                     acronym_node  +=  nodes .Text (section )
926+                     parent .insert (index , acronym_node )
927+ 
928+ 
856929# This replaces the setup() in sage.misc.sagedoc_conf 
857930def  setup (app ):
858931    app .connect ('autodoc-process-docstring' , process_docstring_cython )
@@ -864,6 +937,7 @@ def setup(app):
864937        app .connect ('autodoc-process-docstring' , skip_TESTS_block )
865938    app .connect ('autodoc-skip-member' , skip_member )
866939    app .add_transform (SagemathTransform )
940+     app .add_transform (DocstringTransform )
867941    if  os .environ .get ('SAGE_LIVE_DOC' , 'no' ) ==  'yes' :
868942        app .add_transform (SagecodeTransform )
869943
0 commit comments