diff options
Diffstat (limited to 'lib/parse/renderer.js')
-rw-r--r-- | lib/parse/renderer.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/parse/renderer.js b/lib/parse/renderer.js index 6b45a22..ba543ee 100644 --- a/lib/parse/renderer.js +++ b/lib/parse/renderer.js @@ -5,6 +5,7 @@ var path = require('path'); var marked = require('marked'); +var rendererId = 0; function GitBookRenderer(options, extra_options) { if(!(this instanceof GitBookRenderer)) { @@ -13,6 +14,8 @@ function GitBookRenderer(options, extra_options) { GitBookRenderer.super_.call(this, options); this._extra_options = extra_options; + this.quizRowId = 0; + this.id = rendererId++; } inherits(GitBookRenderer, marked.Renderer); @@ -83,6 +86,20 @@ GitBookRenderer.prototype.image = function(href, title, text) { return GitBookRenderer.super_.prototype.image.call(this, _href, title, text); }; +GitBookRenderer.prototype.tablerow = function(content) { + this.quizRowId += 1; + 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/>"; + } + return GitBookRenderer.super_.prototype.tablecell(radioContent, flags); +}; // Exports module.exports = GitBookRenderer; |