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

Commit 2b49897

Browse files
committed
Fix activecode
1 parent a03f4d6 commit 2b49897

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

runestone/activecode/activecode.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,22 @@ def setup(app):
6060
app.connect("env-purge-doc", purge_activecodes)
6161

6262

63-
XML_START = """
63+
XML_EX_START = """
64+
<exercise xml:id="{divid}">
65+
<statement>
66+
"""
67+
68+
XML_EX_END = """
69+
</statement>
70+
<program xml:id="{divid}_editor" interactive='activecode' language="{language}">
71+
<input>
72+
{initialcode}
73+
</input>
74+
</program>
75+
</exercise>
76+
"""
77+
78+
XML_LISTING_START = """
6479
<listing xml:id="{divid}">
6580
<caption>{caption}</caption>
6681
<program xml:id="{divid}_editor" interactive='activecode' language="{language}">
@@ -71,6 +86,7 @@ def setup(app):
7186
</listing>
7287
"""
7388

89+
7490
TEMPLATE_START = """
7591
<div class="%(divclass)s %(optclass)s">
7692
<div data-component="activecode" id=%(divid)s data-question_label="%(question_label)s">
@@ -96,14 +112,21 @@ class ActivecodeNode(nodes.General, nodes.Element, RunestoneIdNode):
96112

97113

98114
def visit_ac_xml(self, node):
99-
node["runestone_options"]["initialcode"] = node["runestone_options"]["initialcode"].replace(
100-
"<", "&lt;").replace(">", "&gt;")
101-
res = XML_START.format(**node["runestone_options"])
102-
self.output.append(res)
115+
if node["runestone_options"]["has_problem_statement"]:
116+
res = XML_EX_START.format(**node["runestone_options"])
117+
self.output.append(res)
118+
else:
119+
node["runestone_options"]["initialcode"] = node["runestone_options"]["initialcode"].replace(
120+
"<", "&lt;").replace(">", "&gt;")
103121

104122

105123
def depart_ac_xml(self, node):
106-
pass
124+
if node["runestone_options"]["has_problem_statement"]:
125+
res = XML_EX_END.format(**node["runestone_options"])
126+
self.output.append(res)
127+
else:
128+
res = XML_LISTING_START.format(**node["runestone_options"])
129+
self.output.append(res)
107130

108131
# self for these functions is an instance of the writer class. For example
109132
# in html, self is sphinx.writers.html.SmartyPantsHTMLTranslator
@@ -253,7 +276,13 @@ def run(self):
253276
else:
254277
source = "\n"
255278

256-
self.explain_text = explain_text or ["Not an Exercise"]
279+
if explain_text:
280+
self.options["has_problem_statement"] = True
281+
self.explain_text = explain_text
282+
else:
283+
self.options["has_problem_statement"] = False
284+
self.explain_text = ["Not an Exercise"]
285+
257286
addQuestionToDB(self)
258287

259288
self.options["initialcode"] = source

runestone/common/runestonedirective.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ def run(self):
324324
id_ = self.options["divid"]
325325
if re.match(r"^[0-9_]+", id_):
326326
print(f"BAD DIVID: {id_}")
327+
self.options["divid"] = f"rsid_{id_}"
327328
self.options["qnumber"] = self.getNumber()
328329
# print(f"{id_} is number {self.options['qnumber']}")
329330

0 commit comments

Comments
 (0)