@@ -151,12 +151,23 @@ def visit_fitb_xml(self, node):
151151 <statement>
152152 """
153153 self .output .append (TEMPLATE_START )
154+ node .private_children = node .children [1 :]
155+ stmt = str (node .children [0 ])
156+ stmt = re .sub (r"<problematic.*?</problematic>" , "<var />" , stmt )
157+ neededBlanks = len (node ["runestone_options" ]["pattlist" ])
158+ numBlanks = stmt .count ("<var />" )
159+ diff = neededBlanks - numBlanks
160+ if diff > 0 :
161+ stmt = stmt [0 :stmt .rfind ("</paragraph>" )]
162+ for i in range (diff ):
163+ stmt += " <var /> "
164+ stmt += " </paragraph>"
165+ node .children = []
166+ self .output .append (stmt )
167+ self .output .append ("</statement>" )
154168
155169
156170def depart_fitb_xml (self , node ):
157- blankCount = 0
158- for xx in node .traverse (BlankNode ):
159- blankCount += 1
160171
161172 # pattlist = node["runestone_options"]["pattlist"] # answer patterns
162173 # flist = node["runestone_options"]["flist"] # feedback
@@ -166,27 +177,30 @@ def depart_fitb_xml(self, node):
166177 # visit_blank_xml(self, None)
167178 # blankCount += 1
168179
169- self .output .append ("</statement>" )
170180 self .output .append ("<setup>" )
171181 # Walk the children of node
172182 # child 0 is the statement
173183 # children 1..N are the feedbacks
174184 # each of these children will have an atribute called blankfeedbackdict which is the match for this
175185 # each child will have a child/children that is the actual feedback we want to supply
176186 #
177- self .output .append ("<var>" )
178- for child in node .children [1 :]:
179- rx = child ["blankfeedbackdict" ]
180- if "number" in rx :
181- self .output .append (f"""<condition number="{ rx ['number' ]} ">""" )
182- else :
183- self .output .append (f"""<condition string="{ rx ['regex' ]} ">""" )
184- fb = ""
185- for p in child .children :
186- fb += str (p )
187- self .output .append (f"<feedback>{ fb } </feedback>" )
188- self .output .append ("</condition>" )
189- self .output .append ("</var>" )
187+
188+ for var in range (len (node ["runestone_options" ]["pattlist" ])):
189+ self .output .append ("<var>" )
190+
191+ for ans in range (len (node ["runestone_options" ]["pattlist" ][var ])):
192+ child = node .private_children .pop (0 )
193+ rx = child ["blankfeedbackdict" ]
194+ if "number" in rx :
195+ self .output .append (f"""<condition number="{ rx ['number' ]} ">""" )
196+ else :
197+ self .output .append (f"""<condition string="{ rx ['regex' ]} ">""" )
198+ fb = ""
199+ for p in child .children :
200+ fb += str (p )
201+ self .output .append (f"<feedback>{ fb } </feedback>" )
202+ self .output .append ("</condition>" )
203+ self .output .append ("</var>" )
190204 self .output .append ("</setup>" )
191205 self .output .append ("</exercise>" )
192206
0 commit comments