summaryrefslogtreecommitdiffstats
path: root/lib/parse/renderer.js
diff options
context:
space:
mode:
authorJames Phillpotts <jphillpotts@scottlogic.co.uk>2014-04-10 10:29:17 +0100
committerAaron O'Mullan <aaron.omullan@friendco.de>2014-04-12 01:26:03 -0700
commitb07681a16a291a38fdbdfa3065a747ab26f9a6c9 (patch)
treeffb07c822518e689e619dc1ac8780f10877f7b7f /lib/parse/renderer.js
parentf6595f51119baca04bf91e619f64518d400e5cae (diff)
downloadgitbook-b07681a16a291a38fdbdfa3065a747ab26f9a6c9.zip
gitbook-b07681a16a291a38fdbdfa3065a747ab26f9a6c9.tar.gz
gitbook-b07681a16a291a38fdbdfa3065a747ab26f9a6c9.tar.bz2
Quiz with GFM checkbox lists
Diffstat (limited to 'lib/parse/renderer.js')
-rw-r--r--lib/parse/renderer.js24
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/parse/renderer.js b/lib/parse/renderer.js
index ba543ee..2a72d48 100644
--- a/lib/parse/renderer.js
+++ b/lib/parse/renderer.js
@@ -91,14 +91,24 @@ GitBookRenderer.prototype.tablerow = function(content) {
return GitBookRenderer.super_.prototype.tablerow(content);
};
-GitBookRenderer.prototype.tablecell = function(content, flags) {
- var radioContent = content;
- if (content === "( )") {
- radioContent = "<input type='radio' name='quiz-row-" + this.id + "-" + this.quizRowId + "'/>";
- } else if (content === "(x)") {
- radioContent = "<input type='radio' name='quiz-row-" + this.id + "-" + this.quizRowId + "' checked/>";
+var fieldRegex = /^([(\[])([ x])[\])]/;
+GitBookRenderer.prototype._createCheckboxAndRadios = function(text) {
+ var match = fieldRegex.exec(text);
+ if (!match) {
+ return text;
}
- return GitBookRenderer.super_.prototype.tablecell(radioContent, flags);
+ var field = "<input name='quiz-row-" + this.id + "-" + this.quizRowId + "' type='";
+ field += match[1] === '(' ? "radio" : "checkbox";
+ field += match[2] === 'x' ? "' checked/>" : "'/>";
+ return text.replace(fieldRegex, field);
+}
+
+GitBookRenderer.prototype.tablecell = function(content, flags) {
+ return GitBookRenderer.super_.prototype.tablecell(this._createCheckboxAndRadios(content), flags);
+};
+
+GitBookRenderer.prototype.listitem = function(text) {
+ return GitBookRenderer.super_.prototype.listitem(this._createCheckboxAndRadios(text));
};
// Exports