Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit eb5f939

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

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

‎docs/helpers.md‎

Lines changed: 6 additions & 0 deletions
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‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,38 +207,36 @@ export class Compiler {
207207
*/
208208
origin.heading = renderer.heading = function (text, level) {
209209
let { str, config } = getAndRemoveConfig(text);
210-
const nextToc = { level,title: removeAtag(str) };
210+
const nextToc = { level };
211211

212212
if (/<!--{docsify-ignore}-->/g.test(str)) {
213213
str = str.replace('<!-- {docsify-ignore} -->', '');
214-
nextToc.title = removeAtag(str);
215214
nextToc.ignoreSubHeading = true;
216215
}
217216

218217
if (/{docsify-ignore}/g.test(str)) {
219218
str = str.replace('{docsify-ignore}', '');
220-
nextToc.title = removeAtag(str);
221219
nextToc.ignoreSubHeading = true;
222220
}
223221

224222
if (/<!--{docsify-ignore-all}-->/g.test(str)) {
225223
str = str.replace('<!-- {docsify-ignore-all} -->', '');
226-
nextToc.title = removeAtag(str);
227224
nextToc.ignoreAllSubs = true;
228225
}
229226

230227
if (/{docsify-ignore-all}/g.test(str)) {
231228
str = str.replace('{docsify-ignore-all}', '');
232-
nextToc.title = removeAtag(str);
233229
nextToc.ignoreAllSubs = true;
234230
}
235231

232+
const title = config.sidebar || str;
236233
const slug = slugify(config.id || str);
237234
const url = router.toURL(router.getCurrentPath(), { id: slug });
235+
nextToc.title = removeAtag(title);
238236
nextToc.slug = url;
239237
_self.toc.push(nextToc);
240238

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

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /