@@ -53,12 +53,25 @@ def setup(app):
5353 app .add_config_value ("activecode_hide_load_history" , False , "html" )
5454 app .add_config_value ("wasm_uri" , "/_static" , "html" )
5555
56- app .add_node (ActivcodeNode , html = (visit_ac_node , depart_ac_node ))
56+ app .add_node (ActivecodeNode , html = (visit_ac_html , depart_ac_html ),
57+ xml = (visit_ac_xml , depart_ac_xml ))
5758
5859 app .connect ("doctree-resolved" , process_activcode_nodes )
5960 app .connect ("env-purge-doc" , purge_activecodes )
6061
6162
63+ XML_START = """
64+ <listing xml:id="{divid}">
65+ <caption>{caption}</caption>
66+ <program xml:id="{divid}_editor" interactive='yes' language="{language}">
67+ <input>
68+ {initialcode}
69+ </input>
70+ </program>
71+ </listing>
72+
73+ """
74+
6275TEMPLATE_START = """
6376<div class="%(divclass)s">
6477<div data-component="activecode" id=%(divid)s data-question_label="%(question_label)s">
@@ -79,51 +92,49 @@ def setup(app):
7992"""
8093
8194
82- class ActivcodeNode (nodes .General , nodes .Element , RunestoneIdNode ):
83- def __init__ (self , content , ** kwargs ):
84- """
95+ class ActivecodeNode (nodes .General , nodes .Element , RunestoneIdNode ):
96+ pass
97+
98+
99+ def visit_ac_xml (self , node ):
100+ res = XML_START .format (** node ["runestone_options" ])
101+ self .output .append (res )
85102
86- Arguments:
87- - `self`:
88- - `content`:
89- """
90- super (ActivcodeNode , self ).__init__ (name = content ["name" ], ** kwargs )
91- self .runestone_options = content
92103
104+ def depart_ac_xml (self , node ):
105+ pass
93106
94107# self for these functions is an instance of the writer class. For example
95108# in html, self is sphinx.writers.html.SmartyPantsHTMLTranslator
96109# The node that is passed as a parameter is an instance of our node class.
97- def visit_ac_node (self , node ):
98- # print self.settings.env.activecodecounter
99110
100- # todo: handle above in node.runestone_options
101- # todo handle 'hidecode' not in node.runestone_options:
102- # todo: handle if 'gradebutton' in node.runestone_options: res += GRADES
103111
104- node .delimiter = "_start__{}_" .format (node .runestone_options ["divid" ])
112+ def visit_ac_html (self , node ):
113+ # print self.settings.env.activecodecounter
114+
115+ node ["delimiter" ] = "_start__{}_" .format (node ["runestone_options" ]["divid" ])
105116
106- self .body .append (node . delimiter )
117+ self .body .append (node [ " delimiter" ] )
107118
108- res = TEMPLATE_START % node . runestone_options
119+ res = TEMPLATE_START % node [ " runestone_options" ]
109120 self .body .append (res )
110121
111122
112- def depart_ac_node (self , node ):
123+ def depart_ac_html (self , node ):
113124 """This is called at the start of processing an activecode node. If activecode had recursive nodes
114- etc and did not want to do all of the processing in visit_ac_node any finishing touches could be
125+ etc and did not want to do all of the processing in visit_ac_html any finishing touches could be
115126 added here.
116127 """
117- res = TEMPLATE_END % node . runestone_options
128+ res = TEMPLATE_END % node [ " runestone_options" ]
118129 self .body .append (res )
119130
120131 addHTMLToDB (
121- node . runestone_options ["divid" ],
122- node . runestone_options ["basecourse" ],
123- "" .join (self .body [self .body .index (node . delimiter ) + 1 :]),
132+ node [ " runestone_options" ] ["divid" ],
133+ node [ " runestone_options" ] ["basecourse" ],
134+ "" .join (self .body [self .body .index (node [ " delimiter" ] ) + 1 :]),
124135 )
125136
126- self .body .remove (node . delimiter )
137+ self .body .remove (node [ " delimiter" ] )
127138
128139
129140def process_activcode_nodes (app , env , docname ):
@@ -448,8 +459,10 @@ def run(self):
448459 "This should only affect the grading interface. Everything else should be fine."
449460 )
450461
451- acnode = ActivcodeNode (self .options , rawsource = self .block_text )
452- acnode .source , acnode .line = self .state_machine .get_source_and_line (self .lineno )
462+ acnode = ActivecodeNode ()
463+ acnode ["runestone_options" ] = self .options
464+ acnode ["source" ], acnode ["line" ] = self .state_machine .get_source_and_line (
465+ self .lineno )
453466 self .add_name (acnode ) # make this divid available as a target for :ref:
454467
455468 maybeAddToAssignment (self )
0 commit comments