summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/summary.js24
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)
};
}