Skip to content

Commit e54b808

Browse files
author
Aaron O'Mullan
committed
Improve section detection, fixes GitbookIO#68
1 parent 04774df commit e54b808

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/parse/lex.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ function splitSections(nodes) {
1919

2020
// What is the type of this section
2121
function sectionType(nodes, idx) {
22-
var codeNodes = _.filter(nodes, {
23-
type: 'code'
24-
}).length;
22+
var codeType = { type: 'code' };
23+
24+
// Number of code nodes in section
25+
var len = _.filter(nodes, codeType).length;
2526

2627
if(
27-
(codeNodes === 3 || codeNodes === 4) &&
28-
(idx % 2) === 1)
28+
// Got 3 or 4 code blocks
29+
(len === 3 || len === 4) &&
30+
// Ensure all nodes are at the end
31+
_.all(_.last(nodes, len), codeType)
32+
)
2933
{
3034
return 'exercise';
3135
}

0 commit comments

Comments
 (0)