@@ -88,7 +88,13 @@ def all_node_content(
8888 print_fragments : bool = False ,
8989 level_stack : Tuple [int , ...] = (),
9090 custom_level : bool = False ,
91+ update_levels : bool = True ,
9192 ) -> Iterator [Tuple [SDocIteratedElementIF , DocumentIterationContext ]]:
93+ """
94+ FIXME: update_levels is hack. Change the design so that the node state
95+ is not patched during the iteration.
96+ """
97+
9298 if isinstance (node , SDocSection ):
9399 # If node is not whitelisted, we ignore it. Also, note that due to
94100 # this early return, all child nodes of this node are ignored
@@ -100,8 +106,10 @@ def all_node_content(
100106 context = DocumentIterationContext (
101107 node , level_stack , custom_level = custom_level
102108 )
103- node .context .title_number_string = context .get_level_string ()
104- node .ng_level = context .get_level ()
109+
110+ if update_levels :
111+ node .context .title_number_string = context .get_level_string ()
112+ node .ng_level = context .get_level ()
105113
106114 yield node , context
107115
@@ -128,6 +136,7 @@ def all_node_content(
128136 level_stack = level_stack + (current_number ,),
129137 custom_level = custom_level
130138 or subnode_ .ng_resolved_custom_level is not None ,
139+ update_levels = update_levels ,
131140 )
132141
133142 elif isinstance (node , SDocNode ):
@@ -141,8 +150,9 @@ def all_node_content(
141150 context = DocumentIterationContext (
142151 node , level_stack , custom_level = custom_level
143152 )
144- node .context .title_number_string = context .get_level_string ()
145- node .ng_level = context .get_level ()
153+ if update_levels :
154+ node .context .title_number_string = context .get_level_string ()
155+ node .ng_level = context .get_level ()
146156
147157 yield node , context
148158
@@ -161,6 +171,7 @@ def all_node_content(
161171 level_stack = level_stack + (current_number ,),
162172 custom_level = custom_level
163173 or subnode_ .ng_resolved_custom_level is not None ,
174+ update_levels = update_levels ,
164175 )
165176
166177 elif isinstance (node , SDocDocument ):
@@ -172,8 +183,11 @@ def all_node_content(
172183 context = DocumentIterationContext (
173184 node , level_stack , custom_level = custom_level
174185 )
175- node .context .title_number_string = context .get_level_string ()
176- node .ng_level = context .get_level ()
186+ if update_levels :
187+ node .context .title_number_string = (
188+ context .get_level_string ()
189+ )
190+ node .ng_level = context .get_level ()
177191
178192 yield node , context
179193
@@ -198,6 +212,7 @@ def all_node_content(
198212 level_stack = level_stack + (current_number ,),
199213 custom_level = custom_level
200214 or subnode_ .ng_resolved_custom_level is not None ,
215+ update_levels = update_levels ,
201216 )
202217
203218 elif isinstance (node , DocumentFromFile ):
@@ -210,6 +225,7 @@ def all_node_content(
210225 node .resolved_document ,
211226 print_fragments = print_fragments ,
212227 level_stack = level_stack ,
228+ update_levels = update_levels ,
213229 )
214230
215231 else :
0 commit comments