@@ -61,7 +61,7 @@ def condition(node):
6161 return isinstance (node , (nodes .literal_block , nodes .literal ))
6262
6363 for node in self .document .traverse (condition ):
64- if _SUBSTITUTION_OPTION_NAME not in node :
64+ if not node . get ( _SUBSTITUTION_OPTION_NAME ) :
6565 continue
6666
6767 # Some nodes don't have a direct document property, so walk up until we find it
@@ -76,11 +76,13 @@ def condition(node):
7676 old_child = child
7777 for name , value in substitution_defs .items ():
7878 replacement = value .astext ()
79- child = nodes .Text (child .replace (f"|{ name } |" , replacement ))
80- node .replace (old_child , child )
79+ if isinstance (child , nodes .Text ):
80+ child = nodes .Text (child .replace (f"|{ name } |" , replacement ))
81+ if isinstance (node , nodes .Element ):
82+ node .replace (old_child , child )
8183
8284 # The highlighter checks this -- without this, it will refuse to apply highlighting
83- node .rawsource = node .astext ()
85+ node .rawsource = node .astext () # type: ignore[attr-defined]
8486
8587
8688def substitution_code_role (* args , ** kwargs ) -> tuple [list , list [Any ]]:
0 commit comments