diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-10 11:34:56 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-10 11:34:56 +0200 |
commit | 02d8272c74b8b7f2da4e39c432e6521047ea8900 (patch) | |
tree | 597c0f89600a5c35e1e6f32cc67a6a1ed66579c5 /lib/parse | |
parent | 2e85380cd822e05072b00d5f2493c263ac194395 (diff) | |
parent | e54b8080933f7e85df6b2182cc171dd3dc28f8a4 (diff) | |
download | gitbook-02d8272c74b8b7f2da4e39c432e6521047ea8900.zip gitbook-02d8272c74b8b7f2da4e39c432e6521047ea8900.tar.gz gitbook-02d8272c74b8b7f2da4e39c432e6521047ea8900.tar.bz2 |
Merge pull request #77 from GitbookIO/improve/sections_lexing
Improve/sections lexing
Diffstat (limited to 'lib/parse')
-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'; } |