summaryrefslogtreecommitdiffstats
path: root/lib/parse
diff options
context:
space:
mode:
Diffstat (limited to 'lib/parse')
-rw-r--r--lib/parse/renderer.js11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/parse/renderer.js b/lib/parse/renderer.js
index 625a7ce..4da312e 100644
--- a/lib/parse/renderer.js
+++ b/lib/parse/renderer.js
@@ -18,6 +18,7 @@ function GitBookRenderer(options, extra_options) {
this._extra_options = extra_options;
this.quizRowId = 0;
this.id = rendererId++;
+ this.quizIndex = 0;
}
inherits(GitBookRenderer, marked.Renderer);
@@ -66,7 +67,7 @@ GitBookRenderer.prototype.link = function(href, title, text) {
} else if (o && o.repo && o.dir) {
href = url.resolve('https://github.com/' + o.repo + '/blob/', [o.dir, _href].join("/"));
parsed = url.parse(href);
- _href = parsed.href;
+ _href = parsed.href;
}
}
@@ -116,10 +117,14 @@ GitBookRenderer.prototype._createCheckboxAndRadios = function(text) {
if (!match) {
return text;
}
- var field = "<input name='quiz-row-" + this.id + "-" + this.quizRowId + "' type='";
+ var quizIdentifier = 'quiz-row-' + this.id + '-' + this.quizRowId + '-' + this.quizIndex++;
+ var field = "<input name='" + quizIdentifier + "' id='" + quizIdentifier + "' type='";
field += match[1] === '(' ? "radio" : "checkbox";
field += match[2] === 'x' ? "' checked/>" : "'/>";
- return text.replace(fieldRegex, field);
+ var splittedText = text.split(fieldRegex);
+ var length = splittedText.length;
+ var label = '<label class="quiz-label" for="' + quizIdentifier + '">' + splittedText[length - 1] + '</label>';
+ return text.replace(fieldRegex, field).replace(splittedText[length - 1], label);
}
GitBookRenderer.prototype.tablecell = function(content, flags) {