diff options
author | Nattaphoom Ch <attomos@gmail.com> | 2014-04-24 01:19:13 +0700 |
---|---|---|
committer | Nattaphoom Ch <attomos@gmail.com> | 2014-04-24 01:19:13 +0700 |
commit | 8f4b799d3cb2ed0377e0191e9711fe91e9a1ce89 (patch) | |
tree | 68d51f84c6815ee11e3d7012f2fc756e682c8249 /lib/parse/renderer.js | |
parent | 9abbabbce3fefc3a5bb2fd4e3fe409b0265a7564 (diff) | |
download | gitbook-8f4b799d3cb2ed0377e0191e9711fe91e9a1ce89.zip gitbook-8f4b799d3cb2ed0377e0191e9711fe91e9a1ce89.tar.gz gitbook-8f4b799d3cb2ed0377e0191e9711fe91e9a1ce89.tar.bz2 |
Make quiz easier to click by surround it with label.
Diffstat (limited to 'lib/parse/renderer.js')
-rw-r--r-- | lib/parse/renderer.js | 11 |
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) { |