react-native-marked 8.1.1 → 8.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -20
- package/README.md +354 -354
- package/dist/commonjs/components/MDImage.js +3 -3
- package/dist/commonjs/components/MDImage.js.map +1 -1
- package/dist/commonjs/components/MDList.js.map +1 -1
- package/dist/commonjs/components/MDSvg.js.map +1 -1
- package/dist/commonjs/components/MDTable.js.map +1 -1
- package/dist/commonjs/hooks/useMarkdown.js.map +1 -1
- package/dist/commonjs/hooks/useMarkdownWithComponents.js.map +1 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/lib/Markdown.js.map +1 -1
- package/dist/commonjs/lib/Parser.js +4 -4
- package/dist/commonjs/lib/Parser.js.map +1 -1
- package/dist/commonjs/lib/ReactComponentRegistry.js.map +1 -1
- package/dist/commonjs/lib/ReactComponentTokenizer.js.map +1 -1
- package/dist/commonjs/lib/Renderer.js.map +1 -1
- package/dist/commonjs/lib/types.js.map +1 -1
- package/dist/commonjs/theme/colors.js.map +1 -1
- package/dist/commonjs/theme/spacing.js.map +1 -1
- package/dist/commonjs/theme/styles.js.map +1 -1
- package/dist/commonjs/theme/types.js.map +1 -1
- package/dist/commonjs/utils/handlers.js.map +1 -1
- package/dist/commonjs/utils/svg.js.map +1 -1
- package/dist/commonjs/utils/table.js.map +1 -1
- package/dist/commonjs/utils/url.js.map +1 -1
- package/dist/module/components/MDImage.js +3 -3
- package/dist/module/components/MDImage.js.map +1 -1
- package/dist/module/components/MDList.js.map +1 -1
- package/dist/module/components/MDSvg.js.map +1 -1
- package/dist/module/components/MDTable.js.map +1 -1
- package/dist/module/hooks/useMarkdown.js.map +1 -1
- package/dist/module/hooks/useMarkdownWithComponents.js.map +1 -1
- package/dist/module/index.js.map +1 -1
- package/dist/module/lib/Markdown.js.map +1 -1
- package/dist/module/lib/Parser.js +4 -4
- package/dist/module/lib/Parser.js.map +1 -1
- package/dist/module/lib/ReactComponentRegistry.js.map +1 -1
- package/dist/module/lib/ReactComponentTokenizer.js.map +1 -1
- package/dist/module/lib/Renderer.js.map +1 -1
- package/dist/module/lib/types.js.map +1 -1
- package/dist/module/theme/colors.js.map +1 -1
- package/dist/module/theme/spacing.js.map +1 -1
- package/dist/module/theme/styles.js.map +1 -1
- package/dist/module/theme/types.js.map +1 -1
- package/dist/module/utils/handlers.js.map +1 -1
- package/dist/module/utils/svg.js.map +1 -1
- package/dist/module/utils/table.js.map +1 -1
- package/dist/module/utils/url.js.map +1 -1
- package/package.json +175 -175
- package/src/components/MDImage.tsx +90 -90
- package/src/components/MDList.tsx +46 -46
- package/src/components/MDSvg.tsx +108 -108
- package/src/components/MDTable.tsx +60 -60
- package/src/hooks/useMarkdown.ts +51 -51
- package/src/hooks/useMarkdownWithComponents.tsx +89 -89
- package/src/index.ts +43 -43
- package/src/lib/Markdown.tsx +53 -53
- package/src/lib/Parser.tsx +316 -316
- package/src/lib/ReactComponentRegistry.tsx +52 -52
- package/src/lib/ReactComponentTokenizer.ts +149 -149
- package/src/lib/Renderer.tsx +238 -238
- package/src/lib/types.ts +87 -87
- package/src/theme/colors.ts +31 -31
- package/src/theme/spacing.ts +10 -10
- package/src/theme/styles.ts +198 -198
- package/src/theme/types.ts +33 -33
- package/src/utils/handlers.ts +9 -9
- package/src/utils/svg.ts +14 -14
- package/src/utils/table.ts +29 -29
- package/src/utils/url.ts +22 -22
package/src/lib/Renderer.tsx
CHANGED
|
@@ -1,238 +1,238 @@
|
|
|
1
|
-
import Slugger from "github-slugger";
|
|
2
|
-
import React, { type ReactNode } from "react";
|
|
3
|
-
import {
|
|
4
|
-
Dimensions,
|
|
5
|
-
type ImageStyle,
|
|
6
|
-
ScrollView,
|
|
7
|
-
Text,
|
|
8
|
-
type TextStyle,
|
|
9
|
-
TouchableHighlight,
|
|
10
|
-
View,
|
|
11
|
-
type ViewStyle,
|
|
12
|
-
} from "react-native";
|
|
13
|
-
import MDImage from "./../components/MDImage";
|
|
14
|
-
import MDList from "./../components/MDList";
|
|
15
|
-
import MDSvg from "./../components/MDSvg";
|
|
16
|
-
import MDTable from "./../components/MDTable";
|
|
17
|
-
import { onLinkPress } from "../utils/handlers";
|
|
18
|
-
import { getTableWidthArr } from "../utils/table";
|
|
19
|
-
import type { RendererInterface } from "./types";
|
|
20
|
-
|
|
21
|
-
class Renderer implements RendererInterface {
|
|
22
|
-
private slugPrefix = "react-native-marked-ele";
|
|
23
|
-
private slugger: Slugger;
|
|
24
|
-
private windowWidth: number;
|
|
25
|
-
constructor() {
|
|
26
|
-
this.slugger = new Slugger();
|
|
27
|
-
const { width } = Dimensions.get("window");
|
|
28
|
-
this.windowWidth = width;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
paragraph(children: ReactNode[], styles?: ViewStyle): ReactNode {
|
|
32
|
-
return this.getViewNode(children, styles);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
blockquote(children: ReactNode[], styles?: ViewStyle): ReactNode {
|
|
36
|
-
return this.getBlockquoteNode(children, styles);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
heading(text: string | ReactNode[], styles?: TextStyle): ReactNode {
|
|
40
|
-
return this.getTextNode(text, styles);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
code(
|
|
44
|
-
text: string,
|
|
45
|
-
_language?: string,
|
|
46
|
-
containerStyle?: ViewStyle,
|
|
47
|
-
textStyle?: TextStyle,
|
|
48
|
-
): ReactNode {
|
|
49
|
-
return (
|
|
50
|
-
<ScrollView
|
|
51
|
-
horizontal
|
|
52
|
-
key={this.getKey()}
|
|
53
|
-
contentContainerStyle={containerStyle}
|
|
54
|
-
>
|
|
55
|
-
{/*
|
|
56
|
-
Wrapped in View node to avoid the following error
|
|
57
|
-
Error: Cannot add a child that doesn't have a YogaNode to a parent without a measure function!
|
|
58
|
-
ref: https://github.com/facebook/react-native/issues/18773
|
|
59
|
-
*/}
|
|
60
|
-
<View>{this.getTextNode(text, textStyle)}</View>
|
|
61
|
-
</ScrollView>
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
hr(styles?: ViewStyle): ReactNode {
|
|
66
|
-
return this.getViewNode(null, styles);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
listItem(children: ReactNode[], styles?: ViewStyle): ReactNode {
|
|
70
|
-
return this.getViewNode(children, styles);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
list(
|
|
74
|
-
ordered: boolean,
|
|
75
|
-
li: ReactNode[],
|
|
76
|
-
listStyle?: ViewStyle,
|
|
77
|
-
textStyle?: TextStyle,
|
|
78
|
-
startIndex?: number,
|
|
79
|
-
): ReactNode {
|
|
80
|
-
return (
|
|
81
|
-
<MDList
|
|
82
|
-
key={this.getKey()}
|
|
83
|
-
ordered={ordered}
|
|
84
|
-
li={li}
|
|
85
|
-
listStyle={listStyle}
|
|
86
|
-
textStyle={textStyle}
|
|
87
|
-
startIndex={startIndex}
|
|
88
|
-
/>
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
escape(text: string, styles?: TextStyle): ReactNode {
|
|
93
|
-
return this.getTextNode(text, styles);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
link(
|
|
97
|
-
children: string | ReactNode[],
|
|
98
|
-
href: string,
|
|
99
|
-
styles?: TextStyle,
|
|
100
|
-
title?: string,
|
|
101
|
-
): ReactNode {
|
|
102
|
-
return (
|
|
103
|
-
<Text
|
|
104
|
-
selectable
|
|
105
|
-
accessibilityRole="link"
|
|
106
|
-
accessibilityHint="Opens in a new window"
|
|
107
|
-
accessibilityLabel={title || "Link"}
|
|
108
|
-
key={this.getKey()}
|
|
109
|
-
onPress={onLinkPress(href)}
|
|
110
|
-
style={styles}
|
|
111
|
-
>
|
|
112
|
-
{children}
|
|
113
|
-
</Text>
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
image(
|
|
118
|
-
uri: string,
|
|
119
|
-
alt?: string,
|
|
120
|
-
style?: ImageStyle,
|
|
121
|
-
title?: string,
|
|
122
|
-
): ReactNode {
|
|
123
|
-
const key = this.getKey();
|
|
124
|
-
if (uri.endsWith(".svg")) {
|
|
125
|
-
return <MDSvg uri={uri} key={key} />;
|
|
126
|
-
}
|
|
127
|
-
return <MDImage key={key} uri={uri} alt={alt || title} style={style} />;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
strong(children: string | ReactNode[], styles?: TextStyle): ReactNode {
|
|
131
|
-
return this.getTextNode(children, styles);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
em(children: string | ReactNode[], styles?: TextStyle): ReactNode {
|
|
135
|
-
return this.getTextNode(children, styles);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
codespan(text: string, styles?: TextStyle): ReactNode {
|
|
139
|
-
return this.getTextNode(text, styles);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
br(): ReactNode {
|
|
143
|
-
return this.getTextNode("\n", {});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
del(children: string | ReactNode[], styles?: TextStyle): ReactNode {
|
|
147
|
-
return this.getTextNode(children, styles);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
text(text: string | ReactNode[], styles?: TextStyle): ReactNode {
|
|
151
|
-
return this.getTextNode(text, styles);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
html(text: string | ReactNode[], styles?: TextStyle): ReactNode {
|
|
155
|
-
return this.getTextNode(text, styles);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
linkImage(
|
|
159
|
-
href: string,
|
|
160
|
-
imageUrl: string,
|
|
161
|
-
alt?: string,
|
|
162
|
-
style?: ImageStyle,
|
|
163
|
-
title?: string,
|
|
164
|
-
): ReactNode {
|
|
165
|
-
const imageNode = this.image(imageUrl, alt, style, title);
|
|
166
|
-
return (
|
|
167
|
-
<TouchableHighlight
|
|
168
|
-
accessibilityRole="link"
|
|
169
|
-
accessibilityHint="Opens in a new window"
|
|
170
|
-
onPress={onLinkPress(href)}
|
|
171
|
-
key={this.getKey()}
|
|
172
|
-
>
|
|
173
|
-
{imageNode}
|
|
174
|
-
</TouchableHighlight>
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
table(
|
|
179
|
-
header: ReactNode[][],
|
|
180
|
-
rows: ReactNode[][][],
|
|
181
|
-
tableStyle?: ViewStyle,
|
|
182
|
-
rowStyle?: ViewStyle,
|
|
183
|
-
cellStyle?: ViewStyle,
|
|
184
|
-
): React.ReactNode {
|
|
185
|
-
const widthArr = getTableWidthArr(header.length, this.windowWidth);
|
|
186
|
-
const { borderWidth, borderColor } = tableStyle || {};
|
|
187
|
-
return (
|
|
188
|
-
<MDTable
|
|
189
|
-
header={header}
|
|
190
|
-
rows={rows}
|
|
191
|
-
widthArr={widthArr}
|
|
192
|
-
rowStyle={rowStyle}
|
|
193
|
-
cellStyle={cellStyle}
|
|
194
|
-
borderColor={borderColor as string}
|
|
195
|
-
borderWidth={borderWidth}
|
|
196
|
-
/>
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
getKey(): string {
|
|
201
|
-
return this.slugger.slug(this.slugPrefix);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
private getTextNode(
|
|
205
|
-
children: string | ReactNode[],
|
|
206
|
-
styles?: TextStyle,
|
|
207
|
-
): ReactNode {
|
|
208
|
-
return (
|
|
209
|
-
<Text selectable key={this.getKey()} style={styles}>
|
|
210
|
-
{children}
|
|
211
|
-
</Text>
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
private getViewNode(
|
|
216
|
-
children: ReactNode[] | null,
|
|
217
|
-
styles?: ViewStyle,
|
|
218
|
-
): ReactNode {
|
|
219
|
-
return (
|
|
220
|
-
<View key={this.getKey()} style={styles}>
|
|
221
|
-
{children}
|
|
222
|
-
</View>
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
private getBlockquoteNode(
|
|
227
|
-
children: ReactNode[],
|
|
228
|
-
styles?: ViewStyle,
|
|
229
|
-
): ReactNode {
|
|
230
|
-
return (
|
|
231
|
-
<View key={this.getKey()} style={styles}>
|
|
232
|
-
{children}
|
|
233
|
-
</View>
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
export default Renderer;
|
|
1
|
+
import Slugger from "github-slugger";
|
|
2
|
+
import React, { type ReactNode } from "react";
|
|
3
|
+
import {
|
|
4
|
+
Dimensions,
|
|
5
|
+
type ImageStyle,
|
|
6
|
+
ScrollView,
|
|
7
|
+
Text,
|
|
8
|
+
type TextStyle,
|
|
9
|
+
TouchableHighlight,
|
|
10
|
+
View,
|
|
11
|
+
type ViewStyle,
|
|
12
|
+
} from "react-native";
|
|
13
|
+
import MDImage from "./../components/MDImage";
|
|
14
|
+
import MDList from "./../components/MDList";
|
|
15
|
+
import MDSvg from "./../components/MDSvg";
|
|
16
|
+
import MDTable from "./../components/MDTable";
|
|
17
|
+
import { onLinkPress } from "../utils/handlers";
|
|
18
|
+
import { getTableWidthArr } from "../utils/table";
|
|
19
|
+
import type { RendererInterface } from "./types";
|
|
20
|
+
|
|
21
|
+
class Renderer implements RendererInterface {
|
|
22
|
+
private slugPrefix = "react-native-marked-ele";
|
|
23
|
+
private slugger: Slugger;
|
|
24
|
+
private windowWidth: number;
|
|
25
|
+
constructor() {
|
|
26
|
+
this.slugger = new Slugger();
|
|
27
|
+
const { width } = Dimensions.get("window");
|
|
28
|
+
this.windowWidth = width;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
paragraph(children: ReactNode[], styles?: ViewStyle): ReactNode {
|
|
32
|
+
return this.getViewNode(children, styles);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
blockquote(children: ReactNode[], styles?: ViewStyle): ReactNode {
|
|
36
|
+
return this.getBlockquoteNode(children, styles);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
heading(text: string | ReactNode[], styles?: TextStyle): ReactNode {
|
|
40
|
+
return this.getTextNode(text, styles);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
code(
|
|
44
|
+
text: string,
|
|
45
|
+
_language?: string,
|
|
46
|
+
containerStyle?: ViewStyle,
|
|
47
|
+
textStyle?: TextStyle,
|
|
48
|
+
): ReactNode {
|
|
49
|
+
return (
|
|
50
|
+
<ScrollView
|
|
51
|
+
horizontal
|
|
52
|
+
key={this.getKey()}
|
|
53
|
+
contentContainerStyle={containerStyle}
|
|
54
|
+
>
|
|
55
|
+
{/*
|
|
56
|
+
Wrapped in View node to avoid the following error
|
|
57
|
+
Error: Cannot add a child that doesn't have a YogaNode to a parent without a measure function!
|
|
58
|
+
ref: https://github.com/facebook/react-native/issues/18773
|
|
59
|
+
*/}
|
|
60
|
+
<View>{this.getTextNode(text, textStyle)}</View>
|
|
61
|
+
</ScrollView>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
hr(styles?: ViewStyle): ReactNode {
|
|
66
|
+
return this.getViewNode(null, styles);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
listItem(children: ReactNode[], styles?: ViewStyle): ReactNode {
|
|
70
|
+
return this.getViewNode(children, styles);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
list(
|
|
74
|
+
ordered: boolean,
|
|
75
|
+
li: ReactNode[],
|
|
76
|
+
listStyle?: ViewStyle,
|
|
77
|
+
textStyle?: TextStyle,
|
|
78
|
+
startIndex?: number,
|
|
79
|
+
): ReactNode {
|
|
80
|
+
return (
|
|
81
|
+
<MDList
|
|
82
|
+
key={this.getKey()}
|
|
83
|
+
ordered={ordered}
|
|
84
|
+
li={li}
|
|
85
|
+
listStyle={listStyle}
|
|
86
|
+
textStyle={textStyle}
|
|
87
|
+
startIndex={startIndex}
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
escape(text: string, styles?: TextStyle): ReactNode {
|
|
93
|
+
return this.getTextNode(text, styles);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
link(
|
|
97
|
+
children: string | ReactNode[],
|
|
98
|
+
href: string,
|
|
99
|
+
styles?: TextStyle,
|
|
100
|
+
title?: string,
|
|
101
|
+
): ReactNode {
|
|
102
|
+
return (
|
|
103
|
+
<Text
|
|
104
|
+
selectable
|
|
105
|
+
accessibilityRole="link"
|
|
106
|
+
accessibilityHint="Opens in a new window"
|
|
107
|
+
accessibilityLabel={title || "Link"}
|
|
108
|
+
key={this.getKey()}
|
|
109
|
+
onPress={onLinkPress(href)}
|
|
110
|
+
style={styles}
|
|
111
|
+
>
|
|
112
|
+
{children}
|
|
113
|
+
</Text>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
image(
|
|
118
|
+
uri: string,
|
|
119
|
+
alt?: string,
|
|
120
|
+
style?: ImageStyle,
|
|
121
|
+
title?: string,
|
|
122
|
+
): ReactNode {
|
|
123
|
+
const key = this.getKey();
|
|
124
|
+
if (uri.endsWith(".svg")) {
|
|
125
|
+
return <MDSvg uri={uri} key={key} />;
|
|
126
|
+
}
|
|
127
|
+
return <MDImage key={key} uri={uri} alt={alt || title} style={style} />;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
strong(children: string | ReactNode[], styles?: TextStyle): ReactNode {
|
|
131
|
+
return this.getTextNode(children, styles);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
em(children: string | ReactNode[], styles?: TextStyle): ReactNode {
|
|
135
|
+
return this.getTextNode(children, styles);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
codespan(text: string, styles?: TextStyle): ReactNode {
|
|
139
|
+
return this.getTextNode(text, styles);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
br(): ReactNode {
|
|
143
|
+
return this.getTextNode("\n", {});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
del(children: string | ReactNode[], styles?: TextStyle): ReactNode {
|
|
147
|
+
return this.getTextNode(children, styles);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
text(text: string | ReactNode[], styles?: TextStyle): ReactNode {
|
|
151
|
+
return this.getTextNode(text, styles);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
html(text: string | ReactNode[], styles?: TextStyle): ReactNode {
|
|
155
|
+
return this.getTextNode(text, styles);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
linkImage(
|
|
159
|
+
href: string,
|
|
160
|
+
imageUrl: string,
|
|
161
|
+
alt?: string,
|
|
162
|
+
style?: ImageStyle,
|
|
163
|
+
title?: string,
|
|
164
|
+
): ReactNode {
|
|
165
|
+
const imageNode = this.image(imageUrl, alt, style, title);
|
|
166
|
+
return (
|
|
167
|
+
<TouchableHighlight
|
|
168
|
+
accessibilityRole="link"
|
|
169
|
+
accessibilityHint="Opens in a new window"
|
|
170
|
+
onPress={onLinkPress(href)}
|
|
171
|
+
key={this.getKey()}
|
|
172
|
+
>
|
|
173
|
+
{imageNode}
|
|
174
|
+
</TouchableHighlight>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
table(
|
|
179
|
+
header: ReactNode[][],
|
|
180
|
+
rows: ReactNode[][][],
|
|
181
|
+
tableStyle?: ViewStyle,
|
|
182
|
+
rowStyle?: ViewStyle,
|
|
183
|
+
cellStyle?: ViewStyle,
|
|
184
|
+
): React.ReactNode {
|
|
185
|
+
const widthArr = getTableWidthArr(header.length, this.windowWidth);
|
|
186
|
+
const { borderWidth, borderColor } = tableStyle || {};
|
|
187
|
+
return (
|
|
188
|
+
<MDTable
|
|
189
|
+
header={header}
|
|
190
|
+
rows={rows}
|
|
191
|
+
widthArr={widthArr}
|
|
192
|
+
rowStyle={rowStyle}
|
|
193
|
+
cellStyle={cellStyle}
|
|
194
|
+
borderColor={borderColor as string}
|
|
195
|
+
borderWidth={borderWidth}
|
|
196
|
+
/>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
getKey(): string {
|
|
201
|
+
return this.slugger.slug(this.slugPrefix);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private getTextNode(
|
|
205
|
+
children: string | ReactNode[],
|
|
206
|
+
styles?: TextStyle,
|
|
207
|
+
): ReactNode {
|
|
208
|
+
return (
|
|
209
|
+
<Text selectable key={this.getKey()} style={styles}>
|
|
210
|
+
{children}
|
|
211
|
+
</Text>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private getViewNode(
|
|
216
|
+
children: ReactNode[] | null,
|
|
217
|
+
styles?: ViewStyle,
|
|
218
|
+
): ReactNode {
|
|
219
|
+
return (
|
|
220
|
+
<View key={this.getKey()} style={styles}>
|
|
221
|
+
{children}
|
|
222
|
+
</View>
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
private getBlockquoteNode(
|
|
227
|
+
children: ReactNode[],
|
|
228
|
+
styles?: ViewStyle,
|
|
229
|
+
): ReactNode {
|
|
230
|
+
return (
|
|
231
|
+
<View key={this.getKey()} style={styles}>
|
|
232
|
+
{children}
|
|
233
|
+
</View>
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export default Renderer;
|
package/src/lib/types.ts
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
import type { Hooks, Tokenizer } from "marked";
|
|
2
|
-
import type { ReactNode } from "react";
|
|
3
|
-
import type {
|
|
4
|
-
FlatListProps,
|
|
5
|
-
ImageStyle,
|
|
6
|
-
TextStyle,
|
|
7
|
-
ViewStyle,
|
|
8
|
-
} from "react-native";
|
|
9
|
-
import type { MarkedStyles, UserTheme } from "./../theme/types";
|
|
10
|
-
|
|
11
|
-
export interface ParserOptions {
|
|
12
|
-
styles?: MarkedStyles;
|
|
13
|
-
baseUrl?: string;
|
|
14
|
-
renderer: RendererInterface;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface MarkdownProps extends Partial<ParserOptions> {
|
|
18
|
-
value: string;
|
|
19
|
-
flatListProps?: Omit<
|
|
20
|
-
FlatListProps<ReactNode>,
|
|
21
|
-
"data" | "renderItem" | "horizontal"
|
|
22
|
-
>;
|
|
23
|
-
theme?: UserTheme;
|
|
24
|
-
tokenizer?: Tokenizer;
|
|
25
|
-
hooks?: Hooks;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type TableColAlignment = "center" | "left" | "right" | null;
|
|
29
|
-
|
|
30
|
-
export interface RendererInterface {
|
|
31
|
-
paragraph(children: ReactNode[], styles?: ViewStyle): ReactNode;
|
|
32
|
-
blockquote(children: ReactNode[], styles?: ViewStyle): ReactNode;
|
|
33
|
-
heading(
|
|
34
|
-
text: string | ReactNode[],
|
|
35
|
-
styles?: TextStyle,
|
|
36
|
-
depth?: number,
|
|
37
|
-
): ReactNode;
|
|
38
|
-
code(
|
|
39
|
-
text: string,
|
|
40
|
-
language?: string,
|
|
41
|
-
containerStyle?: ViewStyle,
|
|
42
|
-
textStyle?: TextStyle,
|
|
43
|
-
): ReactNode;
|
|
44
|
-
hr(styles?: ViewStyle): ReactNode;
|
|
45
|
-
listItem(children: ReactNode[], styles?: ViewStyle): ReactNode;
|
|
46
|
-
list(
|
|
47
|
-
ordered: boolean,
|
|
48
|
-
li: ReactNode[],
|
|
49
|
-
listStyle?: ViewStyle,
|
|
50
|
-
textStyle?: TextStyle,
|
|
51
|
-
startIndex?: number,
|
|
52
|
-
): ReactNode;
|
|
53
|
-
escape(text: string, styles?: TextStyle): ReactNode;
|
|
54
|
-
link(
|
|
55
|
-
children: string | ReactNode[],
|
|
56
|
-
href: string,
|
|
57
|
-
styles?: TextStyle,
|
|
58
|
-
title?: string,
|
|
59
|
-
): ReactNode;
|
|
60
|
-
image(
|
|
61
|
-
uri: string,
|
|
62
|
-
alt?: string,
|
|
63
|
-
style?: ImageStyle,
|
|
64
|
-
title?: string,
|
|
65
|
-
): ReactNode;
|
|
66
|
-
strong(children: string | ReactNode[], styles?: TextStyle): ReactNode;
|
|
67
|
-
em(children: string | ReactNode[], styles?: TextStyle): ReactNode;
|
|
68
|
-
codespan(text: string, styles?: TextStyle): ReactNode;
|
|
69
|
-
br(): ReactNode;
|
|
70
|
-
del(children: string | ReactNode[], styles?: TextStyle): ReactNode;
|
|
71
|
-
text(text: string | ReactNode[], styles?: TextStyle): ReactNode;
|
|
72
|
-
html(text: string | ReactNode[], styles?: TextStyle): ReactNode;
|
|
73
|
-
linkImage(
|
|
74
|
-
href: string,
|
|
75
|
-
imageUrl: string,
|
|
76
|
-
alt?: string,
|
|
77
|
-
style?: ImageStyle,
|
|
78
|
-
title?: string | null,
|
|
79
|
-
): ReactNode;
|
|
80
|
-
table(
|
|
81
|
-
header: ReactNode[][],
|
|
82
|
-
rows: ReactNode[][][],
|
|
83
|
-
tableStyle?: ViewStyle,
|
|
84
|
-
rowStyle?: ViewStyle,
|
|
85
|
-
cellStyle?: ViewStyle,
|
|
86
|
-
): ReactNode;
|
|
87
|
-
}
|
|
1
|
+
import type { Hooks, Tokenizer } from "marked";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import type {
|
|
4
|
+
FlatListProps,
|
|
5
|
+
ImageStyle,
|
|
6
|
+
TextStyle,
|
|
7
|
+
ViewStyle,
|
|
8
|
+
} from "react-native";
|
|
9
|
+
import type { MarkedStyles, UserTheme } from "./../theme/types";
|
|
10
|
+
|
|
11
|
+
export interface ParserOptions {
|
|
12
|
+
styles?: MarkedStyles;
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
renderer: RendererInterface;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface MarkdownProps extends Partial<ParserOptions> {
|
|
18
|
+
value: string;
|
|
19
|
+
flatListProps?: Omit<
|
|
20
|
+
FlatListProps<ReactNode>,
|
|
21
|
+
"data" | "renderItem" | "horizontal"
|
|
22
|
+
>;
|
|
23
|
+
theme?: UserTheme;
|
|
24
|
+
tokenizer?: Tokenizer;
|
|
25
|
+
hooks?: Hooks;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type TableColAlignment = "center" | "left" | "right" | null;
|
|
29
|
+
|
|
30
|
+
export interface RendererInterface {
|
|
31
|
+
paragraph(children: ReactNode[], styles?: ViewStyle): ReactNode;
|
|
32
|
+
blockquote(children: ReactNode[], styles?: ViewStyle): ReactNode;
|
|
33
|
+
heading(
|
|
34
|
+
text: string | ReactNode[],
|
|
35
|
+
styles?: TextStyle,
|
|
36
|
+
depth?: number,
|
|
37
|
+
): ReactNode;
|
|
38
|
+
code(
|
|
39
|
+
text: string,
|
|
40
|
+
language?: string,
|
|
41
|
+
containerStyle?: ViewStyle,
|
|
42
|
+
textStyle?: TextStyle,
|
|
43
|
+
): ReactNode;
|
|
44
|
+
hr(styles?: ViewStyle): ReactNode;
|
|
45
|
+
listItem(children: ReactNode[], styles?: ViewStyle): ReactNode;
|
|
46
|
+
list(
|
|
47
|
+
ordered: boolean,
|
|
48
|
+
li: ReactNode[],
|
|
49
|
+
listStyle?: ViewStyle,
|
|
50
|
+
textStyle?: TextStyle,
|
|
51
|
+
startIndex?: number,
|
|
52
|
+
): ReactNode;
|
|
53
|
+
escape(text: string, styles?: TextStyle): ReactNode;
|
|
54
|
+
link(
|
|
55
|
+
children: string | ReactNode[],
|
|
56
|
+
href: string,
|
|
57
|
+
styles?: TextStyle,
|
|
58
|
+
title?: string,
|
|
59
|
+
): ReactNode;
|
|
60
|
+
image(
|
|
61
|
+
uri: string,
|
|
62
|
+
alt?: string,
|
|
63
|
+
style?: ImageStyle,
|
|
64
|
+
title?: string,
|
|
65
|
+
): ReactNode;
|
|
66
|
+
strong(children: string | ReactNode[], styles?: TextStyle): ReactNode;
|
|
67
|
+
em(children: string | ReactNode[], styles?: TextStyle): ReactNode;
|
|
68
|
+
codespan(text: string, styles?: TextStyle): ReactNode;
|
|
69
|
+
br(): ReactNode;
|
|
70
|
+
del(children: string | ReactNode[], styles?: TextStyle): ReactNode;
|
|
71
|
+
text(text: string | ReactNode[], styles?: TextStyle): ReactNode;
|
|
72
|
+
html(text: string | ReactNode[], styles?: TextStyle): ReactNode;
|
|
73
|
+
linkImage(
|
|
74
|
+
href: string,
|
|
75
|
+
imageUrl: string,
|
|
76
|
+
alt?: string,
|
|
77
|
+
style?: ImageStyle,
|
|
78
|
+
title?: string | null,
|
|
79
|
+
): ReactNode;
|
|
80
|
+
table(
|
|
81
|
+
header: ReactNode[][],
|
|
82
|
+
rows: ReactNode[][][],
|
|
83
|
+
tableStyle?: ViewStyle,
|
|
84
|
+
rowStyle?: ViewStyle,
|
|
85
|
+
cellStyle?: ViewStyle,
|
|
86
|
+
): ReactNode;
|
|
87
|
+
}
|