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

Commit 51ef84d

Browse files
committed
Support for display math in parsons
1 parent d41c4a4 commit 51ef84d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

runestone/parsons/js/parsons.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@ export default class Parsons extends RunestoneBase {
323323
depends =
324324
dependsString.length > 0 ? dependsString.split(",") : [];
325325
}
326+
if (textBlock.includes('class="displaymath')) {
327+
options["displaymath"] = true;
328+
} else {
329+
options["displaymath"] = false;
330+
}
326331
textBlock = textBlock.replace(
327332
/#(paired|distractor|tag:.*;.*;)/,
328333
function (mystring, arg1) {
@@ -332,12 +337,16 @@ export default class Parsons extends RunestoneBase {
332337
);
333338
// Create lines
334339
var lines = [];
335-
var split = textBlock.split("\n");
340+
if (! options["displaymath"]) {
341+
var split = textBlock.split("\n");
342+
} else {
343+
var split = [textBlock];
344+
}
336345
for (var j = 0; j < split.length; j++) {
337346
var code = split[j];
338347
// discard blank rows
339348
if (!/^\s*$/.test(code)) {
340-
var line = new ParsonsLine(this, code);
349+
var line = new ParsonsLine(this, code, options["displaymath"]);
341350
lines.push(line);
342351
if (options["paired"]) {
343352
line.distractor = true;

runestone/parsons/js/parsonsLine.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,22 @@
1818
// Initialize from codestring
1919

2020
export default class ParsonsLine {
21-
constructor(problem, codestring) {
21+
constructor(problem, codestring, displaymath) {
2222
this.problem = problem;
2323
this.index = problem.lines.length;
2424
var trimmed = codestring.replace(/\s*$/, "");
2525
this.text = trimmed.replace(/^\s*/, "");
2626
this.indent = trimmed.length - this.text.length;
2727
// Create the View
2828
var view;
29+
// TODO: this does not work with display math... Perhaps with pretext we should have html as a language and do nothing?
30+
2931
if (problem.options.language == "natural" || problem.options.language == "math") {
30-
view = document.createElement("p");
32+
if (! displaymath) {
33+
view = document.createElement("p");
34+
} else {
35+
view = document.createElement("div");
36+
}
3137
} else {
3238
view = document.createElement("code");
3339
$(view).addClass(problem.options.prettifyLanguage);

0 commit comments

Comments
 (0)