mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 19:06:31 +00:00
Fix bug with exercise classification
This commit is contained in:
+9
-7
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user