Fix bug with exercise classification

This commit is contained in:
Aaron O'Mullan
2014-03-31 12:40:51 -07:00
parent d98669958d
commit 264a506e8b
+9 -7
View File
@@ -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,
};