diff --git a/docs/helpers.md b/docs/helpers.md index 6bd8a069d..910846345 100644 --- a/docs/helpers.md +++ b/docs/helpers.md @@ -127,6 +127,12 @@ Only when you set both the `routerMode: 'history'` and `externalLinkTarget: '_se ### Hello, world! :id=hello-world ``` +## Customise the title for the sidebar items :sidebar="Customise title for sidebar" + +```md +### How would I write a "hello, world" example? :sidebar="Hello, world?" +``` + ## Markdown in html tag You need to insert a space between the html and markdown content. diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index 255c49642..c59f5a1c9 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -207,34 +207,32 @@ export class Compiler { */ origin.heading = renderer.heading = function (text, level) { let { str, config } = getAndRemoveConfig(text); - const nextToc = { level, title: removeAtag(str) }; + const nextToc = { level }; if (//g.test(str)) { str = str.replace('', ''); - nextToc.title = removeAtag(str); nextToc.ignoreSubHeading = true; } if (/{docsify-ignore}/g.test(str)) { str = str.replace('{docsify-ignore}', ''); - nextToc.title = removeAtag(str); nextToc.ignoreSubHeading = true; } if (//g.test(str)) { str = str.replace('', ''); - nextToc.title = removeAtag(str); nextToc.ignoreAllSubs = true; } if (/{docsify-ignore-all}/g.test(str)) { str = str.replace('{docsify-ignore-all}', ''); - nextToc.title = removeAtag(str); nextToc.ignoreAllSubs = true; } const slug = slugify(config.id || str); const url = router.toURL(router.getCurrentPath(), { id: slug }); + nextToc.title = removeAtag(str); + nextToc.text = config.sidebar || nextToc.title; nextToc.slug = url; _self.toc.push(nextToc); diff --git a/src/core/render/compiler/headline.js b/src/core/render/compiler/headline.js index 61e4b3fb9..bbe9be19a 100644 --- a/src/core/render/compiler/headline.js +++ b/src/core/render/compiler/headline.js @@ -4,34 +4,32 @@ import { slugify } from './slugify'; export const headingCompiler = ({ renderer, router, _self }) => (renderer.code = (text, level) => { let { str, config } = getAndRemoveConfig(text); - const nextToc = { level, title: removeAtag(str) }; + const nextToc = { level }; if (//g.test(str)) { str = str.replace('', ''); - nextToc.title = removeAtag(str); nextToc.ignoreSubHeading = true; } if (/{docsify-ignore}/g.test(str)) { str = str.replace('{docsify-ignore}', ''); - nextToc.title = removeAtag(str); nextToc.ignoreSubHeading = true; } if (//g.test(str)) { str = str.replace('', ''); - nextToc.title = removeAtag(str); nextToc.ignoreAllSubs = true; } if (/{docsify-ignore-all}/g.test(str)) { str = str.replace('{docsify-ignore-all}', ''); - nextToc.title = removeAtag(str); nextToc.ignoreAllSubs = true; } const slug = slugify(config.id || str); const url = router.toURL(router.getCurrentPath(), { id: slug }); + nextToc.title = removeAtag(str); + nextToc.text = config.sidebar || nextToc.title; nextToc.slug = url; _self.toc.push(nextToc); diff --git a/src/core/render/tpl.js b/src/core/render/tpl.js index 47ceeab74..ff5668179 100644 --- a/src/core/render/tpl.js +++ b/src/core/render/tpl.js @@ -92,7 +92,7 @@ export function tree(toc, tpl = '
') { let innerHTML = ''; toc.forEach(node => { const title = node.title.replace(/(<([^>]+)>)/g, ''); - innerHTML += `