diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-04-24 23:45:47 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-04-24 23:45:47 +0200 |
commit | 3f5c8acb3cdbf71c429ad331d23698cc53358746 (patch) | |
tree | 6b22b6cc3b447d26ff1867e6899401fa6dfe1374 /lib/output | |
parent | 93b257314aa9a6ba240ff7d9534ddb1a6ded6bc0 (diff) | |
download | gitbook-3f5c8acb3cdbf71c429ad331d23698cc53358746.zip gitbook-3f5c8acb3cdbf71c429ad331d23698cc53358746.tar.gz gitbook-3f5c8acb3cdbf71c429ad331d23698cc53358746.tar.bz2 |
Add fiel for testing resolveLinks
Diffstat (limited to 'lib/output')
-rw-r--r-- | lib/output/getModifiers.js | 26 | ||||
-rw-r--r-- | lib/output/json/onPage.js | 6 | ||||
-rw-r--r-- | lib/output/modifiers/__tests__/resolveLinks.js | 11 | ||||
-rw-r--r-- | lib/output/resolveFile.js | 21 |
4 files changed, 60 insertions, 4 deletions
diff --git a/lib/output/getModifiers.js b/lib/output/getModifiers.js new file mode 100644 index 0000000..96784fe --- /dev/null +++ b/lib/output/getModifiers.js @@ -0,0 +1,26 @@ +var Modifier = require('../modifier'); +var resolveFile = require('./resolveFile'); + +/** + Return default modifier to prepare a page + + @return <Array> +*/ +function getModifiers(output, page) { + var book = output.getBook(); + var glossary = book.getGlossary(); + var entries = glossary.getEntries(); + + var file = page.getFile(); + + return [ + Modifier.addHeadingId, + Modifier.resolveLinks.bind(null, + file.getPath(), + resolveFile.bind(null, output) + ), + Modifier.annotateText(entries) + ]; +} + +module.exports = getModifiers; diff --git a/lib/output/json/onPage.js b/lib/output/json/onPage.js index 1143aaa..8216bb9 100644 --- a/lib/output/json/onPage.js +++ b/lib/output/json/onPage.js @@ -1,6 +1,7 @@ var JSONUtils = require('../../json'); var Modifier = require('../modifier'); var Writer = require('../writer'); +var getModifiers = require('../getModifiers'); /** Write a page as a json file @@ -9,10 +10,7 @@ var Writer = require('../writer'); @param {Page} page */ function onPage(output, page) { - return Modifier.modifyHTML(page, [ - Modifier.addHeadingId, - Modifier.resolveLinks - ]) + return Modifier.modifyHTML(page, getModifiers(output, page)) .then(function(resultPage) { // Generate the JSON var json = JSONUtils.encodeBookWithPage(output.getBook(), resultPage); diff --git a/lib/output/modifiers/__tests__/resolveLinks.js b/lib/output/modifiers/__tests__/resolveLinks.js new file mode 100644 index 0000000..36511a2 --- /dev/null +++ b/lib/output/modifiers/__tests__/resolveLinks.js @@ -0,0 +1,11 @@ +jest.autoMockOff(); + +var cheerio = require('cheerio'); + +describe('resolveLinks', function() { + var resolveLinks = require('../resolveLinks'); + + +}); + + diff --git a/lib/output/resolveFile.js b/lib/output/resolveFile.js new file mode 100644 index 0000000..a3a49c5 --- /dev/null +++ b/lib/output/resolveFile.js @@ -0,0 +1,21 @@ +var PathUtils = require('../utils/path'); + +/** + Resolve an absolute path (extracted from a link) + + @param {Output} output + @param {String} filePath + @return {String} +*/ +function resolveFile(output, filePath) { + var pages = output.getPages(); + var page = pages.get(filePath); + + if (!page) { + return filePath; + } + + return PathUtils.setExtension(filePath, '.html'); +} + +module.exports = resolveFile; |