diff --git a/lib/output/getModifiers.js b/lib/output/getModifiers.js index e649df680..4dbeb2e74 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 40b1e6c30..67e7a1067 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('

This is a word, and multiple words

'); - 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(''); - annotateText(entries, $); + annotateText(entries, 'GLOSSARY.md', $); expect($('a').length).toBe(0); }); it('should not annotate when has class "no-glossary"', function() { var $ = cheerio.load('

This is a word, and multiple words

'); - 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 d8443cf7f..2b4b4394f 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} + @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 '' + match + '';