diff options
Diffstat (limited to 'lib/backbone/summary.js')
-rw-r--r-- | lib/backbone/summary.js | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/backbone/summary.js b/lib/backbone/summary.js index 4ae3453..a79b1e9 100644 --- a/lib/backbone/summary.js +++ b/lib/backbone/summary.js @@ -6,7 +6,6 @@ var location = require('../utils/location'); var error = require('../utils/error'); var BackboneFile = require('./file'); - /* An article represent an entry in the Summary. It's defined by a title, a reference, and children articles, @@ -37,8 +36,9 @@ function TOCArticle(def, parent) { var parts = url.parse(this.ref); if (!this.isExternal()) { - this.path = parts.pathname; - this.anchor = parts.hash; + var parts = this.ref.split('#'); + this.path = (parts.length > 1? parts.slice(0, -1).join('#') : this.ref); + this.anchor = (parts.length > 1? '#' + _.last(parts) : null); } } @@ -264,6 +264,17 @@ Summary.prototype.find = function(filter) { return result; }; +// Flatten the list of articles +Summary.prototype.flatten = function() { + var result = []; + + this.walk(function(article) { + result.push(article); + }); + + return result; +}; + // Return the first TOCArticle for a specific page (or path) Summary.prototype.getArticle = function(page) { if (!_.isString(page)) page = page.path; |