Skip to content

Commit

Permalink
Merge pull request #95 from mrdrogdrog/master
Browse files Browse the repository at this point in the history
Add types that match release 8.0.0
  • Loading branch information
valeriangalliat committed Jun 20, 2021
2 parents df3bbd9 + cc6fbcb commit 1931e42
Showing 1 changed file with 52 additions and 23 deletions.
75 changes: 52 additions & 23 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -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<string, string>;
callback?(token: Token, anchor_info: AnchorInfo): void;
}
export type RenderHref = (slug: string, state: State) => string;
export type RenderAttrs = (slug: string, state: State) => Record<string, string | number>;

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;

0 comments on commit 1931e42

Please sign in to comment.