diff options
author | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-03-30 22:02:07 -0700 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-03-30 22:02:07 -0700 |
commit | cfbdadd6e412ae7affbf23f11a9de6a938b1a74b (patch) | |
tree | 13ddd148e2be22cf527340b10e6c058af3361be9 | |
parent | 603870ee07d2d62382cf19107643e0acb79e3b58 (diff) | |
download | gitbook-cfbdadd6e412ae7affbf23f11a9de6a938b1a74b.zip gitbook-cfbdadd6e412ae7affbf23f11a9de6a938b1a74b.tar.gz gitbook-cfbdadd6e412ae7affbf23f11a9de6a938b1a74b.tar.bz2 |
Add title and path parsing for chapters & articles
-rw-r--r-- | lib/summary.js | 24 |
1 files 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) }; } |