From cfbdadd6e412ae7affbf23f11a9de6a938b1a74b Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Sun, 30 Mar 2014 22:02:07 -0700 Subject: Add title and path parsing for chapters & articles --- lib/summary.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/summary.js b/lib/summary.js index 37e920a..8787554 100644 --- a/lib/summary.js +++ b/lib/summary.js @@ -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) }; } -- cgit v1.1