summaryrefslogtreecommitdiffstats
path: root/lib/parse/page.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/page.js
parentab27725b9935b185a58b725e75aedeb579e87d8f (diff)
downloadgitbook-f6595f51119baca04bf91e619f64518d400e5cae.zip
gitbook-f6595f51119baca04bf91e619f64518d400e5cae.tar.gz
gitbook-f6595f51119baca04bf91e619f64518d400e5cae.tar.bz2
Tabular quiz
Diffstat (limited to 'lib/parse/page.js')
-rw-r--r--lib/parse/page.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/parse/page.js b/lib/parse/page.js
index 3479c85..4e26455 100644
--- a/lib/parse/page.js
+++ b/lib/parse/page.js
@@ -36,6 +36,10 @@ function render(section, _options) {
return marked.parser(section, options);
}
+function quizNodesTest(node) {
+ return node.type === 'table' || node.type === 'list';
+}
+
function parsePage(src, options) {
options = options || {};
@@ -76,6 +80,20 @@ function parsePage(src, options) {
context: codeNodes[3] ? codeNodes[3].text : null,
}
};
+ } else if (section.type === 'quiz') {
+ var nonQuizNodes = _.reject(section, quizNodesTest);
+ var quizNodes = _.filter(section, quizNodesTest);
+ var feedback = nonQuizNodes.splice(_.findIndex(nonQuizNodes, { type: 'blockquote_start' }), _.findIndex(nonQuizNodes, { type: 'blockquote_end' }));
+ return {
+ id: section.id,
+ type: section.type,
+ content: render(nonQuizNodes),
+ quiz: {
+ base: render([quizNodes[0]]),
+ solution: render([quizNodes[1]]),
+ feedback: render(feedback.slice(1, feedback.length - 1))
+ }
+ };
}
// Render normal pages