Skip to content

Commit 22580b7

Browse files
author
Jacco-V
committed
Implement support for setting a customized sidebar item name from the markdown content
1 parent 1e46f2b commit 22580b7

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

docs/helpers.md

+6
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ Only when you set both the `routerMode: 'history'` and `externalLinkTarget: '_se
127127
### Hello, world! :id=hello-world
128128
```
129129

130+
## Customise item name for sidebar
131+
132+
```md
133+
### How would I write a "hello, world" example? :sidebar="Hello, world?"
134+
```
135+
130136
## Markdown in html tag
131137

132138
You need to insert a space between the html and markdown content.

src/core/render/compiler.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,14 @@ export class Compiler {
233233
nextToc.ignoreAllSubs = true;
234234
}
235235

236+
const title = config.sidebar || str;
236237
const slug = slugify(config.id || str);
237238
const url = router.toURL(router.getCurrentPath(), { id: slug });
239+
nextToc.title = removeAtag(title);
238240
nextToc.slug = url;
239241
_self.toc.push(nextToc);
240242

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

244246
origin.code = highlightCodeCompiler({ renderer });

0 commit comments

Comments
 (0)