@@ -385,20 +385,26 @@ def handle_directive(
385385
386386 doc = n .Directive ((line ,), [], domain , name , [], options )
387387
388- if (
389- node .children
390- and node .children [0 ].__class__ .__name__ == "directive_argument"
391- ):
392- visitor = self .__make_child_visitor ()
393- node .children [0 ].walkabout (visitor )
394- top_of_visitor_state = visitor .state [- 1 ]
395- assert isinstance (top_of_visitor_state , n .Parent )
396- argument = top_of_visitor_state .children
397- doc .argument = argument # type: ignore
398- node .children = node .children [1 :]
399- else :
400- argument = []
401- doc .argument = argument
388+ # Find and move the argument from the children to the "argument" field.
389+ argument : MutableSequence [Any ] = []
390+ if node .children :
391+ index_of_argument = next (
392+ (
393+ idx
394+ for idx , value in enumerate (node .children )
395+ if isinstance (value , rstparser .directive_argument )
396+ ),
397+ None ,
398+ )
399+ if index_of_argument is not None :
400+ visitor = self .__make_child_visitor ()
401+ node .children [index_of_argument ].walkabout (visitor )
402+ top_of_visitor_state = visitor .state [- 1 ]
403+ assert isinstance (top_of_visitor_state , n .Parent )
404+ argument = top_of_visitor_state .children
405+ del node .children [index_of_argument ]
406+
407+ doc .argument = argument
402408
403409 argument_text = None
404410 try :
0 commit comments