summaryrefslogtreecommitdiffstats
path: root/lib/parse/page.js
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@friendco.de>2014-03-31 12:40:51 -0700
committerAaron O'Mullan <aaron.omullan@friendco.de>2014-03-31 12:40:53 -0700
commit264a506e8b3039b89fe0aa1d8e8f3f33cc360cff (patch)
treeebef681556b76ff6eff7c687da863c90235f1d18 /lib/parse/page.js
parentd98669958dfd626009c680f1b712da18966bbd5a (diff)
downloadgitbook-264a506e8b3039b89fe0aa1d8e8f3f33cc360cff.zip
gitbook-264a506e8b3039b89fe0aa1d8e8f3f33cc360cff.tar.gz
gitbook-264a506e8b3039b89fe0aa1d8e8f3f33cc360cff.tar.bz2
Fix bug with exercise classification
Diffstat (limited to 'lib/parse/page.js')
-rw-r--r--lib/parse/page.js16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/parse/page.js b/lib/parse/page.js
index b1e4332..79f5e7e 100644
--- a/lib/parse/page.js
+++ b/lib/parse/page.js
@@ -21,10 +21,12 @@ function splitSections(nodes) {
}
// What is the type of this section
-function sectionType(nodes) {
- if(_.filter(nodes, {
+function sectionType(nodes, idx) {
+ var codeNodes = _.filter(nodes, {
type: 'code'
- }).length === 3) {
+ }).length;
+
+ if(codeNodes === 3 && (idx % 2) == 1) {
return 'exercise';
}
@@ -35,14 +37,14 @@ function parsePage(src) {
var nodes = marked.lexer(src);
return _.chain(splitSections(nodes))
- .map(function(section) {
+ .map(function(section, idx) {
// Detect section type
- section.type = sectionType(section);
+ section.type = sectionType(section, idx);
return section;
})
- .map(function(section, idx) {
+ .map(function(section) {
// Transform given type
- if(section.type === 'exercise' && (idx % 2) == 1) {
+ if(section.type === 'exercise') {
return {
type: section.type,
};