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

Commit 6e3506b

Browse files
committed
encode and decode html so it is properly represented in the editor.
1 parent 27c0a2a commit 6e3506b

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

runestone/activecode/activecode.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from docutils.parsers.rst import directives
2121
from docutils.parsers.rst import Directive
2222
from .textfield import *
23+
import cgi
2324

2425
def setup(app):
2526
app.add_directive('activecode', ActiveCode)
@@ -205,6 +206,7 @@ def run(self):
205206

206207
if self.options['language'] == 'html':
207208
self.options['language'] = 'htmlmixed'
209+
self.options['initialcode'] = cgi.escape(self.options['initialcode'])
208210

209211
if 'nocodelens' in self.options or self.options['language'] != 'python':
210212
self.options['codelens'] = ''

runestone/activecode/js/activecode.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -508,26 +508,24 @@ HTMLActiveCode.prototype.runProg = function () {
508508
$(this.codeDiv).switchClass("col-md-12","col-md-6",{duration:500,queue:false});
509509
$(this.outDiv).show({duration:700,queue:false});
510510

511-
$(this.output).html(prog)
511+
this.output.srcdoc = prog;
512512
};
513513

514514
HTMLActiveCode.prototype.init = function(opts) {
515515
ActiveCode.prototype.init.apply(this,arguments)
516-
this.code = $(this.origElem).html();
516+
this.code = $('<textarea />').html(orig.innerHTML).text();
517517
this.editor.setValue(this.code);
518518
};
519519

520520
HTMLActiveCode.prototype.createOutput = function () {
521-
// Create a parent div with two elements: pre for standard output and a div
522-
// to hold turtle graphics output. We use a div in case the turtle changes from
523-
// using a canvas to using some other element like svg in the future.
524-
console.log("creating html output")
525521
var outDiv = document.createElement("div");
526522
$(outDiv).addClass("ac_output col-md-6");
527523
this.outDiv = outDiv;
528-
this.output = document.createElement('div');
524+
this.output = document.createElement('iframe');
529525
$(this.output).css("background-color","white");
530-
526+
$(this.output).css("position","relative");
527+
$(this.output).css("height","400px");
528+
$(this.output).css("width","100%");
531529
outDiv.appendChild(this.output);
532530
this.outerDiv.appendChild(outDiv);
533531

0 commit comments

Comments
 (0)