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

Commit 3edf422

Browse files
committed
Make divids available to link to using the :ref: role
1 parent cbf5b20 commit 3edf422

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

runestone/activecode/activecode.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(self, content):
6767
- `self`:
6868
- `content`:
6969
"""
70-
super(ActivcodeNode, self).__init__()
70+
super(ActivcodeNode, self).__init__(name=content['name'])
7171
self.ac_components = content
7272

7373

@@ -136,6 +136,8 @@ def run(self):
136136
env.activecodecounter = 0
137137
env.activecodecounter += 1
138138

139+
self.options['name'] = self.arguments[0].strip()
140+
139141
self.options['divid'] = self.arguments[0]
140142

141143
if self.content:
@@ -227,7 +229,9 @@ def run(self):
227229
if 'gradebutton' not in self.options:
228230
self.options['gradebutton'] = ''
229231

230-
return [ActivcodeNode(self.options)]
232+
acnode = ActivcodeNode(self.options)
233+
self.add_name(acnode) # make this divid available as a target for :ref:
234+
return [acnode]
231235

232236

233237
class ActiveExercise(ActiveCode):

runestone/activecode/js/activecode.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ ActiveCode.prototype.init = function(opts) {
6464

6565
ActiveCode.prototype.createEditor = function (index) {
6666
var newdiv = document.createElement('div');
67+
var linkdiv = document.createElement('div')
68+
linkdiv.id = this.divid.replace(/_/g,'-').toLowerCase(); // :ref: changes _ to - so add this as a target
6769
$(newdiv).addClass("ac_section alert alert-warning");
6870
var codeDiv = document.createElement("div");
6971
$(codeDiv).addClass("ac_code_div col-md-12");
@@ -73,6 +75,9 @@ ActiveCode.prototype.createEditor = function (index) {
7375
this.outerDiv = newdiv;
7476

7577
$(this.origElem).replaceWith(newdiv);
78+
if (linkdiv.id !== this.divid) { // Don't want the 'extra' target if they match.
79+
newdiv.appendChild(linkdiv);
80+
}
7681
newdiv.appendChild(codeDiv);
7782
var editor = CodeMirror(codeDiv, {value: this.code, lineNumbers: true, mode: newdiv.lang});
7883

0 commit comments

Comments
 (0)