Add title and path parsing for chapters & articles

This commit is contained in:
Aaron O'Mullan
2014-03-30 22:02:07 -07:00
parent 603870ee07
commit cfbdadd6e4
+22 -2
View File
@@ -60,13 +60,33 @@ function filterList(nodes) {
.value().slice(1, -1);
}
// Parses an Article or Chapter title
// supports extracting links
function parseTitle(src) {
// Check if it's a link
var matches = marked.InlineLexer.rules.link.exec(src);
// Not a link, return plain text
if(!matches) {
return {
title: src,
path: null,
};
}
return {
title: matches[1],
path: matches[2],
};
}
function parseArticle(nodes) {
return _.first(nodes).text;
return parseTitle(_.first(nodes).text);
}
function parseChapter(nodes) {
return {
chapter: _.first(nodes).text,
chapter: parseTitle(_.first(nodes).text),
articles: _.map(listSplit(filterList(nodes), 'list_item_start', 'list_item_end'), parseArticle)
};
}