diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-05-26 21:10:06 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-05-26 21:10:06 +0200 |
commit | b47ebaa9d91ecc0a1a1678eb8da79837a3cfee19 (patch) | |
tree | b0768304482c15b1387a41e9c828e1739bdfc52e /lib | |
parent | ecd86ec8778fdf54c5a8e6edef618cde89336641 (diff) | |
download | gitbook-b47ebaa9d91ecc0a1a1678eb8da79837a3cfee19.zip gitbook-b47ebaa9d91ecc0a1a1678eb8da79837a3cfee19.tar.gz gitbook-b47ebaa9d91ecc0a1a1678eb8da79837a3cfee19.tar.bz2 |
Use real glossary name when annotating
Diffstat (limited to 'lib')
-rw-r--r-- | lib/output/getModifiers.js | 9 | ||||
-rw-r--r-- | lib/output/modifiers/__tests__/annotateText.js | 6 | ||||
-rw-r--r-- | lib/output/modifiers/annotateText.js | 5 |
3 files changed, 13 insertions, 7 deletions
diff --git a/lib/output/getModifiers.js b/lib/output/getModifiers.js index e649df6..4dbeb2e 100644 --- a/lib/output/getModifiers.js +++ b/lib/output/getModifiers.js @@ -4,6 +4,7 @@ var Api = require('../api'); var Plugins = require('../plugins'); var Promise = require('../utils/promise'); var defaultBlocks = require('../constants/defaultBlocks'); +var fileToOutput = require('./helper/fileToOutput'); var CODEBLOCK = 'code'; @@ -17,9 +18,13 @@ function getModifiers(output, page) { var book = output.getBook(); var plugins = output.getPlugins(); var glossary = book.getGlossary(); - var entries = glossary.getEntries(); var file = page.getFile(); + // Glossary entries + var entries = glossary.getEntries(); + var glossaryFile = glossary.getFile(); + var glossaryFilename = fileToOutput(output, glossaryFile.getPath()); + // Current file path var currentFilePath = file.getPath(); @@ -44,7 +49,7 @@ function getModifiers(output, page) { Modifiers.resolveImages.bind(null, currentFilePath), // Annotate text with glossary entries - Modifiers.annotateText.bind(null, entries), + Modifiers.annotateText.bind(null, entries, glossaryFilename), // Highlight code blocks using "code" block Modifiers.highlightCode.bind(null, function(lang, source) { diff --git a/lib/output/modifiers/__tests__/annotateText.js b/lib/output/modifiers/__tests__/annotateText.js index 40b1e6c..67e7a10 100644 --- a/lib/output/modifiers/__tests__/annotateText.js +++ b/lib/output/modifiers/__tests__/annotateText.js @@ -12,7 +12,7 @@ describe('annotateText', function() { it('should annotate text', function() { var $ = cheerio.load('<p>This is a word, and multiple words</p>'); - annotateText(entries, $); + annotateText(entries, 'GLOSSARY.md', $); var links = $('a'); expect(links.length).toBe(2); @@ -31,14 +31,14 @@ describe('annotateText', function() { it('should not annotate scripts', function() { var $ = cheerio.load('<script>This is a word, and multiple words</script>'); - annotateText(entries, $); + annotateText(entries, 'GLOSSARY.md', $); expect($('a').length).toBe(0); }); it('should not annotate when has class "no-glossary"', function() { var $ = cheerio.load('<p class="no-glossary">This is a word, and multiple words</p>'); - annotateText(entries, $); + annotateText(entries, 'GLOSSARY.md', $); expect($('a').length).toBe(0); }); }); diff --git a/lib/output/modifiers/annotateText.js b/lib/output/modifiers/annotateText.js index d8443cf..2b4b439 100644 --- a/lib/output/modifiers/annotateText.js +++ b/lib/output/modifiers/annotateText.js @@ -62,9 +62,10 @@ function replaceText($, el, search, replace, text_only ) { Annotate text using a list of GlossaryEntry @param {List<GlossaryEntry>} + @param {String} glossaryFilePath @param {HTMLDom} $ */ -function annotateText(entries, $) { +function annotateText(entries, glossaryFilePath, $) { entries.forEach(function(entry) { var entryId = entry.getID(); var name = entry.getName(); @@ -81,7 +82,7 @@ function annotateText(entries, $) { ) return; replaceText($, this, searchRegex, function(match) { - return '<a href="/GLOSSARY.md#' + entryId + '" ' + return '<a href="/' + glossaryFilePath + '#' + entryId + '" ' + 'class="glossary-term" title="' + escape(description) + '">' + match + '</a>'; |