summaryrefslogtreecommitdiffstats
path: root/lib/parse
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-04-10 11:34:56 +0200
committerSamy Pessé <samypesse@gmail.com>2014-04-10 11:34:56 +0200
commit02d8272c74b8b7f2da4e39c432e6521047ea8900 (patch)
tree597c0f89600a5c35e1e6f32cc67a6a1ed66579c5 /lib/parse
parent2e85380cd822e05072b00d5f2493c263ac194395 (diff)
parente54b8080933f7e85df6b2182cc171dd3dc28f8a4 (diff)
downloadgitbook-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.js14
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';
}