mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 19:06:31 +00:00
Add initial page parsing
(Split sections)
This commit is contained in:
+28
@@ -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;
|
||||
Reference in New Issue
Block a user