Add initial page parsing

(Split sections)
This commit is contained in:
Aaron O'Mullan
2014-03-30 22:30:45 -07:00
parent 9284eb4115
commit 0199e56000
+28
View File
@@ -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;