2929
3030def 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
5062class JournalNode (nodes .General , nodes .Element , RunestoneIdNode ):
5163 pass
5264
5365
5466def 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+
6783def 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+
83103class JournalDirective (Assessment ):
84104 """
85105.. shortanswer:: uniqueid
0 commit comments