diff options
author | James Phillpotts <jphillpotts@scottlogic.co.uk> | 2014-04-10 10:29:17 +0100 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-04-12 01:26:03 -0700 |
commit | b07681a16a291a38fdbdfa3065a747ab26f9a6c9 (patch) | |
tree | ffb07c822518e689e619dc1ac8780f10877f7b7f /lib/parse/renderer.js | |
parent | f6595f51119baca04bf91e619f64518d400e5cae (diff) | |
download | gitbook-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.js | 24 |
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 |