metalsmith-autotoc
Advanced tools
Comparing version 0.1.0 to 0.1.1
20
index.js
@@ -43,2 +43,7 @@ | ||
/** | ||
* @param {Function} [options.slug] | ||
* @param {String} [options.selector] | ||
* @param {String} [options.headerIdPrefix] | ||
*/ | ||
module.exports = function(options) { | ||
@@ -48,11 +53,6 @@ options = options || {}; | ||
options.headerIdPrefix = options.headerIdPrefix || ''; | ||
options.slug = options.slug || function(innerHTML) { | ||
return options.headerIdPrefix + slug(innerHTML); | ||
}; | ||
function generateId(header) { | ||
if (!header.id) { | ||
return options.headerIdPrefix + slug(header.innerHTML); | ||
} else { | ||
return header.id; | ||
} | ||
} | ||
function getRootLevel(headers) { | ||
@@ -133,3 +133,5 @@ return headers.map(function(header) { | ||
).map(function(header) { | ||
header.id = generateId(header); | ||
if (!header.id) { | ||
header.id = options.slug(header.innerHTML); | ||
} | ||
return header; | ||
@@ -136,0 +138,0 @@ }); |
{ | ||
"name": "metalsmith-autotoc", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "A metalsmith plugin to generate table of contents of a document.", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:anatoo/metalsmith-autotoc.git", |
@@ -36,12 +36,12 @@ # metalsmith-autotoc | ||
--- | ||
<h2 id="aaa">aaa</h2> | ||
<h2>aaa</h2> | ||
<p>paragraph</p> | ||
<h3 id="bbb">bbb</h3> | ||
<h3>bbb</h3> | ||
<p>paragraph</p> | ||
<h3 id="ccc">ccc</h3> | ||
<h3>ccc</h3> | ||
<p>paragraph</p> | ||
<h2 id="ddd">ddd</h2> | ||
<h2>ddd</h2> | ||
<p>paragraph</p> | ||
@@ -48,0 +48,0 @@ ``` |
@@ -13,3 +13,2 @@ var assert = require('assert'); | ||
headerIdPrefix: 'foo-' | ||
})) | ||
@@ -16,0 +15,0 @@ .use(templates({ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8015
153