summaryrefslogtreecommitdiffstats
path: root/lib/parse/renderer.js
diff options
context:
space:
mode:
authorJames Phillpotts <jphillpotts@scottlogic.co.uk>2014-04-08 09:51:11 +0100
committerAaron O'Mullan <aaron.omullan@friendco.de>2014-04-12 01:25:07 -0700
commitf6595f51119baca04bf91e619f64518d400e5cae (patch)
tree765ad8ab0f40d3bb68c03e8df1d5246664556e9c /lib/parse/renderer.js
parentab27725b9935b185a58b725e75aedeb579e87d8f (diff)
downloadgitbook-f6595f51119baca04bf91e619f64518d400e5cae.zip
gitbook-f6595f51119baca04bf91e619f64518d400e5cae.tar.gz
gitbook-f6595f51119baca04bf91e619f64518d400e5cae.tar.bz2
Tabular quiz
Diffstat (limited to 'lib/parse/renderer.js')
-rw-r--r--lib/parse/renderer.js17
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;