diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-05-28 15:21:03 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-05-28 15:21:03 +0200 |
commit | 946883fd4c7aebe625868df3d90728f6d69607ce (patch) | |
tree | 5c972e11da8d86c2389452c6e41c0b838de7ecce /lib/utils | |
parent | b1b7e3148b132abf8fe79bf1f7021370f0822f55 (diff) | |
parent | 32203f643825c12e7869006896b03f08cfaa43cc (diff) | |
download | gitbook-946883fd4c7aebe625868df3d90728f6d69607ce.zip gitbook-946883fd4c7aebe625868df3d90728f6d69607ce.tar.gz gitbook-946883fd4c7aebe625868df3d90728f6d69607ce.tar.bz2 |
Merge pull request #772 from GitbookIO/feature/glossary_order
Fix #768: sort glossary, start with longest matchs
Diffstat (limited to 'lib/utils')
-rw-r--r-- | lib/utils/page.js | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/utils/page.js b/lib/utils/page.js index 9b33b96..f24013f 100644 --- a/lib/utils/page.js +++ b/lib/utils/page.js @@ -237,13 +237,16 @@ function normalizeHtml(src, options) { }); // Replace glossary terms - _.each(options.glossary, function(term) { + var glossary = _.sortBy(options.glossary, function(term) { + return -term.name.length; + }); + _.each(glossary, function(term) { var r = new RegExp( "\\b(" + pregQuote(term.name.toLowerCase()) + ")\\b" , 'gi' ); var includedInFiles = false; $("*").each(function() { // Ignore codeblocks - if (_.contains(["code", "pre"], this.name.toLowerCase())) return; + if (_.contains(["code", "pre", "a"], this.name.toLowerCase())) return; replaceText($, this, r, function(match) { // Add to files index in glossary |