summaryrefslogtreecommitdiffstats
path: root/lib/utils
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-10-21 17:58:06 +0200
committerSamy Pessé <samypesse@gmail.com>2015-10-21 17:58:06 +0200
commitdf1d5a06802154c5b6fb922c73365d2afceaecd9 (patch)
tree7efad6611750626cf2c32147bcff33760827e536 /lib/utils
parent722109faf0408fce189a142776bf10773f8682b4 (diff)
downloadgitbook-df1d5a06802154c5b6fb922c73365d2afceaecd9.zip
gitbook-df1d5a06802154c5b6fb922c73365d2afceaecd9.tar.gz
gitbook-df1d5a06802154c5b6fb922c73365d2afceaecd9.tar.bz2
Correctly generate id if none found
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/page.js18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/utils/page.js b/lib/utils/page.js
index c79f237..739b59c 100644
--- a/lib/utils/page.js
+++ b/lib/utils/page.js
@@ -6,6 +6,7 @@ var cheerio = require('cheerio');
var domSerializer = require('dom-serializer');
var request = require('request');
var crc = require('crc');
+var slug = require('github-slugid');
var links = require('./links');
var imgUtils = require('./images');
@@ -14,18 +15,18 @@ var batch = require('./batch');
var parsableExtensions = require('gitbook-parsers').extensions;
+// Map of images that have been converted
+var imgConversionCache = {};
+
// Render a cheerio dom as html
-var renderDom = function($, dom, options) {
+function renderDom($, dom, options) {
if (!dom && $._root && $._root.children) {
dom = $._root.children;
}
options = options|| dom.options || $._options;
return domSerializer(dom, options);
-};
-
-// Map of images that have been converted
-var imgConversionCache = {};
+}
function replaceText($, el, search, replace, text_only ) {
return $(el).each(function(){
@@ -114,6 +115,13 @@ function normalizeHtml(src, options) {
});
}
+ // Generate ID for headings
+ $('h1,h2,h3,h4,h5,h6').each(function() {
+ if ($(this).attr('id')) return;
+
+ $(this).attr('id', slug($(this).text()));
+ });
+
// Find images to normalize
$('img').each(function() {
var origin;