mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 19:06:31 +00:00
Add title and path parsing for chapters & articles
This commit is contained in:
+22
-2
@@ -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)
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user