summaryrefslogtreecommitdiffstats
path: root/lib/utils/page.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils/page.js')
-rw-r--r--lib/utils/page.js28
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/utils/page.js b/lib/utils/page.js
index 689cf74..3c7d0b0 100644
--- a/lib/utils/page.js
+++ b/lib/utils/page.js
@@ -11,6 +11,7 @@ var links = require('./links');
var imgUtils = require('./images');
var fs = require('./fs');
var batch = require('./batch');
+var code = require('./code');
// Render a cheerio dom as html
var renderDom = function($, dom, options) {
@@ -183,6 +184,7 @@ function normalizeHtml(src, options) {
$(this).attr("src", src);
});
+ // Normalize links
$("a").each(function() {
var href = $(this).attr("href");
if (!href) return;
@@ -210,7 +212,31 @@ function normalizeHtml(src, options) {
$(this).attr("href", href);
});
- // Replace glossayr terms
+ // Highlight code blocks
+ $("code").each(function() {
+ // Extract language
+ var lang = _.chain(
+ ($(this).attr("class") || "").split(" ")
+ )
+ .map(function(cl) {
+ if (cl.search("lang-") === 0) return cl.slice("lang-".length);
+ return null;
+ })
+ .compact()
+ .first()
+ .value();
+
+ if (lang) {
+ var html = code.highlight(
+ lang,
+ $(this).text()
+ );
+
+ $(this).html(html);
+ }
+ });
+
+ // Replace glossary terms
_.each(options.glossary, function(term) {
var r = new RegExp( "\\b(" + pregQuote(term.name.toLowerCase()) + ")\\b" , 'gi' );
var includedInFiles = false;