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

Commit 100acfd

Browse files
committed
convert shortanswer
1 parent 6d9e8e4 commit 100acfd

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

runestone/shortanswer/shortanswer.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929

3030
def setup(app):
3131
app.add_directive("shortanswer", JournalDirective)
32-
app.add_node(JournalNode, html=(visit_journal_html, depart_journal_html))
32+
app.add_node(JournalNode, html=(visit_journal_html, depart_journal_html),
33+
xml=(visit_journal_xml, depart_journal_xml))
34+
3335
app.add_config_value("shortanswer_div_class", "journal alert alert-warning", "html")
3436
app.add_config_value(
3537
"shortanswer_optional_div_class", "journal alert alert-success", "html"
@@ -46,24 +48,38 @@ def setup(app):
4648
</div> <!-- end of runestone div -->
4749
"""
4850

51+
XML_START = """
52+
<exercise xml:id={divid} {optional}>
53+
<statement>
54+
"""
55+
56+
XML_END = """
57+
</statement>
58+
</exercise>
59+
"""
60+
4961

5062
class JournalNode(nodes.General, nodes.Element, RunestoneIdNode):
5163
pass
5264

5365

5466
def visit_journal_html(self, node):
55-
div_id = node["runestone_options"]["divid"]
56-
components = dict(node["runestone_options"])
57-
components.update({"divid": div_id})
5867

5968
node["delimiter"] = "_start__{}_".format(node["runestone_options"]["divid"])
6069
self.body.append(node["delimiter"])
6170

62-
res = TEXT_START % components
71+
res = TEXT_START % node["runestone_options"]
6372

6473
self.body.append(res)
6574

6675

76+
def visit_journal_xml(self, node):
77+
78+
res = XML_START.format(**node["runestone_options"])
79+
80+
self.output.append(res)
81+
82+
6783
def depart_journal_html(self, node):
6884

6985
components = dict(node["runestone_options"])
@@ -80,6 +96,10 @@ def depart_journal_html(self, node):
8096
self.body.remove(node["delimiter"])
8197

8298

99+
def depart_journal_xml(self, node):
100+
self.output.append(XML_END)
101+
102+
83103
class JournalDirective(Assessment):
84104
"""
85105
.. shortanswer:: uniqueid

0 commit comments

Comments
 (0)