@@ -35,6 +35,49 @@ class MChoiceNode(nodes.General, nodes.Element, RunestoneIdNode):
3535 pass
3636
3737
38+ XML_START = """
39+ <exercise xml:id="{divid}">
40+ <statement>
41+
42+ """
43+
44+ XML_START_END = """
45+ </statement>
46+ <choices>
47+ """
48+
49+ XML_OPTION = """
50+ <choice {is_correct}>
51+ <statement>
52+ <p>{atext}</p>
53+ </statement>
54+ <feedback>
55+ <p>Incorrect: green means "go!".</p>
56+ </feedback>
57+ </choice>
58+ """
59+
60+ XML_END = """
61+ </choices>
62+ </exercise>
63+ """
64+
65+ TEMPLATE_START = """
66+ <div class="{divclass}">
67+ <ul data-component="multiplechoice" data-question_label="{question_label}" data-multipleanswers="{multipleAnswers}" {random} id="{divid}" {optional} style="visibility: hidden;">
68+ """
69+
70+ OPTION = """
71+ <li data-component="answer" {is_correct} id="{divid}_opt_{alabel}">{atext}</li><li data-component="feedback">{feedtext}</li>
72+ """
73+
74+ TEMPLATE_END = """
75+
76+ </ul>
77+ </div>
78+ """
79+
80+
3881def visit_mc_common (self , node ):
3982
4083 res = ""
@@ -49,7 +92,7 @@ def visit_mc_common(self, node):
4992 node ["runestone_options" ]["multipleAnswers" ] = "true"
5093 else :
5194 node ["runestone_options" ]["multipleAnswers" ] = "false"
52- res = node ["template_start" ] % node ["runestone_options" ]
95+ res = node ["template_start" ]. format ( ** node ["runestone_options" ])
5396
5497 return res
5598
@@ -73,19 +116,23 @@ def depart_mc_common(self, node):
73116 node ["runestone_options" ]["is_correct" ] = "data-correct"
74117 else :
75118 node ["runestone_options" ]["is_correct" ] = ""
76- res += node ["template_option" ] % node ["runestone_options" ]
119+ res += node ["template_option" ]. format ( ** node ["runestone_options" ])
77120
78- res += node ["template_end" ] % node ["runestone_options" ]
121+ res += node ["template_end" ]. format ( ** node ["runestone_options" ])
79122 return res
80123
81124
82125def visit_mc_xml (self , node ):
83-
126+ node ["template_start" ] = XML_START
127+ node ["template_end" ] = XML_END
128+ node ["template_option" ] = XML_OPTION
129+ pdb .set_trace ()
84130 res = visit_mc_common (self , node )
85131 self .output .append (res )
86132
87133
88134def depart_mc_xml (self , node ):
135+ self .output .append (XML_START_END )
89136 res = depart_mc_common (self , node )
90137 self .output .append (res )
91138
@@ -207,24 +254,9 @@ def run(self):
207254
208255 super (MChoice , self ).run ()
209256
210- TEMPLATE_START = """
211- <div class="%(divclass)s">
212- <ul data-component="multiplechoice" data-question_label="%(question_label)s" data-multipleanswers="%(multipleAnswers)s" %(random)s id="%(divid)s" %(optional)s style="visibility: hidden;">
213- """
214-
215- OPTION = """
216- <li data-component="answer" %(is_correct)s id="%(divid)s_opt_%(alabel)s">%(atext)s</li><li data-component="feedback">%(feedtext)s</li>
217- """
218-
219- TEMPLATE_END = """
220-
221- </ul>
222- </div>
223- """
224257 addQuestionToDB (self )
225258
226259 mcNode = MChoiceNode ()
227- # This is maybe a hack or maybe the new right way to do this...
228260 mcNode ["runestone_options" ] = self .options
229261 mcNode ["source" ], mcNode ["line" ] = self .state_machine .get_source_and_line (
230262 self .lineno )
@@ -386,8 +418,8 @@ def visit_answer_list_item(self, node):
386418
387419 # Format the HTML.
388420 self .body .append (
389- '<li data-component="answer" %( is_correct)s id="%( divid)s_opt_%( alabel)s ">'
390- % mc_node ["runestone_options" ]
421+ '<li data-component="answer" { is_correct} id="{ divid}_opt_{ alabel} ">' . format (
422+ ** mc_node ["runestone_options" ])
391423 )
392424
393425
@@ -413,8 +445,8 @@ def visit_feedback_list_item(self, node):
413445 label = chr (answer_list_item .parent .index (answer_list_item ) + ord ("a" ))
414446 mc_node ["runestone_options" ]["alabel" ] = label
415447 self .body .append (
416- '</li><li data-component="feedback" id="%( divid)s_opt_%( alabel)s ">\n '
417- % mc_node ["runestone_options" ]
448+ '</li><li data-component="feedback" id="{ divid}_opt_{ alabel} ">\n ' . format (
449+ ** mc_node ["runestone_options" ])
418450 )
419451
420452
0 commit comments