From 6ccdd629a9f98827215cbf3a8af3c822ee2ceaf1 Mon Sep 17 00:00:00 2001 From: Tilman Vatteroth Date: Thu, 26 Aug 2021 20:47:31 +0200 Subject: [PATCH] Add option "allowedTokenTypes" --- index.js | 5 +++-- types/index.d.ts | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index e1e3cc0..dec343d 100644 --- a/index.js +++ b/index.js @@ -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 @@ -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.includes(token.type) }) .reduce(function (s, t) { return s + t.content }, '') ) diff --git a/types/index.d.ts b/types/index.d.ts index 449bbdd..163b7bf 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -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 {