diff options
author | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-04-10 02:32:37 -0700 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-04-10 02:32:37 -0700 |
commit | e54b8080933f7e85df6b2182cc171dd3dc28f8a4 (patch) | |
tree | 597c0f89600a5c35e1e6f32cc67a6a1ed66579c5 /lib | |
parent | 04774df3724ba96a80a07371244c2d47426720c0 (diff) | |
download | gitbook-e54b8080933f7e85df6b2182cc171dd3dc28f8a4.zip gitbook-e54b8080933f7e85df6b2182cc171dd3dc28f8a4.tar.gz gitbook-e54b8080933f7e85df6b2182cc171dd3dc28f8a4.tar.bz2 |
Improve section detection, fixes #68
Diffstat (limited to 'lib')
-rw-r--r-- | lib/parse/lex.js | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/parse/lex.js b/lib/parse/lex.js index def74b4..cec6047 100644 --- a/lib/parse/lex.js +++ b/lib/parse/lex.js @@ -19,13 +19,17 @@ function splitSections(nodes) { // What is the type of this section function sectionType(nodes, idx) { - var codeNodes = _.filter(nodes, { - type: 'code' - }).length; + var codeType = { type: 'code' }; + + // Number of code nodes in section + var len = _.filter(nodes, codeType).length; if( - (codeNodes === 3 || codeNodes === 4) && - (idx % 2) === 1) + // Got 3 or 4 code blocks + (len === 3 || len === 4) && + // Ensure all nodes are at the end + _.all(_.last(nodes, len), codeType) + ) { return 'exercise'; } |