Skip to content

Commit 718e56c

Browse files
committed
Add typescript definitions
1 parent cbaef49 commit 718e56c

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "3.1.0",
44
"description": "Markdown renderer for react-native, with CommonMark spec support + adds syntax extensions & sugar (URL autolinking, typographer).",
55
"main": "src/index.js",
6+
"typesc": "src/index.d.ts",
67
"scripts": {},
78
"repository": {
89
"type": "git",
@@ -23,6 +24,8 @@
2324
},
2425
"homepage": "https://github.com/mientjan/react-native-markdown-renderer#readme",
2526
"dependencies": {
27+
"@types/markdown-it": "^0.0.4",
28+
"@types/react-native": ">=0.50.0",
2629
"markdown-it": "^8.4.0",
2730
"prop-types": "^15.5.10",
2831
"react-native-fit-image": "^1.5.2"

src/index.d.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// tslint:disable:max-classes-per-file
2+
import { MarkdownIt, Token } from 'markdown-it';
3+
import { Component } from 'react';
4+
import { StyleSheet, View } from 'react-native';
5+
6+
export interface MarkdownProps {
7+
rules?: RenderRules;
8+
style?: StyleSheet.NamedStyles<any>;
9+
renderer?: AstRenderer;
10+
markdownit?: MarkdownIt;
11+
plugins?: Array<PluginContainer<any>>;
12+
}
13+
14+
class Markdown extends Component<MarkdownProps, {}>{}
15+
16+
export function getUniqueID(): string;
17+
export function openUrl(url: string): void;
18+
19+
export function hasParents(parents: any[], type: string): boolean;
20+
21+
export type RenderFunction = (
22+
node: any,
23+
children: Component[],
24+
parent: Component,
25+
styles: any,
26+
) => Component;
27+
28+
export interface RenderRules {
29+
[name: string]: RenderFunction;
30+
}
31+
32+
export const renderRules: RenderRules;
33+
34+
export interface MarkdownParser {
35+
parse: (value: string, options: any) => Token[];
36+
}
37+
38+
export interface ASTNode {
39+
type: string;
40+
sourceType: string; // original source token name
41+
key: string;
42+
content: string;
43+
tokenIndex: number;
44+
index: number;
45+
attributes: Record<string, any>;
46+
children: ASTNode[];
47+
}
48+
49+
export class AstRenderer {
50+
constructor(renderRules: RenderRules, style?: any);
51+
getRenderFunction(type: string): RenderFunction;
52+
renderNode(node: any, parentNodes: ReadonlyArray<any>): Component;
53+
render(nodes: ReadonlyArray<any>): View;
54+
}
55+
56+
export function parser(
57+
source: string,
58+
renderer: (node: ASTNode) => View,
59+
parser: MarkdownParser,
60+
): any;
61+
62+
export function stringToTokens(
63+
source: string,
64+
markdownIt: MarkdownParser,
65+
): Token[];
66+
67+
export function tokensToAST(tokens: ReadonlyArray<Token>): ASTNode[];
68+
69+
interface PluginContainerResult<A> {
70+
[index: number]: any;
71+
0: A;
72+
}
73+
74+
export class PluginContainer<A> {
75+
constructor(plugin: A, ...options: any[]);
76+
toArray(): [A, any];
77+
}
78+
79+
export function blockPlugin(md: any, name: string, options: object): any;
80+
81+
export const styles: any;
82+
83+
export default Markdown;

0 commit comments

Comments
 (0)