Skip to content

Commit d74b36f

Browse files
committed
Add option "allowedTokenTypes"
1 parent 0a9fe6d commit d74b36f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ function tocPlugin (md, options) {
3535
level: 1,
3636
listType: 'ol',
3737
format: undefined,
38-
callback: undefined/* function(html, ast) {} */
38+
callback: undefined/* function(html, ast) {} */,
39+
allowedTokenTypes: ["text", "code_inline"]
3940
}, options)
4041

4142
let ast
@@ -156,7 +157,7 @@ function tocPlugin (md, options) {
156157
const key = (
157158
tokens[i + 1]
158159
.children
159-
.filter(function (token) { return token.type === 'text' || token.type === 'code_inline' })
160+
.filter(function (token) { return options.allowedTokenTypes.indexOf(token.type) !== -1 })
160161
.reduce(function (s, t) { return s + t.content }, '')
161162
)
162163

types/index.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ declare module 'markdown-it-toc-done-right' {
1313
level: number | number[]
1414
listType: 'ol' | 'ul'
1515
format: (s: string) => string
16-
callback: (tocCode: string, ast: TocAst) => void
16+
callback: (tocCode: string, ast: TocAst) => void,
17+
allowedTokenTypes: string[]
1718
}
1819

1920
export interface TocAst {

0 commit comments

Comments
 (0)