Skip to content

Commit a3fad22

Browse files
authored
Merge pull request #68 from lukeramsden/patch-1
Fixed TypeScript type definitions
2 parents 626c928 + 1162b1b commit a3fad22

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

src/index.d.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// tslint:disable:max-classes-per-file
2-
import {MarkdownIt, Token} from 'markdown-it';
2+
import MarkdownIt from 'markdown-it';
3+
import Token from 'markdown-it/lib/token';
34
import {ComponentType, ReactNode} from 'react';
45
import {StyleSheet, View} from 'react-native';
56

@@ -9,14 +10,37 @@ export function openUrl(url: string): void;
910
export function hasParents(parents: any[], type: string): boolean;
1011

1112
export type RenderFunction = (
12-
node: any,
13+
node: ASTNode,
1314
children: ReactNode[],
14-
parent: ReactNode,
15+
parentNodes: ASTNode[],
1516
styles: any,
17+
styleObj?: any,
18+
// must have this so that we can have fixed overrides with more arguments
19+
...args: any,
20+
) => ReactNode;
21+
22+
export type RenderLinkFunction = (
23+
node: ASTNode,
24+
children: ReactNode[],
25+
parentNodes: ASTNode[],
26+
styles: any,
27+
onLinkPress: (url: string) => boolean,
28+
) => ReactNode;
29+
30+
export type RenderImageFunction = (
31+
node: ASTNode,
32+
children: ReactNode[],
33+
parentNodes: ASTNode[],
34+
styles: any,
35+
allowedImageHandlers: string[],
36+
defaultImageHandler: string,
1637
) => ReactNode;
1738

1839
export interface RenderRules {
19-
[name: string]: RenderFunction;
40+
[name: string]: RenderFunction | undefined;
41+
link?: RenderLinkFunction;
42+
blocklink?: RenderLinkFunction;
43+
image?: RenderImageFunction;
2044
}
2145

2246
export const renderRules: RenderRules;
@@ -30,6 +54,7 @@ export interface ASTNode {
3054
sourceType: string; // original source token name
3155
key: string;
3256
content: string;
57+
markup: string;
3358
tokenIndex: number;
3459
index: number;
3560
attributes: Record<string, any>;
@@ -56,30 +81,19 @@ export function stringToTokens(
5681

5782
export function tokensToAST(tokens: ReadonlyArray<Token>): ASTNode[];
5883

59-
interface PluginContainerResult<A> extends Array<any> {
60-
0: A;
61-
}
62-
63-
export class PluginContainer<A> {
64-
constructor(plugin: A, ...options: any[]);
65-
toArray(): PluginContainerResult<A>;
66-
}
67-
68-
export function blockPlugin(md: any, name: string, options: object): any;
69-
7084
export const styles: any;
7185

7286
export interface MarkdownProps {
7387
rules?: RenderRules;
7488
style?: StyleSheet.NamedStyles<any>;
7589
renderer?: AstRenderer;
7690
markdownit?: MarkdownIt;
77-
plugins?: Array<PluginContainer<any>>;
7891
mergeStyle?: boolean;
92+
debugPrintTree?: boolean;
7993
}
8094

8195
type MarkdownStatic = React.ComponentType<MarkdownProps>;
8296
export const Markdown: MarkdownStatic;
8397
export type Markdown = MarkdownStatic;
84-
98+
export {MarkdownIt};
8599
export default Markdown;

0 commit comments

Comments
 (0)