diff options
author | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-10-13 15:07:46 +0200 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-10-13 15:07:46 +0200 |
commit | d730a3aac601f000d770dbccca02ac4bb2d07245 (patch) | |
tree | f80730d3e1aeb578faa69bc25ed75e1dc93cfa75 /lib/parse/is_exercise.js | |
parent | ffb0b1201268134ca697723b473ec74c010442d3 (diff) | |
download | gitbook-d730a3aac601f000d770dbccca02ac4bb2d07245.zip gitbook-d730a3aac601f000d770dbccca02ac4bb2d07245.tar.gz gitbook-d730a3aac601f000d770dbccca02ac4bb2d07245.tar.bz2 |
Split section classification to separate files
Maybe have a sections folder in the future and one per type
(quiz/exercise/normal) ?
Diffstat (limited to 'lib/parse/is_exercise.js')
-rw-r--r-- | lib/parse/is_exercise.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/parse/is_exercise.js b/lib/parse/is_exercise.js new file mode 100644 index 0000000..74ed753 --- /dev/null +++ b/lib/parse/is_exercise.js @@ -0,0 +1,17 @@ +var _ = require('lodash'); + +function isExercise(nodes) { + var codeType = { type: 'code' }; + + // Number of code nodes in section + var len = _.filter(nodes, codeType).length; + + return ( + // Got 3 or 4 code blocks + (len === 3 || len === 4) && + // Ensure all nodes are at the end + _.all(_.last(nodes, len), codeType) + ); +} + +module.exports = isExercise; |