Skip to content

Commit

Permalink
Add option "allowedTokenTypes"
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdrogdrog committed Aug 26, 2021
1 parent 0a9fe6d commit d74b36f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ function tocPlugin (md, options) {
level: 1,
listType: 'ol',
format: undefined,
callback: undefined/* function(html, ast) {} */
callback: undefined/* function(html, ast) {} */,
allowedTokenTypes: ["text", "code_inline"]
}, options)

let ast
Expand Down Expand Up @@ -156,7 +157,7 @@ function tocPlugin (md, options) {
const key = (
tokens[i + 1]
.children
.filter(function (token) { return token.type === 'text' || token.type === 'code_inline' })
.filter(function (token) { return options.allowedTokenTypes.indexOf(token.type) !== -1 })
.reduce(function (s, t) { return s + t.content }, '')
)

Expand Down
3 changes: 2 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ declare module 'markdown-it-toc-done-right' {
level: number | number[]
listType: 'ol' | 'ul'
format: (s: string) => string
callback: (tocCode: string, ast: TocAst) => void
callback: (tocCode: string, ast: TocAst) => void,
allowedTokenTypes: string[]
}

export interface TocAst {
Expand Down

0 comments on commit d74b36f

Please sign in to comment.