diff options
-rw-r--r-- | lib/parse/page.js | 16 |
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, }; |