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 22580b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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
4 changes: 3 additions & 1 deletion src/core/render/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,14 @@ export class Compiler {
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 22580b7

Please sign in to comment.