2929from runestone .server .componentdb import addQuestionToDB , addHTMLToDB
3030from runestone .common import RunestoneIdDirective , RunestoneIdNode
3131from docutils import nodes
32+
3233__author__ = "rmorelli"
3334
3435# Debug flags
@@ -53,12 +54,14 @@ def setup(app):
5354 app .add_directive ("khanex" , Khanex )
5455 app .add_node (KhanexNode , html = (visit_khanex_html , depart_khanex_html ))
5556
57+
5658# The only content needed from khanex.py is the exercise name
5759
5860
5961class KhanexNode (nodes .General , nodes .Element , RunestoneIdNode ):
6062 pass
6163
64+
6265# self for these functions is an instance of the writer class. For example
6366# in html, self is sphinx.writers.html.SmartyPantsHTMLTranslator
6467# The node that is passed as a parameter is an instance of our node class.
@@ -69,28 +72,30 @@ def visit_khanex_html(self, node):
6972 node ["delimiter" ] = "_start__{}_" .format (node ["runestone_options" ]["divid" ])
7073 self .body .append (node ["delimiter" ])
7174
72- print ('DEBUG: visit_khanex_html exername = ' + node ["exername" ]) if DEBUG else None
73- print ('DEBUG: visit_khanex_html template = ' + node ["template" ]) if DEBUG else None
74- print ('DEBUG: visit_khanex_html options = '
75- + str (node ["runestone_options" ])) if DEBUG else None
75+ print ("DEBUG: visit_khanex_html exername = " + node ["exername" ]) if DEBUG else None
76+ print ("DEBUG: visit_khanex_html template = " + node ["template" ]) if DEBUG else None
77+ print (
78+ "DEBUG: visit_khanex_html options = " + str (node ["runestone_options" ])
79+ ) if DEBUG else None
7680
7781 res = node ["template" ] % (node ["runestone_options" ])
78- print (' DEBUG: visit_khanex_html res = ' + res ) if DEBUG else None
82+ print (" DEBUG: visit_khanex_html res = " + res ) if DEBUG else None
7983 self .body .append (res )
8084
8185
8286def depart_khanex_html (self , node ):
83- """ This is called at the start of processing an activecode node. If activecode had recursive nodes
84- etc and did not want to do all of the processing in visit_ac_html any finishing touches could be
85- added here.
87+ """This is called at the start of processing an activecode node. If activecode had recursive nodes
88+ etc and did not want to do all of the processing in visit_ac_html any finishing touches could be
89+ added here.
8690 """
87- print (' DEBUG: depart_khanex_html' ) if DEBUG else None
91+ print (" DEBUG: depart_khanex_html" ) if DEBUG else None
8892 bc = node ["runestone_options" ]["basecourse" ]
8993 addHTMLToDB (
9094 node ["runestone_options" ]["divid" ],
9195 bc ,
92- "" .join (self .body [self .body .index (node ["delimiter" ]) + 1 :])
93- .replace ("../_static" , f"/runestone/books/published/{ bc } /_static" ),
96+ "" .join (self .body [self .body .index (node ["delimiter" ]) + 1 :]).replace (
97+ "../_static" , f"/ns/books/published/{ bc } /_static"
98+ ),
9499 )
95100 self .body .remove (node ["delimiter" ])
96101 pass
@@ -110,20 +115,21 @@ class Khanex(RunestoneIdDirective):
110115 """
111116 .. khanex:: some_unique_id, e.g., ex1
112117
113- :exercise: unique-ex-name:
118+ :exercise: unique-ex-name:
114119 """
120+
115121 required_arguments = 1
116122 optional_arguments = 0
117- has_content = True
123+ has_content = True
118124 option_spec = RunestoneIdDirective .option_spec .copy ()
119- option_spec .update ( {} )
125+ option_spec .update ({} )
120126
121127 # This invokes the rendering code in js/khanex.js
122128 def run (self ):
123129 super (Khanex , self ).run ()
124- print (' DEBUG; Khanex.run()' ) if DEBUG else None
130+ print (" DEBUG; Khanex.run()" ) if DEBUG else None
125131
126- addQuestionToDB (self ) # Not sure whether this works?
132+ addQuestionToDB (self ) # Not sure whether this works?
127133 document = self .state .document
128134 rel_filename , filename = document .settings .env .relfn2path (self .arguments [0 ])
129135
@@ -136,12 +142,14 @@ def run(self):
136142
137143 khanex_node = KhanexNode ()
138144 khanex_node ["runestone_options" ] = self .options
139- khanex_node ["exername" ] = str (self .options [' controls' ][0 ])
145+ khanex_node ["exername" ] = str (self .options [" controls" ][0 ])
140146 khanex_node ["exername" ] = str .strip (khanex_node ["exername" ][10 :])
141147 khanex_node ["template" ] = KHANEX_TEMPLATE .replace (
142- '###' , khanex_node ["exername" ])
143-
144- khanex_node ["source" ], khanex_node ["line" ] = self .state_machine .get_source_and_line (
145- self .lineno
148+ "###" , khanex_node ["exername" ]
146149 )
150+
151+ (
152+ khanex_node ["source" ],
153+ khanex_node ["line" ],
154+ ) = self .state_machine .get_source_and_line (self .lineno )
147155 return [khanex_node ]
0 commit comments