react-native-marked 8.2.0 → 8.3.1

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