summaryrefslogtreecommitdiffstats
path: root/lib/page.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/page.js')
-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;