diff options
Diffstat (limited to 'lib/utils/page.js')
-rw-r--r-- | lib/utils/page.js | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/lib/utils/page.js b/lib/utils/page.js index f24013f..5b4eca8 100644 --- a/lib/utils/page.js +++ b/lib/utils/page.js @@ -11,7 +11,8 @@ var links = require('./links'); var imgUtils = require('./images'); var fs = require('./fs'); var batch = require('./batch'); -var code = require('./code'); + +var parsableExtensions = require('gitbook-parsers').extensions; // Render a cheerio dom as html var renderDom = function($, dom, options) { @@ -196,11 +197,19 @@ function normalizeHtml(src, options) { var absolutePath = links.join(options.base, parts.pathname); var anchor = parts.hash || ""; + // If is in navigation relative: transform as content if (options.navigation[absolutePath]) { absolutePath = options.book.contentLink(absolutePath); } + // If md/adoc/rst files is not in summary + // or for ebook, signal all files that are outside the summary + else if (_.contains(parsableExtensions, path.extname(absolutePath)) + || _.contains(['epub', 'pdf', 'mobi'], options.book.options.generator)) { + options.book.log.warn.ln("page", options.input, "contains an hyperlink to resource outside spine '"+href+"'"); + } + // Transform as absolute href = links.toAbsolute("/"+absolutePath, options.base, options.output)+anchor; } else { @@ -214,26 +223,32 @@ function normalizeHtml(src, options) { // Highlight code blocks $("code").each(function() { - // Extract language + // Normalize language var lang = _.chain( ($(this).attr("class") || "").split(" ") ) .map(function(cl) { + // Markdown if (cl.search("lang-") === 0) return cl.slice("lang-".length); + + // Asciidoc + if (cl.search("language-") === 0) return cl.slice("language-".length); + return null; }) .compact() .first() .value(); - if (lang) { - var html = code.highlight( - lang, - $(this).text() - ); + var source = $(this).text(); + var html = options.book.template.applyBlock('code', { + body: source, + kwargs: { + language: lang + } + }).body; - $(this).html(html); - } + $(this).html(html); }); // Replace glossary terms @@ -285,7 +300,13 @@ function convertImages(images, options) { if (!image.origin && !_.contains(downloaded, image.origin)) return; options.book.log.debug("download image", image.origin, "..."); downloaded.push(image.origin); - return options.book.log.debug.promise(fs.writeStream(imgin, request(image.origin))); + return options.book.log.debug.promise(fs.writeStream(imgin, request(image.origin))) + .fail(function(err) { + if (!_.isError(err)) err = new Error(err); + + err.message = 'Fail downloading '+image.origin+': '+err.message; + throw err; + }); }) // Write svg if content |