diff --git a/types/index.d.ts b/types/index.d.ts index 2db2fc9..abf8639 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,29 +1,58 @@ -import MarkdownIt = require('markdown-it'); -import Core = require('markdown-it/lib/parser_core'); -import Token = require('markdown-it/lib/token'); +import MarkdownIt from 'markdown-it'; +import Token from 'markdown-it/lib/token'; +import State from 'markdown-it/lib/rules_core/state_core'; declare namespace anchor { - interface AnchorInfo { - slug: string; - title: string; - } - - interface AnchorOptions { - level?: number; - slugify?(str: string): string; - uniqueSlugStartIndex?: number; - permalink?: boolean; - renderPermalink?(slug: string, opts: AnchorOptions, state: Core, idx: number): void; - permalinkClass?: string; - permalinkSpace?: boolean; - permalinkSymbol?: string; - permalinkBefore?: boolean; - permalinkHref?(slug: string, state: Core): string; - permalinkAttrs?(slug: string, state: Core): Record; - callback?(token: Token, anchor_info: AnchorInfo): void; - } + export type RenderHref = (slug: string, state: State) => string; + export type RenderAttrs = (slug: string, state: State) => Record; + + export interface PermalinkOptions { + class?: string, + symbol?: string, + renderHref?: RenderHref, + renderAttrs?: RenderAttrs + } + + export interface LinkAfterHeaderPermalinkOptions extends PermalinkOptions { + style?: 'visually-hidden' | 'aria-label' | 'aria-describedby' | 'aria-labelledby', + assistiveText?: (title: string) => string, + visuallyHiddenClass?: string, + space?: boolean, + placement?: 'before' | 'after' + } + + export interface AriaHiddenPermalinkOptions extends PermalinkOptions { + space?: boolean, + placement?: 'before' | 'after' + } + + export type PermalinkGenerator = (slug: string, opts: PermalinkOptions, state: State, index: number) => string; + + export interface AnchorInfo { + slug: string; + title: string; + } + + export interface AnchorOptions { + level?: number; + + slugify?(str: string): string; + + uniqueSlugStartIndex?: number; + permalink?: PermalinkGenerator; + + callback?(token: Token, anchor_info: AnchorInfo): void; + + tabIndex?: number; + } + + export const permalink: { + headerLink: () => PermalinkGenerator + linkAfterHeader: (opts: LinkAfterHeaderPermalinkOptions) => PermalinkGenerator + ariaHidden: (opts: AriaHiddenPermalinkOptions) => PermalinkGenerator + }; } declare function anchor(md: MarkdownIt, opts?: anchor.AnchorOptions): void; -export = anchor; +export = anchor; \ No newline at end of file