forked from Benjamin-Dobell/react-native-markdown-view
-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.js
90 lines (69 loc) · 1.7 KB
/
types.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* @flow */
// AST Nodes
export type CodeBlockNode = {
lang: ?string,
content: string,
}
export type EmptyNode = {
}
export type HeadingNode = {
level: number,
content: InlineNode,
}
export type ImageNode = {
alt: string,
target: string,
title: string,
width?: number,
height?: number,
}
export type InlineContentNode = {
content: InlineNode,
}
export type LinkNode = {
content: Node,
target: string,
title?: ?string,
}
export type ListNode = {
ordered: boolean,
start: number,
items: InlineNode[],
}
export type TableAlign = 'right' | 'center' | 'left' | null
export type TableNode = {
header: InlineNode[],
align: TableAlign,
cells: InlineNode[][],
}
export type TextNode = {
content: string,
}
export type InlineNode = EmptyNode |
ImageNode |
InlineContentNode |
LinkNode |
TextNode
export type Node = InlineNode |
CodeBlockNode |
HeadingNode |
ListNode |
TableNode
// Rules
export type RegexComponents = string[]
export type NestedParseFunction = (string, any) => ?Object
export type ParseState = Object
export type ParseFunction = (RegexComponents, NestedParseFunction, ParseState) => any
export type NodeKey = string
export type OutputFunction = (Node, Object) => ?any
export type RenderState = {
key: string,
onLinkPress: ?(string) => void
}
export type RenderStyle = Object
export type RenderStyles = {[key: NodeKey]: RenderStyle}
export type RenderFunction = (Node, OutputFunction, RenderState, RenderStyle) => ?any
export type Rule = {order?: number, match?: (string, RenderState, string[]) => ?RegExp, parse?: ParseFunction, render?: RenderFunction}
export type Rules = {[key: NodeKey]: Rule}
// Styles
export type Styles = {[key: NodeKey]: ?Object}