Skip to content

Commit

Permalink
Implement support for setting a customized sidebar item name from the…
Browse files Browse the repository at this point in the history
… markdown content
  • Loading branch information
Jacco-V committed Jun 22, 2022
1 parent 1e46f2b commit eb5f939
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 6 additions & 0 deletions docs/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ Only when you set both the `routerMode: 'history'` and `externalLinkTarget: '_se
### Hello, world! :id=hello-world
```

## Customise item name 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.
Expand Down
10 changes: 4 additions & 6 deletions src/core/render/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,38 +207,36 @@ 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 (/<!-- {docsify-ignore} -->/g.test(str)) {
str = str.replace('<!-- {docsify-ignore} -->', '');
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 (/<!-- {docsify-ignore-all} -->/g.test(str)) {
str = str.replace('<!-- {docsify-ignore-all} -->', '');
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 title = config.sidebar || str;
const slug = slugify(config.id || str);
const url = router.toURL(router.getCurrentPath(), { id: slug });
nextToc.title = removeAtag(title);
nextToc.slug = url;
_self.toc.push(nextToc);

return `<h${level} id="${slug}"><a href="${url}" data-id="${slug}" class="anchor"><span>${str}</span></a></h${level}>`;
return `<h${level} id="${slug}"><a href="${url}" data-id="${slug}" class="anchor"><span>${title}</span></a></h${level}>`;
};

origin.code = highlightCodeCompiler({ renderer });
Expand Down

0 comments on commit eb5f939

Please sign in to comment.