Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}>`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tried the patch, but looking at this I would think that the sidebar text would also be used in the rendered page, but I don't think this is correct. We want the sidebar text in the sidebar but not in the page.

Have you tried this? :-)

Copy link
Author

@Jacco-V Jacco-V Jun 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I have not tried the changes, because I do not have a working frontend development environment. (I'm just a backend dev giving this a try).

Copy link
Author

@Jacco-V Jacco-V Jun 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, where can I find the automated tests for this file?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

};

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