react-native-nitro-markdown 0.2.1 → 0.3.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/README.md +217 -101
- package/lib/commonjs/MarkdownContext.js +3 -7
- package/lib/commonjs/MarkdownContext.js.map +1 -1
- package/lib/commonjs/default-markdown-renderer.js +4 -7
- package/lib/commonjs/default-markdown-renderer.js.map +1 -1
- package/lib/commonjs/headless.js +12 -1
- package/lib/commonjs/headless.js.map +1 -1
- package/lib/commonjs/index.js +35 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/markdown.js +88 -37
- package/lib/commonjs/markdown.js.map +1 -1
- package/lib/commonjs/renderers/blockquote.js +1 -1
- package/lib/commonjs/renderers/blockquote.js.map +1 -1
- package/lib/commonjs/renderers/code.js +15 -8
- package/lib/commonjs/renderers/code.js.map +1 -1
- package/lib/commonjs/renderers/heading.js +2 -1
- package/lib/commonjs/renderers/heading.js.map +1 -1
- package/lib/commonjs/renderers/horizontal-rule.js +4 -2
- package/lib/commonjs/renderers/horizontal-rule.js.map +1 -1
- package/lib/commonjs/renderers/image.js +13 -9
- package/lib/commonjs/renderers/image.js.map +1 -1
- package/lib/commonjs/renderers/link.js +1 -3
- package/lib/commonjs/renderers/link.js.map +1 -1
- package/lib/commonjs/renderers/list.js +11 -7
- package/lib/commonjs/renderers/list.js.map +1 -1
- package/lib/commonjs/renderers/math.js +23 -47
- package/lib/commonjs/renderers/math.js.map +1 -1
- package/lib/commonjs/renderers/paragraph.js +0 -5
- package/lib/commonjs/renderers/paragraph.js.map +1 -1
- package/lib/commonjs/renderers/table.js +127 -120
- package/lib/commonjs/renderers/table.js.map +1 -1
- package/lib/commonjs/theme.js +146 -13
- package/lib/commonjs/theme.js.map +1 -1
- package/lib/module/MarkdownContext.js +3 -8
- package/lib/module/MarkdownContext.js.map +1 -1
- package/lib/module/default-markdown-renderer.js +1 -4
- package/lib/module/default-markdown-renderer.js.map +1 -1
- package/lib/module/headless.js +10 -0
- package/lib/module/headless.js.map +1 -1
- package/lib/module/index.js +2 -20
- package/lib/module/index.js.map +1 -1
- package/lib/module/markdown.js +89 -38
- package/lib/module/markdown.js.map +1 -1
- package/lib/module/renderers/blockquote.js +1 -1
- package/lib/module/renderers/blockquote.js.map +1 -1
- package/lib/module/renderers/code.js +15 -8
- package/lib/module/renderers/code.js.map +1 -1
- package/lib/module/renderers/heading.js +2 -1
- package/lib/module/renderers/heading.js.map +1 -1
- package/lib/module/renderers/horizontal-rule.js +4 -2
- package/lib/module/renderers/horizontal-rule.js.map +1 -1
- package/lib/module/renderers/image.js +13 -9
- package/lib/module/renderers/image.js.map +1 -1
- package/lib/module/renderers/link.js +1 -3
- package/lib/module/renderers/link.js.map +1 -1
- package/lib/module/renderers/list.js +11 -7
- package/lib/module/renderers/list.js.map +1 -1
- package/lib/module/renderers/math.js +24 -48
- package/lib/module/renderers/math.js.map +1 -1
- package/lib/module/renderers/paragraph.js +0 -5
- package/lib/module/renderers/paragraph.js.map +1 -1
- package/lib/module/renderers/table.js +128 -121
- package/lib/module/renderers/table.js.map +1 -1
- package/lib/module/theme.js +144 -12
- package/lib/module/theme.js.map +1 -1
- package/lib/typescript/commonjs/MarkdownContext.d.ts +45 -6
- package/lib/typescript/commonjs/MarkdownContext.d.ts.map +1 -1
- package/lib/typescript/commonjs/default-markdown-renderer.d.ts +1 -1
- package/lib/typescript/commonjs/default-markdown-renderer.d.ts.map +1 -1
- package/lib/typescript/commonjs/headless.d.ts +8 -1
- package/lib/typescript/commonjs/headless.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +4 -16
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/markdown.d.ts +20 -2
- package/lib/typescript/commonjs/markdown.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/code.d.ts +6 -2
- package/lib/typescript/commonjs/renderers/code.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/heading.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/horizontal-rule.d.ts +6 -1
- package/lib/typescript/commonjs/renderers/horizontal-rule.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/image.d.ts +2 -0
- package/lib/typescript/commonjs/renderers/image.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/link.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/list.d.ts +4 -0
- package/lib/typescript/commonjs/renderers/list.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/math.d.ts +3 -4
- package/lib/typescript/commonjs/renderers/math.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/paragraph.d.ts +0 -5
- package/lib/typescript/commonjs/renderers/paragraph.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/table.d.ts +2 -0
- package/lib/typescript/commonjs/renderers/table.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme.d.ts +41 -28
- package/lib/typescript/commonjs/theme.d.ts.map +1 -1
- package/lib/typescript/module/MarkdownContext.d.ts +45 -6
- package/lib/typescript/module/MarkdownContext.d.ts.map +1 -1
- package/lib/typescript/module/default-markdown-renderer.d.ts +1 -1
- package/lib/typescript/module/default-markdown-renderer.d.ts.map +1 -1
- package/lib/typescript/module/headless.d.ts +8 -1
- package/lib/typescript/module/headless.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +4 -16
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/markdown.d.ts +20 -2
- package/lib/typescript/module/markdown.d.ts.map +1 -1
- package/lib/typescript/module/renderers/code.d.ts +6 -2
- package/lib/typescript/module/renderers/code.d.ts.map +1 -1
- package/lib/typescript/module/renderers/heading.d.ts.map +1 -1
- package/lib/typescript/module/renderers/horizontal-rule.d.ts +6 -1
- package/lib/typescript/module/renderers/horizontal-rule.d.ts.map +1 -1
- package/lib/typescript/module/renderers/image.d.ts +2 -0
- package/lib/typescript/module/renderers/image.d.ts.map +1 -1
- package/lib/typescript/module/renderers/link.d.ts.map +1 -1
- package/lib/typescript/module/renderers/list.d.ts +4 -0
- package/lib/typescript/module/renderers/list.d.ts.map +1 -1
- package/lib/typescript/module/renderers/math.d.ts +3 -4
- package/lib/typescript/module/renderers/math.d.ts.map +1 -1
- package/lib/typescript/module/renderers/paragraph.d.ts +0 -5
- package/lib/typescript/module/renderers/paragraph.d.ts.map +1 -1
- package/lib/typescript/module/renderers/table.d.ts +2 -0
- package/lib/typescript/module/renderers/table.d.ts.map +1 -1
- package/lib/typescript/module/theme.d.ts +41 -28
- package/lib/typescript/module/theme.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/MarkdownContext.ts +66 -9
- package/src/default-markdown-renderer.tsx +1 -6
- package/src/headless.ts +11 -1
- package/src/index.ts +24 -19
- package/src/markdown.tsx +125 -43
- package/src/renderers/blockquote.tsx +1 -2
- package/src/renderers/code.tsx +36 -12
- package/src/renderers/heading.tsx +1 -1
- package/src/renderers/horizontal-rule.tsx +7 -4
- package/src/renderers/image.tsx +24 -9
- package/src/renderers/link.tsx +1 -6
- package/src/renderers/list.tsx +11 -5
- package/src/renderers/math.tsx +20 -43
- package/src/renderers/paragraph.tsx +0 -6
- package/src/renderers/table.tsx +185 -160
- package/src/theme.ts +203 -12
package/src/renderers/list.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactNode, useMemo, type FC } from "react";
|
|
2
|
-
import { View, Text, StyleSheet } from "react-native";
|
|
2
|
+
import { View, Text, StyleSheet, type ViewStyle } from "react-native";
|
|
3
3
|
import { useMarkdownContext } from "../MarkdownContext";
|
|
4
4
|
|
|
5
5
|
interface ListProps {
|
|
@@ -7,6 +7,7 @@ interface ListProps {
|
|
|
7
7
|
start?: number;
|
|
8
8
|
depth: number;
|
|
9
9
|
children: ReactNode;
|
|
10
|
+
style?: ViewStyle;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export const List: FC<ListProps> = ({
|
|
@@ -14,6 +15,7 @@ export const List: FC<ListProps> = ({
|
|
|
14
15
|
start = 1,
|
|
15
16
|
depth,
|
|
16
17
|
children,
|
|
18
|
+
style,
|
|
17
19
|
}) => {
|
|
18
20
|
const { theme } = useMarkdownContext();
|
|
19
21
|
const styles = useMemo(
|
|
@@ -30,7 +32,7 @@ export const List: FC<ListProps> = ({
|
|
|
30
32
|
[theme]
|
|
31
33
|
);
|
|
32
34
|
return (
|
|
33
|
-
<View style={[styles.list, depth > 0 && styles.listNested]}>
|
|
35
|
+
<View style={[styles.list, depth > 0 && styles.listNested, style]}>
|
|
34
36
|
{children}
|
|
35
37
|
</View>
|
|
36
38
|
);
|
|
@@ -41,6 +43,7 @@ interface ListItemProps {
|
|
|
41
43
|
index: number;
|
|
42
44
|
ordered: boolean;
|
|
43
45
|
start: number;
|
|
46
|
+
style?: ViewStyle;
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
export const ListItem: FC<ListItemProps> = ({
|
|
@@ -48,6 +51,7 @@ export const ListItem: FC<ListItemProps> = ({
|
|
|
48
51
|
index,
|
|
49
52
|
ordered,
|
|
50
53
|
start,
|
|
54
|
+
style,
|
|
51
55
|
}) => {
|
|
52
56
|
const { theme } = useMarkdownContext();
|
|
53
57
|
const styles = useMemo(
|
|
@@ -65,6 +69,7 @@ export const ListItem: FC<ListItemProps> = ({
|
|
|
65
69
|
marginRight: theme.spacing.s,
|
|
66
70
|
minWidth: 20,
|
|
67
71
|
textAlign: "center",
|
|
72
|
+
fontFamily: theme.fontFamilies.regular,
|
|
68
73
|
},
|
|
69
74
|
listItemContent: {
|
|
70
75
|
flex: 1,
|
|
@@ -76,7 +81,7 @@ export const ListItem: FC<ListItemProps> = ({
|
|
|
76
81
|
);
|
|
77
82
|
const bullet = ordered ? `${start + index}.` : "•";
|
|
78
83
|
return (
|
|
79
|
-
<View style={styles.listItem}>
|
|
84
|
+
<View style={[styles.listItem, style]}>
|
|
80
85
|
<Text style={styles.listBullet}>{bullet}</Text>
|
|
81
86
|
<View style={styles.listItemContent}>{children}</View>
|
|
82
87
|
</View>
|
|
@@ -86,11 +91,13 @@ export const ListItem: FC<ListItemProps> = ({
|
|
|
86
91
|
interface TaskListItemProps {
|
|
87
92
|
children: ReactNode;
|
|
88
93
|
checked: boolean;
|
|
94
|
+
style?: ViewStyle;
|
|
89
95
|
}
|
|
90
96
|
|
|
91
97
|
export const TaskListItem: FC<TaskListItemProps> = ({
|
|
92
98
|
children,
|
|
93
99
|
checked,
|
|
100
|
+
style,
|
|
94
101
|
}) => {
|
|
95
102
|
const { theme } = useMarkdownContext();
|
|
96
103
|
const styles = useMemo(
|
|
@@ -116,10 +123,9 @@ export const TaskListItem: FC<TaskListItemProps> = ({
|
|
|
116
123
|
[theme]
|
|
117
124
|
);
|
|
118
125
|
return (
|
|
119
|
-
<View style={styles.taskListItem}>
|
|
126
|
+
<View style={[styles.taskListItem, style]}>
|
|
120
127
|
<Text style={styles.taskCheckbox}>{checked ? "☑" : "☐"}</Text>
|
|
121
128
|
<View style={styles.taskContent}>{children}</View>
|
|
122
129
|
</View>
|
|
123
130
|
);
|
|
124
131
|
};
|
|
125
|
-
|
package/src/renderers/math.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
View,
|
|
4
4
|
Text,
|
|
5
5
|
StyleSheet,
|
|
6
|
+
Platform,
|
|
6
7
|
type StyleProp,
|
|
7
8
|
type ViewStyle,
|
|
8
9
|
} from "react-native";
|
|
@@ -27,41 +28,25 @@ try {
|
|
|
27
28
|
|
|
28
29
|
interface MathInlineProps {
|
|
29
30
|
content?: string;
|
|
31
|
+
style?: ViewStyle;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
/**
|
|
33
|
-
* Inline math renderer.
|
|
34
|
-
* Uses react-native-mathjax-svg if installed, otherwise shows raw LaTeX.
|
|
35
|
-
* Note: Renders as a View since SVG can't be nested in Text.
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
34
|
const createMathStyles = (theme: MarkdownTheme) =>
|
|
39
35
|
StyleSheet.create({
|
|
40
36
|
mathInlineContainer: {
|
|
41
|
-
flexDirection: "row",
|
|
42
|
-
alignItems: "baseline",
|
|
43
|
-
alignSelf: "baseline",
|
|
44
|
-
justifyContent: "flex-start",
|
|
45
|
-
flexShrink: 1,
|
|
46
37
|
marginHorizontal: 2,
|
|
47
|
-
top: -theme.fontSizes.m,
|
|
48
|
-
marginBottom: 0,
|
|
49
|
-
paddingVertical: 0,
|
|
50
|
-
},
|
|
51
|
-
mathJaxInline: {
|
|
52
|
-
marginTop: 0,
|
|
53
|
-
marginBottom: 0,
|
|
54
38
|
},
|
|
55
39
|
mathInlineFallbackContainer: {
|
|
56
40
|
backgroundColor: theme.colors.codeBackground,
|
|
57
|
-
paddingHorizontal:
|
|
41
|
+
paddingHorizontal: theme.spacing.xs,
|
|
58
42
|
paddingVertical: 2,
|
|
59
|
-
borderRadius:
|
|
60
|
-
alignSelf: "baseline",
|
|
43
|
+
borderRadius: theme.borderRadius.s,
|
|
61
44
|
marginHorizontal: 2,
|
|
62
45
|
},
|
|
63
46
|
mathInlineFallback: {
|
|
64
|
-
fontFamily:
|
|
47
|
+
fontFamily:
|
|
48
|
+
theme.fontFamilies.mono ??
|
|
49
|
+
Platform.select({ ios: "Courier", android: "monospace" }),
|
|
65
50
|
fontSize: theme.fontSizes.s,
|
|
66
51
|
color: theme.colors.code,
|
|
67
52
|
},
|
|
@@ -70,49 +55,45 @@ const createMathStyles = (theme: MarkdownTheme) =>
|
|
|
70
55
|
paddingVertical: theme.spacing.l,
|
|
71
56
|
paddingHorizontal: theme.spacing.l,
|
|
72
57
|
backgroundColor: theme.colors.surface,
|
|
73
|
-
borderRadius:
|
|
58
|
+
borderRadius: theme.borderRadius.l,
|
|
74
59
|
alignItems: "center",
|
|
75
60
|
borderWidth: 1,
|
|
76
61
|
borderColor: theme.colors.border,
|
|
77
|
-
shadowColor: "#000",
|
|
78
|
-
shadowOffset: { width: 0, height: 1 },
|
|
79
|
-
shadowOpacity: 0.05,
|
|
80
|
-
shadowRadius: 2,
|
|
81
|
-
elevation: 1,
|
|
82
62
|
},
|
|
83
63
|
mathBlockFallbackContainer: {
|
|
84
64
|
marginVertical: theme.spacing.m,
|
|
85
65
|
paddingVertical: theme.spacing.m,
|
|
86
66
|
paddingHorizontal: theme.spacing.l,
|
|
87
67
|
backgroundColor: theme.colors.codeBackground,
|
|
88
|
-
borderRadius:
|
|
68
|
+
borderRadius: theme.borderRadius.m,
|
|
89
69
|
alignItems: "center",
|
|
90
70
|
borderWidth: 1,
|
|
91
71
|
borderColor: theme.colors.border,
|
|
92
72
|
},
|
|
93
73
|
mathBlockFallback: {
|
|
94
|
-
fontFamily:
|
|
74
|
+
fontFamily:
|
|
75
|
+
theme.fontFamilies.mono ??
|
|
76
|
+
Platform.select({ ios: "Courier", android: "monospace" }),
|
|
95
77
|
fontSize: theme.fontSizes.m,
|
|
96
78
|
color: theme.colors.code,
|
|
97
79
|
textAlign: "center",
|
|
98
80
|
},
|
|
99
81
|
});
|
|
100
82
|
|
|
101
|
-
export const MathInline: FC<MathInlineProps> = ({ content }) => {
|
|
83
|
+
export const MathInline: FC<MathInlineProps> = ({ content, style }) => {
|
|
102
84
|
const { theme } = useMarkdownContext();
|
|
103
85
|
const styles = useMemo(() => createMathStyles(theme), [theme]);
|
|
104
86
|
|
|
105
87
|
if (!content) return null;
|
|
106
88
|
|
|
107
89
|
if (MathJaxComponent) {
|
|
108
|
-
const fontSize = theme.fontSizes.
|
|
90
|
+
const fontSize = theme.fontSizes.s;
|
|
109
91
|
return (
|
|
110
|
-
<View style={styles.mathInlineContainer}>
|
|
92
|
+
<View style={[styles.mathInlineContainer, style]}>
|
|
111
93
|
<MathJaxComponent
|
|
112
94
|
fontSize={fontSize}
|
|
113
95
|
color={theme.colors.text}
|
|
114
96
|
fontCache={true}
|
|
115
|
-
style={styles.mathJaxInline}
|
|
116
97
|
>
|
|
117
98
|
{content}
|
|
118
99
|
</MathJaxComponent>
|
|
@@ -121,7 +102,7 @@ export const MathInline: FC<MathInlineProps> = ({ content }) => {
|
|
|
121
102
|
}
|
|
122
103
|
|
|
123
104
|
return (
|
|
124
|
-
<View style={styles.mathInlineFallbackContainer}>
|
|
105
|
+
<View style={[styles.mathInlineFallbackContainer, style]}>
|
|
125
106
|
<Text style={styles.mathInlineFallback}>{content}</Text>
|
|
126
107
|
</View>
|
|
127
108
|
);
|
|
@@ -129,13 +110,10 @@ export const MathInline: FC<MathInlineProps> = ({ content }) => {
|
|
|
129
110
|
|
|
130
111
|
interface MathBlockProps {
|
|
131
112
|
content?: string;
|
|
113
|
+
style?: ViewStyle;
|
|
132
114
|
}
|
|
133
115
|
|
|
134
|
-
|
|
135
|
-
* Block math renderer.
|
|
136
|
-
* Uses react-native-mathjax-svg if installed, otherwise shows raw LaTeX.
|
|
137
|
-
*/
|
|
138
|
-
export const MathBlock: FC<MathBlockProps> = ({ content }) => {
|
|
116
|
+
export const MathBlock: FC<MathBlockProps> = ({ content, style }) => {
|
|
139
117
|
const { theme } = useMarkdownContext();
|
|
140
118
|
const styles = useMemo(() => createMathStyles(theme), [theme]);
|
|
141
119
|
|
|
@@ -143,7 +121,7 @@ export const MathBlock: FC<MathBlockProps> = ({ content }) => {
|
|
|
143
121
|
|
|
144
122
|
if (MathJaxComponent) {
|
|
145
123
|
return (
|
|
146
|
-
<View style={styles.mathBlockContainer}>
|
|
124
|
+
<View style={[styles.mathBlockContainer, style]}>
|
|
147
125
|
<MathJaxComponent
|
|
148
126
|
fontSize={theme.fontSizes.l}
|
|
149
127
|
color={theme.colors.text}
|
|
@@ -156,9 +134,8 @@ export const MathBlock: FC<MathBlockProps> = ({ content }) => {
|
|
|
156
134
|
}
|
|
157
135
|
|
|
158
136
|
return (
|
|
159
|
-
<View style={styles.mathBlockFallbackContainer}>
|
|
137
|
+
<View style={[styles.mathBlockFallbackContainer, style]}>
|
|
160
138
|
<Text style={styles.mathBlockFallback}>{content}</Text>
|
|
161
139
|
</View>
|
|
162
140
|
);
|
|
163
141
|
};
|
|
164
|
-
|
|
@@ -8,11 +8,6 @@ interface ParagraphProps {
|
|
|
8
8
|
style?: StyleProp<ViewStyle>;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Paragraph component that supports mixed content (Text and View elements).
|
|
13
|
-
* Uses View with flexDirection: 'row' and flexWrap: 'wrap' to allow inline flow
|
|
14
|
-
* of both text and non-text elements (like inline math).
|
|
15
|
-
*/
|
|
16
11
|
export const Paragraph: FC<ParagraphProps> = ({
|
|
17
12
|
children,
|
|
18
13
|
inListItem,
|
|
@@ -50,4 +45,3 @@ export const Paragraph: FC<ParagraphProps> = ({
|
|
|
50
45
|
</View>
|
|
51
46
|
);
|
|
52
47
|
};
|
|
53
|
-
|