From 4e6b760cf09c93667e34a39e7326cfafea04cdda Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 4 Sep 2024 23:20:59 +0000 Subject: [PATCH 1/2] Export Token and State types from index.d.ts This makes it possible to accurately declare callback functions that take these types. --- types/index.d.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index bb6d58a..24ba3e2 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,8 +1,10 @@ import MarkdownIt from 'markdown-it'; -import Token from 'markdown-it/lib/token.mjs'; -import State from 'markdown-it/lib/rules_core/state_core.mjs'; +import Token as JSToken from 'markdown-it/lib/token.mjs'; +import State as JSState from 'markdown-it/lib/rules_core/state_core.mjs'; declare namespace anchor { + export type Token = JSToken; + export type State = JSState; export type RenderHref = (slug: string, state: State) => string; export type RenderAttrs = (slug: string, state: State) => Record; From 1628108693ac2182d69a84fb69bc9ff5586b6e18 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 4 Sep 2024 18:16:34 -0700 Subject: [PATCH 2/2] Use types from @types/markdown-it --- types/index.d.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 24ba3e2..7658832 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,12 +1,8 @@ -import MarkdownIt from 'markdown-it'; -import Token as JSToken from 'markdown-it/lib/token.mjs'; -import State as JSState from 'markdown-it/lib/rules_core/state_core.mjs'; +import MarkdownIt, {StateCore, Token} from 'markdown-it'; declare namespace anchor { - export type Token = JSToken; - export type State = JSState; - export type RenderHref = (slug: string, state: State) => string; - export type RenderAttrs = (slug: string, state: State) => Record; + export type RenderHref = (slug: string, state: StateCore) => string; + export type RenderAttrs = (slug: string, state: StateCore) => Record; export interface PermalinkOptions { class?: string, @@ -39,7 +35,7 @@ declare namespace anchor { placement?: 'before' | 'after' } - export type PermalinkGenerator = (slug: string, opts: PermalinkOptions, state: State, index: number) => void; + export type PermalinkGenerator = (slug: string, opts: PermalinkOptions, state: StateCore, index: number) => void; export interface AnchorInfo { slug: string; @@ -50,7 +46,7 @@ declare namespace anchor { level?: number | number[]; slugify?(str: string): string; - slugifyWithState?(str: string, state: State): string; + slugifyWithStateCore?(str: string, state: StateCore): string; getTokensText?(tokens: Token[]): string; uniqueSlugStartIndex?: number;