Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit bd6e411

Browse files
committed
Fix: fillins missing their label
1 parent b7553d4 commit bd6e411

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

runestone/fitb/fitb.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,16 @@ def noop(self, node):
5050
def setup(app):
5151
app.add_directive("fillintheblank", FillInTheBlank)
5252
app.add_role("blank", BlankRole)
53-
app.add_node(FITBNode, html=(visit_fitb_html, depart_fitb_html),
54-
xml=(visit_fitb_xml, depart_fitb_xml))
53+
app.add_node(
54+
FITBNode,
55+
html=(visit_fitb_html, depart_fitb_html),
56+
xml=(visit_fitb_xml, depart_fitb_xml),
57+
)
5558
app.add_node(BlankNode, html=(visit_blank_html, depart_blank_html))
5659
app.add_node(
57-
FITBFeedbackNode, html=(visit_fitb_feedback_html, depart_fitb_feedback_html),
58-
xml=(noop, noop)
60+
FITBFeedbackNode,
61+
html=(visit_fitb_feedback_html, depart_fitb_feedback_html),
62+
xml=(noop, noop),
5963
)
6064

6165
app.add_config_value("fitb_div_class", "runestone", "html")
@@ -114,6 +118,7 @@ def depart_fitb_html(self, node):
114118

115119
self.body.remove(node["delimiter"])
116120

121+
117122
# <exercise>
118123
# <title>Fill-In, Integer Answer</title>
119124

@@ -144,8 +149,8 @@ def depart_fitb_html(self, node):
144149

145150
def visit_fitb_xml(self, node):
146151

147-
TEMPLATE_START = """
148-
<exercise>
152+
TEMPLATE_START = f"""
153+
<exercise label="{node["runestone_options"]["divid"]}">
149154
<statement>
150155
"""
151156
self.output.append(TEMPLATE_START)
@@ -156,7 +161,7 @@ def visit_fitb_xml(self, node):
156161
numBlanks = stmt.count("<var />")
157162
diff = neededBlanks - numBlanks
158163
if diff > 0:
159-
stmt = stmt[0:stmt.rfind("</paragraph>")]
164+
stmt = stmt[0 : stmt.rfind("</paragraph>")]
160165
for i in range(diff):
161166
stmt += " <var /> "
162167
stmt += " </paragraph>"
@@ -234,11 +239,11 @@ class FillInTheBlank(RunestoneIdDirective):
234239

235240
def run(self):
236241
"""
237-
process the fillintheblank directive and generate html for output.
238-
:param self:
239-
:return: Nodes resulting from this directive.
240-
...
241-
"""
242+
process the fillintheblank directive and generate html for output.
243+
:param self:
244+
:return: Nodes resulting from this directive.
245+
...
246+
"""
242247

243248
super(FillInTheBlank, self).run()
244249

@@ -375,7 +380,6 @@ def run(self):
375380
regex = (
376381
# The given regex must match the entire string, from the beginning (which may be preceded by whitespaces) ...
377382
r"^\s*"
378-
379383
# ... to the contents (where a single space in the provided pattern is treated as one or more whitespaces in the student's answer) ...
380384
+ feedback_field_name.rawsource.replace(" ", r"\s+")
381385
# ... to the end (also with optional spaces).
@@ -401,7 +405,7 @@ def run(self):
401405
ffn = FITBFeedbackNode(
402406
feedback_field_body.rawsource,
403407
*feedback_field_body.children,
404-
**feedback_field_body.attributes
408+
**feedback_field_body.attributes,
405409
)
406410
ffn["blankFeedbackDict"] = blankFeedbackDict
407411
fitbNode += ffn
@@ -454,7 +458,7 @@ def visit_blank_html(self, node):
454458

455459

456460
def visit_blank_xml(self, node):
457-
self.output.append('<p><var /></p>')
461+
self.output.append("<p><var /></p>")
458462

459463

460464
def depart_blank_html(self, node):

0 commit comments

Comments
 (0)