1- from typing import Dict , List
1+ from typing import Dict , List , Tuple
22
33from docutils import nodes
44from docutils .statemachine import StringList
@@ -20,9 +20,11 @@ class GridBuilderDirective(SphinxDirective):
2020 Helper functions for the `InfoCardDirective` to create grids and cards.
2121 """
2222
23- def create_grid (self ):
23+ def create_grid (self ) -> Tuple [ nodes . container , nodes . container ] :
2424 """
2525 Create a "grid layout" using sphinx-design components.
26+
27+ Return its outer and inner `docutils.container` instances.
2628 """
2729 margin_padding_classes = [margin_option ("0" )[0 ], padding_option ("0" )[0 ]]
2830
@@ -47,25 +49,32 @@ def create_grid(self):
4749 grid_container += grid_row
4850 return grid_container , grid_row
4951
50- def create_card (self ):
52+ def create_card (self ) -> Tuple [ nodes . container , nodes . container ] :
5153 """
5254 Create a sphinx-design "card" component.
55+
56+ Return its outer and inner `docutils.container` instances.
5357 """
54- # A dummy directive needed to use the CardDirective.
55- dummy = SphinxDirective (
58+ card = CardDirective (
59+ # FIXME: Need to assign random name?
5660 name = "sdroot" ,
57- arguments = [] ,
58- options = {} ,
61+ arguments = self . arguments ,
62+ options = self . options ,
5963 content = StringList (None ),
6064 lineno = self .lineno ,
6165 content_offset = self .content_offset ,
62- block_text = "" ,
66+ block_text = self . block_text ,
6367 state = self .state ,
6468 state_machine = self .state_machine ,
6569 )
66- card = CardDirective .create_card (dummy , [], {})
67- self .set_source_info (card )
68- return card
70+
71+ # TODO: Can process this differently?
72+ card_node = card .run ()[0 ]
73+ self .set_source_info (card_node )
74+
75+ card_body = card_node .children [0 ]
76+ self .set_source_info (card_body )
77+ return card_node , card_body
6978
7079
7180class InfoCardDirective (GridBuilderDirective ):
@@ -87,17 +96,17 @@ def run(self) -> List[nodes.Node]:
8796 root , canvas = self .create_grid ()
8897
8998 # Create a card, and add it to the canvas.
90- card = self .create_card ()
99+ card , card_body = self .create_card ()
91100 canvas += card
92101
93102 # Create a content grid, and add it to the card.
94- outer , inner = self .create_grid ()
95- self .set_source_info (outer )
96- card += outer
103+ content_outer , content_inner = self .create_grid ()
104+ self .set_source_info (content_outer )
105+ card_body += content_outer
97106
98107 # Parse the node content, assuming grid items, and add them to the content grid.
99- self .state .nested_parse (self .content , self .content_offset , inner )
100- self .set_source_info (inner )
108+ self .state .nested_parse (self .content , self .content_offset , content_inner )
109+ self .set_source_info (content_inner )
101110
102111 # Return a reference to the root node.
103112 return [root ]
0 commit comments