summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@friendco.de>2014-03-30 22:36:22 -0700
committerAaron O'Mullan <aaron.omullan@friendco.de>2014-03-30 22:36:22 -0700
commitc21303c762e0bd019a1fbe54a0b6ec6408dfc685 (patch)
tree48e151fab89a27239350224510b20109ec98a752
parent4c1435f27f7c17ffb8dcdd8c9f0f6b870c3e14ce (diff)
downloadgitbook-c21303c762e0bd019a1fbe54a0b6ec6408dfc685.zip
gitbook-c21303c762e0bd019a1fbe54a0b6ec6408dfc685.tar.gz
gitbook-c21303c762e0bd019a1fbe54a0b6ec6408dfc685.tar.bz2
Add section type detection
-rw-r--r--lib/page.js18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/page.js b/lib/page.js
index 3eabb09..1929f6b 100644
--- a/lib/page.js
+++ b/lib/page.js
@@ -18,10 +18,26 @@ function splitSections(nodes) {
}, []).concat([section]); // Add remaining nodes
}
+// What is the type of this section
+function sectionType(nodes) {
+ if(_.filter(nodes, {
+ type: 'code'
+ }).length === 3) {
+ return 'exercise';
+ }
+
+ return 'normal';
+}
+
function parsePage(src) {
var nodes = marked.lexer(src);
- return splitSections(nodes);
+ return _.chain(splitSections(nodes))
+ .map(function(section) {
+ section.type = sectionType(section);
+ return section;
+ })
+ .value();
}
// Exports