From 0199e5600009989f511169f0bd8300e92fd0fd9b Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Sun, 30 Mar 2014 22:30:45 -0700 Subject: [PATCH] Add initial page parsing (Split sections) --- lib/page.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lib/page.js diff --git a/lib/page.js b/lib/page.js new file mode 100644 index 000000000..3eabb0993 --- /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;