bit-docs-html-toc
Advanced tools
Comparing version 0.3.0 to 0.4.0
{ | ||
"name": "bit-docs-html-toc", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "table of contents bit-docs plugin", | ||
@@ -5,0 +5,0 @@ "main": "toc.js", |
19
toc.js
@@ -23,2 +23,9 @@ var stache = require("can-stache"); | ||
function makeAnchorHeadingId(anchorText) { | ||
return (anchorText || "") | ||
.replace(/\s/g, "-") // replace spaces with dashes | ||
.replace(/[^\w\-]/g, "") // remove punctuation | ||
.toLowerCase(); | ||
} | ||
function outerHeight(el) { | ||
@@ -102,5 +109,13 @@ var height = el.offsetHeight; | ||
var navHeight = this.navHeight; | ||
return [].map.call(titles, function(title, idx){ | ||
var headings = {}; | ||
return [].map.call(titles, function(title, idx) { | ||
var txt = title.textContent; | ||
title.id = 'section_' + txt.replace(/\s/g,"").replace(/[^\w]/g,"_"); | ||
var id = makeAnchorHeadingId(txt); | ||
var count = headings[id] || 0; | ||
// add unique id if we get headings with the same text | ||
title.id = makeAnchorHeadingId(txt) + (count > 0 ? "-" + count : ""); | ||
headings[id] = count + 1; | ||
return { | ||
@@ -107,0 +122,0 @@ id: title.id, |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
10282
308
0