summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2015-05-28 14:49:53 +0200
committerSamy Pesse <samypesse@gmail.com>2015-05-28 14:49:53 +0200
commit32203f643825c12e7869006896b03f08cfaa43cc (patch)
tree2cd6b897415238a99aae493a82471d4c8d9c81ba
parentf2d3c5d2ed85d3924666a00caa8a28549d2ba292 (diff)
downloadgitbook-32203f643825c12e7869006896b03f08cfaa43cc.zip
gitbook-32203f643825c12e7869006896b03f08cfaa43cc.tar.gz
gitbook-32203f643825c12e7869006896b03f08cfaa43cc.tar.bz2
Sort glossary before applying it on pages
-rw-r--r--lib/utils/page.js7
-rw-r--r--test/glossary.js2
2 files changed, 6 insertions, 3 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
diff --git a/test/glossary.js b/test/glossary.js
index 14c3cf7..fb573d9 100644
--- a/test/glossary.js
+++ b/test/glossary.js
@@ -76,7 +76,7 @@ describe('Glossary', function () {
it('should correctly select the longest term', function() {
readme.should.be.html({
- ".page-inner a[href='GLOSSARY.html#test-long']": {
+ ".page-inner a[href='GLOSSARY.html#test_long']": {
count: 1,
text: "test long"
}