Add ability to ignore headers when generating toc (#127)
* Added ability to ignore some or all headings when generating toc in sidebar * Added documentation for ignoring sub headers * Fixed minor test issues
This commit is contained in:
parent
788bbb36b4
commit
d57b80e224
14 changed files with 63 additions and 17 deletions
|
|
@ -2992,10 +2992,24 @@ markdown.update = function () {
|
|||
* @link https://github.com/chjj/marked#overriding-renderer-methods
|
||||
*/
|
||||
renderer.heading = function (text, level) {
|
||||
var nextToc = { level: level, title: text };
|
||||
|
||||
if (/{docsify-ignore}/g.test(text)) {
|
||||
text = text.replace('{docsify-ignore}','');
|
||||
nextToc.title = text;
|
||||
nextToc.ignoreSubHeading = true;
|
||||
}
|
||||
|
||||
if (/{docsify-ignore-all}/g.test(text)) {
|
||||
text = text.replace('{docsify-ignore-all}','');
|
||||
nextToc.title = text;
|
||||
nextToc.ignoreAllSubs = true;
|
||||
}
|
||||
|
||||
var slug = slugify(text);
|
||||
var url = toURL(currentPath, { id: slug });
|
||||
|
||||
toc.push({ level: level, slug: url, title: text });
|
||||
nextToc.slug = url;
|
||||
toc.push(nextToc);
|
||||
|
||||
return ("<h" + level + " id=\"" + slug + "\"><a href=\"" + url + "\" data-id=\"" + slug + "\" class=\"anchor\"><span>" + text + "</span></a></h" + level + ">")
|
||||
};
|
||||
|
|
@ -3017,7 +3031,7 @@ renderer.link = function (href, title, text) {
|
|||
if (title) {
|
||||
title = " title=\"" + title + "\"";
|
||||
}
|
||||
return ("<a href=\"" + href + "\"" + title + blank + ">" + text + "</a>")
|
||||
return ("<a href=\"" + href + "\"" + (title || '') + blank + ">" + text + "</a>")
|
||||
};
|
||||
renderer.paragraph = function (text) {
|
||||
if (/^!>/.test(text)) {
|
||||
|
|
@ -3061,7 +3075,11 @@ function sidebar (text, level) {
|
|||
*/
|
||||
function subSidebar (el, level) {
|
||||
if (el) {
|
||||
toc[0] && toc[0].ignoreAllSubs && (toc = []);
|
||||
toc[0] && toc[0].level === 1 && toc.shift();
|
||||
toc.forEach(function (node, i) {
|
||||
node.ignoreSubHeading && toc.splice(i, 1);
|
||||
});
|
||||
var tree$$1 = cacheTree[currentPath] || genTree(toc, level);
|
||||
el.parentNode.innerHTML += tree(tree$$1, '<ul class="app-sub-sidebar">');
|
||||
cacheTree[currentPath] = tree$$1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue