summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@friendco.de>2014-03-30 22:30:45 -0700
committerAaron O'Mullan <aaron.omullan@friendco.de>2014-03-30 22:30:45 -0700
commit0199e5600009989f511169f0bd8300e92fd0fd9b (patch)
treedcfa5dd099d7b0665a0ce4100c40b7c748495f58
parent9284eb4115a38d1a45f12b343a4bf9a4cae90331 (diff)
downloadgitbook-0199e5600009989f511169f0bd8300e92fd0fd9b.zip
gitbook-0199e5600009989f511169f0bd8300e92fd0fd9b.tar.gz
gitbook-0199e5600009989f511169f0bd8300e92fd0fd9b.tar.bz2
Add initial page parsing
(Split sections)
-rw-r--r--lib/page.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/page.js b/lib/page.js
new file mode 100644
index 0000000..3eabb09
--- /dev/null
+++ b/lib/page.js
@@ -0,0 +1,28 @@
+var _ = require('lodash');
+var marked = require('marked');
+
+
+// Split a page up into sections (lesson, exercises, ...)
+function splitSections(nodes) {
+ var section = [];
+
+ return _.reduce(nodes, function(sections, el) {
+ if(el.type === 'hr') {
+ sections.push(section);
+ section = [];
+ } else {
+ section.push(el);
+ }
+
+ return sections;
+ }, []).concat([section]); // Add remaining nodes
+}
+
+function parsePage(src) {
+ var nodes = marked.lexer(src);
+
+ return splitSections(nodes);
+}
+
+// Exports
+module.exports = parsePage;