diff --git a/docs/helpers.md b/docs/helpers.md
index 801683126..450ddb29d 100644
--- a/docs/helpers.md
+++ b/docs/helpers.md
@@ -94,3 +94,9 @@ You will get `link`html. Do not worry, you can still set ti



+
+## Customise ID for headings
+
+```md
+### 你好,世界! :id=hello-world
+```
\ No newline at end of file
diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js
index 3509cf227..397597b79 100644
--- a/src/core/render/compiler.js
+++ b/src/core/render/compiler.js
@@ -190,26 +190,27 @@ export class Compiler {
* @link https://github.com/markedjs/marked#overriding-renderer-methods
*/
origin.heading = renderer.heading = function (text, level) {
- const nextToc = {level, title: text}
+ let {str, config} = getAndRemoveConfig(text)
+ const nextToc = {level, title: str}
- if (/{docsify-ignore}/g.test(text)) {
- text = text.replace('{docsify-ignore}', '')
- nextToc.title = text
+ if (/{docsify-ignore}/g.test(str)) {
+ str = str.replace('{docsify-ignore}', '')
+ nextToc.title = str
nextToc.ignoreSubHeading = true
}
- if (/{docsify-ignore-all}/g.test(text)) {
- text = text.replace('{docsify-ignore-all}', '')
- nextToc.title = text
+ if (/{docsify-ignore-all}/g.test(str)) {
+ str = str.replace('{docsify-ignore-all}', '')
+ nextToc.title = str
nextToc.ignoreAllSubs = true
}
- const slug = slugify(text)
+ const slug = slugify(config.id || str)
const url = router.toURL(router.getCurrentPath(), {id: slug})
nextToc.slug = url
_self.toc.push(nextToc)
- return `${text}`
+ return `${str}`
}
// Highlight code
origin.code = renderer.code = function (code, lang = '') {