diff options
Diffstat (limited to 'lib/parse/summary.js')
-rw-r--r-- | lib/parse/summary.js | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/parse/summary.js b/lib/parse/summary.js index 1237b37..0995c40 100644 --- a/lib/parse/summary.js +++ b/lib/parse/summary.js @@ -62,20 +62,24 @@ function filterList(nodes) { // Parses an Article or Chapter title // supports extracting links -function parseTitle(src) { +function parseTitle(src, nums) { // Check if it's a link var matches = marked.InlineLexer.rules.link.exec(src); + var level = nums.join('.'); + // Not a link, return plain text if(!matches) { return { title: src, + level: level, path: null, }; } return { title: matches[1], + level: level, // Replace .md references with .html path: matches[2].replace(/\.md$/, '.html'), @@ -85,13 +89,13 @@ function parseTitle(src) { }; } -function parseArticle(nodes) { - return parseTitle(_.first(nodes).text); +function parseArticle(chapterNum, nodes, idx) { + return parseTitle(_.first(nodes).text, [chapterNum, idx+1]); } -function parseChapter(nodes) { - return _.extend(parseTitle(_.first(nodes).text), { - articles: _.map(listSplit(filterList(nodes), 'list_item_start', 'list_item_end'), parseArticle) +function parseChapter(nodes, idx) { + return _.extend(parseTitle(_.first(nodes).text, [idx+1]), { + articles: _.map(listSplit(filterList(nodes), 'list_item_start', 'list_item_end'), parseArticle.bind(null, idx+1)) }); } |