Skip to content

Commit b7ca131

Browse files
authored
Merge pull request mientjan#35 from doomsower/ts
Add typescript definitions
2 parents 608684e + cdffd7f commit b7ca131

File tree

2 files changed

+87
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)