diff options
author | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-03-30 22:30:45 -0700 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-03-30 22:30:45 -0700 |
commit | 0199e5600009989f511169f0bd8300e92fd0fd9b (patch) | |
tree | dcfa5dd099d7b0665a0ce4100c40b7c748495f58 | |
parent | 9284eb4115a38d1a45f12b343a4bf9a4cae90331 (diff) | |
download | gitbook-0199e5600009989f511169f0bd8300e92fd0fd9b.zip gitbook-0199e5600009989f511169f0bd8300e92fd0fd9b.tar.gz gitbook-0199e5600009989f511169f0bd8300e92fd0fd9b.tar.bz2 |
Add initial page parsing
(Split sections)
-rw-r--r-- | lib/page.js | 28 |
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; |