diff options
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 |