react-native-marked 1.4.3 → 1.6.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 +33 -11
- package/dist/commonjs/lib/Markdown.js +7 -4
- package/dist/commonjs/lib/Markdown.js.map +1 -1
- package/dist/commonjs/lib/Parser.js +11 -3
- package/dist/commonjs/lib/Parser.js.map +1 -1
- package/dist/commonjs/theme/colors.js.map +1 -1
- package/dist/commonjs/theme/spacing.js +15 -0
- package/dist/commonjs/theme/spacing.js.map +1 -0
- package/dist/commonjs/theme/styles.js +37 -28
- package/dist/commonjs/theme/styles.js.map +1 -1
- package/dist/commonjs/utils/url.js +29 -0
- package/dist/commonjs/utils/url.js.map +1 -0
- package/dist/module/lib/Markdown.js +7 -4
- package/dist/module/lib/Markdown.js.map +1 -1
- package/dist/module/lib/Parser.js +10 -3
- package/dist/module/lib/Parser.js.map +1 -1
- package/dist/module/theme/colors.js.map +1 -1
- package/dist/module/theme/spacing.js +8 -0
- package/dist/module/theme/spacing.js.map +1 -0
- package/dist/module/theme/styles.js +34 -28
- package/dist/module/theme/styles.js.map +1 -1
- package/dist/module/utils/url.js +20 -0
- package/dist/module/utils/url.js.map +1 -0
- package/dist/typescript/lib/Markdown.d.ts +1 -1
- package/dist/typescript/lib/Markdown.d.ts.map +1 -1
- package/dist/typescript/lib/Parser.d.ts +1 -0
- package/dist/typescript/lib/Parser.d.ts.map +1 -1
- package/dist/typescript/lib/types.d.ts +4 -3
- package/dist/typescript/lib/types.d.ts.map +1 -1
- package/dist/typescript/theme/colors.d.ts +3 -2
- package/dist/typescript/theme/colors.d.ts.map +1 -1
- package/dist/typescript/theme/spacing.d.ts +4 -0
- package/dist/typescript/theme/spacing.d.ts.map +1 -0
- package/dist/typescript/theme/styles.d.ts +2 -2
- package/dist/typescript/theme/styles.d.ts.map +1 -1
- package/dist/typescript/theme/types.d.ts +5 -3
- package/dist/typescript/theme/types.d.ts.map +1 -1
- package/dist/typescript/utils/url.d.ts +2 -0
- package/dist/typescript/utils/url.d.ts.map +1 -0
- package/package.json +11 -11
- package/src/lib/Markdown.tsx +8 -12
- package/src/lib/Parser.tsx +15 -3
- package/src/lib/types.ts +4 -3
- package/src/theme/colors.ts +3 -2
- package/src/theme/spacing.ts +10 -0
- package/src/theme/styles.ts +33 -29
- package/src/theme/types.ts +5 -4
- package/src/utils/url.ts +19 -0
- package/dist/commonjs/theme/theme.js +0 -19
- package/dist/commonjs/theme/theme.js.map +0 -1
- package/dist/module/theme/theme.js +0 -7
- package/dist/module/theme/theme.js.map +0 -1
- package/dist/typescript/theme/theme.d.ts +0 -4
- package/dist/typescript/theme/theme.d.ts.map +0 -1
- package/src/theme/theme.ts +0 -9
|
@@ -1,26 +1,32 @@
|
|
|
1
1
|
import { StyleSheet } from 'react-native';
|
|
2
|
-
import
|
|
2
|
+
import spacing from './spacing';
|
|
3
|
+
import colors from './colors';
|
|
3
4
|
|
|
4
|
-
const getFontStyles =
|
|
5
|
+
const getFontStyles = mdColors => {
|
|
5
6
|
return StyleSheet.create({
|
|
6
7
|
regular: {
|
|
7
8
|
fontSize: 16,
|
|
8
9
|
lineHeight: 24,
|
|
9
|
-
color:
|
|
10
|
+
color: mdColors.text
|
|
10
11
|
},
|
|
11
12
|
heading: {
|
|
12
13
|
fontWeight: '500',
|
|
13
|
-
color:
|
|
14
|
+
color: mdColors.text
|
|
14
15
|
}
|
|
15
16
|
});
|
|
16
17
|
};
|
|
17
18
|
|
|
18
|
-
const getStyles = (userStyles, colorScheme) => {
|
|
19
|
-
const
|
|
20
|
-
|
|
19
|
+
const getStyles = (userStyles, colorScheme, userTheme) => {
|
|
20
|
+
const mdColors = { ...colors[colorScheme || 'light'],
|
|
21
|
+
...(userTheme === null || userTheme === void 0 ? void 0 : userTheme.colors)
|
|
22
|
+
};
|
|
23
|
+
const mdSpacing = { ...spacing,
|
|
24
|
+
...(userTheme === null || userTheme === void 0 ? void 0 : userTheme.spacing)
|
|
25
|
+
};
|
|
26
|
+
const fontStyle = getFontStyles(mdColors);
|
|
21
27
|
const defaultStyles = StyleSheet.create({
|
|
22
28
|
container: {
|
|
23
|
-
backgroundColor:
|
|
29
|
+
backgroundColor: mdColors.background
|
|
24
30
|
},
|
|
25
31
|
em: { ...fontStyle.regular,
|
|
26
32
|
fontStyle: 'italic'
|
|
@@ -35,69 +41,69 @@ const getStyles = (userStyles, colorScheme) => {
|
|
|
35
41
|
text: { ...fontStyle.regular
|
|
36
42
|
},
|
|
37
43
|
paragraph: { ...fontStyle.regular,
|
|
38
|
-
paddingVertical:
|
|
44
|
+
paddingVertical: mdSpacing.m
|
|
39
45
|
},
|
|
40
46
|
link: { ...fontStyle.regular,
|
|
41
47
|
fontStyle: 'italic',
|
|
42
|
-
color:
|
|
48
|
+
color: mdColors.link
|
|
43
49
|
},
|
|
44
50
|
blockquote: {
|
|
45
|
-
borderLeftColor:
|
|
46
|
-
paddingLeft:
|
|
47
|
-
borderLeftWidth:
|
|
51
|
+
borderLeftColor: mdColors.border,
|
|
52
|
+
paddingLeft: mdSpacing.l,
|
|
53
|
+
borderLeftWidth: mdSpacing.s,
|
|
48
54
|
opacity: 0.8
|
|
49
55
|
},
|
|
50
56
|
h1: {
|
|
51
57
|
fontSize: 32,
|
|
52
58
|
lineHeight: 40,
|
|
53
59
|
fontWeight: 'bold',
|
|
54
|
-
marginVertical:
|
|
60
|
+
marginVertical: mdSpacing.m,
|
|
55
61
|
letterSpacing: 0,
|
|
56
|
-
paddingBottom:
|
|
57
|
-
borderBottomColor:
|
|
62
|
+
paddingBottom: mdSpacing.s,
|
|
63
|
+
borderBottomColor: mdColors.border,
|
|
58
64
|
borderBottomWidth: 1
|
|
59
65
|
},
|
|
60
66
|
h2: { ...fontStyle.heading,
|
|
61
67
|
fontSize: 28,
|
|
62
68
|
lineHeight: 36,
|
|
63
|
-
marginVertical:
|
|
64
|
-
paddingBottom:
|
|
65
|
-
borderBottomColor:
|
|
69
|
+
marginVertical: mdSpacing.m,
|
|
70
|
+
paddingBottom: mdSpacing.s,
|
|
71
|
+
borderBottomColor: mdColors.border,
|
|
66
72
|
borderBottomWidth: 1
|
|
67
73
|
},
|
|
68
74
|
h3: { ...fontStyle.heading,
|
|
69
75
|
fontSize: 24,
|
|
70
76
|
lineHeight: 32,
|
|
71
|
-
marginVertical:
|
|
77
|
+
marginVertical: mdSpacing.s
|
|
72
78
|
},
|
|
73
79
|
h4: { ...fontStyle.heading,
|
|
74
80
|
fontSize: 22,
|
|
75
81
|
lineHeight: 28,
|
|
76
|
-
marginVertical:
|
|
82
|
+
marginVertical: mdSpacing.s
|
|
77
83
|
},
|
|
78
84
|
h5: { ...fontStyle.regular,
|
|
79
85
|
...fontStyle.heading,
|
|
80
|
-
marginVertical:
|
|
86
|
+
marginVertical: mdSpacing.xs
|
|
81
87
|
},
|
|
82
88
|
h6: { ...fontStyle.heading,
|
|
83
89
|
fontSize: 14,
|
|
84
90
|
lineHeight: 20,
|
|
85
|
-
marginVertical:
|
|
91
|
+
marginVertical: mdSpacing.xs
|
|
86
92
|
},
|
|
87
93
|
codespan: { ...fontStyle.regular,
|
|
88
94
|
fontStyle: 'italic',
|
|
89
|
-
backgroundColor:
|
|
95
|
+
backgroundColor: mdColors.code,
|
|
90
96
|
fontWeight: '300'
|
|
91
97
|
},
|
|
92
98
|
code: {
|
|
93
|
-
padding:
|
|
94
|
-
backgroundColor:
|
|
99
|
+
padding: mdSpacing.l,
|
|
100
|
+
backgroundColor: mdColors.code,
|
|
95
101
|
minWidth: '100%'
|
|
96
102
|
},
|
|
97
103
|
hr: {
|
|
98
104
|
borderBottomWidth: 1,
|
|
99
|
-
borderBottomColor:
|
|
100
|
-
marginVertical:
|
|
105
|
+
borderBottomColor: mdColors.border,
|
|
106
|
+
marginVertical: mdSpacing.s
|
|
101
107
|
},
|
|
102
108
|
li: { ...fontStyle.regular,
|
|
103
109
|
flexShrink: 1
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["StyleSheet","
|
|
1
|
+
{"version":3,"names":["StyleSheet","spacing","colors","getFontStyles","mdColors","create","regular","fontSize","lineHeight","color","text","heading","fontWeight","getStyles","userStyles","colorScheme","userTheme","mdSpacing","fontStyle","defaultStyles","container","backgroundColor","background","em","strong","strikethrough","textDecorationLine","textDecorationStyle","paragraph","paddingVertical","m","link","blockquote","borderLeftColor","border","paddingLeft","l","borderLeftWidth","s","opacity","h1","marginVertical","letterSpacing","paddingBottom","borderBottomColor","borderBottomWidth","h2","h3","h4","h5","xs","h6","codespan","code","padding","minWidth","hr","li","flexShrink","image","resizeMode"],"sourceRoot":"../../src","sources":["styles.ts"],"mappings":"AAAA,SAA0BA,UAA1B,QAA4C,cAA5C;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAOC,MAAP,MAA4C,UAA5C;;AAGA,MAAMC,aAAa,GAAIC,QAAD,IAA8B;EAClD,OAAOJ,UAAU,CAACK,MAAX,CAAkB;IACvBC,OAAO,EAAE;MACPC,QAAQ,EAAE,EADH;MAEPC,UAAU,EAAE,EAFL;MAGPC,KAAK,EAAEL,QAAQ,CAACM;IAHT,CADc;IAMvBC,OAAO,EAAE;MACPC,UAAU,EAAE,KADL;MAEPH,KAAK,EAAEL,QAAQ,CAACM;IAFT;EANc,CAAlB,CAAP;AAWD,CAZD;;AAcA,MAAMG,SAAS,GAAG,CAChBC,UADgB,EAEhBC,WAFgB,EAGhBC,SAHgB,KAIC;EACjB,MAAMZ,QAAQ,GAAG,EAAE,GAAGF,MAAM,CAACa,WAAW,IAAI,OAAhB,CAAX;IAAqC,IAAGC,SAAH,aAAGA,SAAH,uBAAGA,SAAS,CAAEd,MAAd;EAArC,CAAjB;EACA,MAAMe,SAAS,GAAG,EAAE,GAAGhB,OAAL;IAAc,IAAGe,SAAH,aAAGA,SAAH,uBAAGA,SAAS,CAAEf,OAAd;EAAd,CAAlB;EAEA,MAAMiB,SAAS,GAAGf,aAAa,CAACC,QAAD,CAA/B;EACA,MAAMe,aAAa,GAAGnB,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,GAAGvC,SAAS,CAACZ,OADX;MAEFoD,UAAU,EAAE;IAFV,CA7FgD;IAiGpDC,KAAK,EAAE;MACLC,UAAU,EAAE;IADP;EAjG6C,CAAhC,CAAtB;EAsGA,OAAO,EACL,GAAGzC,aADE;IAEL,GAAGL;EAFE,CAAP;AAID,CAnHD;;AAqHA,eAAeD,SAAf"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const getValidURL = (prefix, path) => {
|
|
2
|
+
// remove trailing slash from prefix
|
|
3
|
+
if (prefix.endsWith('/')) {
|
|
4
|
+
prefix = prefix.slice(0, -1);
|
|
5
|
+
} // path is valid url
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
if (path.startsWith('https') || path.startsWith('http')) {
|
|
9
|
+
return path;
|
|
10
|
+
} // absolute path
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
if (path.startsWith('/')) {
|
|
14
|
+
return `${prefix}${path}`;
|
|
15
|
+
} // relative path
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
return `${prefix}/${path}`;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getValidURL","prefix","path","endsWith","slice","startsWith"],"sourceRoot":"../../src","sources":["url.ts"],"mappings":"AAAA,OAAO,MAAMA,WAAW,GAAG,CAACC,MAAD,EAAiBC,IAAjB,KAAkC;EAC3D;EACA,IAAID,MAAM,CAACE,QAAP,CAAgB,GAAhB,CAAJ,EAA0B;IACxBF,MAAM,GAAGA,MAAM,CAACG,KAAP,CAAa,CAAb,EAAgB,CAAC,CAAjB,CAAT;EACD,CAJ0D,CAM3D;;;EACA,IAAIF,IAAI,CAACG,UAAL,CAAgB,OAAhB,KAA4BH,IAAI,CAACG,UAAL,CAAgB,MAAhB,CAAhC,EAAyD;IACvD,OAAOH,IAAP;EACD,CAT0D,CAW3D;;;EACA,IAAIA,IAAI,CAACG,UAAL,CAAgB,GAAhB,CAAJ,EAA0B;IACxB,OAAQ,GAAEJ,MAAO,GAAEC,IAAK,EAAxB;EACD,CAd0D,CAgB3D;;;EACA,OAAQ,GAAED,MAAO,IAAGC,IAAK,EAAzB;AACD,CAlBM"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { MarkdownProps } from './types';
|
|
3
|
-
declare const _default: React.MemoExoticComponent<({ value, flatListProps, styles: userStyles, }: MarkdownProps) => JSX.Element>;
|
|
3
|
+
declare const _default: React.MemoExoticComponent<({ value, flatListProps, theme, baseUrl, styles: userStyles, }: MarkdownProps) => JSX.Element>;
|
|
4
4
|
export default _default;
|
|
5
5
|
//# sourceMappingURL=Markdown.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Markdown.d.ts","sourceRoot":"","sources":["../../../src/lib/Markdown.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAgD,MAAM,OAAO,CAAC;AAKrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;;
|
|
1
|
+
{"version":3,"file":"Markdown.d.ts","sourceRoot":"","sources":["../../../src/lib/Markdown.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAgD,MAAM,OAAO,CAAC;AAKrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;;AA4C7C,wBAA8B"}
|
|
@@ -6,6 +6,7 @@ declare class Parser {
|
|
|
6
6
|
private renderer;
|
|
7
7
|
private styles;
|
|
8
8
|
private headingStylesMap;
|
|
9
|
+
private baseUrl;
|
|
9
10
|
constructor(options: ParserOptions);
|
|
10
11
|
parse(tokens: marked.Token[]): ReactNode[];
|
|
11
12
|
parseInline(tokens: marked.Token[], styles?: ViewStyle | TextStyle | ImageStyle): ReactNode[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Parser.d.ts","sourceRoot":"","sources":["../../../src/lib/Parser.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGrC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"Parser.d.ts","sourceRoot":"","sources":["../../../src/lib/Parser.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGrC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAG7C,cAAM,MAAM;IACV,OAAO,CAAC,QAAQ,CAAC;IACjB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,gBAAgB,CAAwC;IAChE,OAAO,CAAC,OAAO,CAAS;gBACZ,OAAO,EAAE,aAAa;IAclC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE;IA0E5B,WAAW,CACT,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,EACtB,MAAM,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,UAAU;IA6F7C,OAAO,CAAC,gDAAgD,CAuDtD;CACH;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { FlatListProps } from 'react-native';
|
|
3
|
-
import type { MarkedStyles } from './../theme/types';
|
|
3
|
+
import type { MarkedStyles, UserTheme } from './../theme/types';
|
|
4
4
|
export interface ParserOptions {
|
|
5
5
|
styles?: MarkedStyles;
|
|
6
|
+
baseUrl?: string;
|
|
6
7
|
}
|
|
7
|
-
export interface MarkdownProps {
|
|
8
|
+
export interface MarkdownProps extends ParserOptions {
|
|
8
9
|
value: string;
|
|
9
10
|
flatListProps?: Omit<FlatListProps<ReactNode>, 'data' | 'renderItem' | 'horizontal'>;
|
|
10
|
-
|
|
11
|
+
theme?: UserTheme;
|
|
11
12
|
}
|
|
12
13
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEhE,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAc,SAAQ,aAAa;IAClD,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,IAAI,CAClB,aAAa,CAAC,SAAS,CAAC,EACxB,MAAM,GAAG,YAAY,GAAG,YAAY,CACrC,CAAC;IACF,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
declare
|
|
1
|
+
export declare type ColorKeysType = 'background' | 'code' | 'link' | 'text' | 'border';
|
|
2
|
+
export declare type ColorsPropType = Record<ColorKeysType, string>;
|
|
3
|
+
declare const colors: Record<'light' | 'dark', ColorsPropType>;
|
|
3
4
|
export default colors;
|
|
4
5
|
//# sourceMappingURL=colors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../../src/theme/colors.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../../src/theme/colors.ts"],"names":[],"mappings":"AAAA,oBAAY,aAAa,GAAG,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAC/E,oBAAY,cAAc,GAAG,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;AAE3D,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,EAAE,cAAc,CAepD,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spacing.d.ts","sourceRoot":"","sources":["../../../src/theme/spacing.ts"],"names":[],"mappings":"AAAA,oBAAY,eAAe,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAErD,QAAA,MAAM,OAAO,EAAE,MAAM,CAAC,eAAe,EAAE,MAAM,CAK5C,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ColorSchemeName } from 'react-native';
|
|
2
|
-
import type { MarkedStyles } from './types';
|
|
3
|
-
declare const getStyles: (userStyles?: MarkedStyles, colorScheme?: ColorSchemeName) => MarkedStyles;
|
|
2
|
+
import type { MarkedStyles, UserTheme } from './types';
|
|
3
|
+
declare const getStyles: (userStyles?: MarkedStyles, colorScheme?: ColorSchemeName, userTheme?: UserTheme) => MarkedStyles;
|
|
4
4
|
export default getStyles;
|
|
5
5
|
//# sourceMappingURL=styles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../src/theme/styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAc,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../src/theme/styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAc,MAAM,cAAc,CAAC;AAG3D,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAgBvD,QAAA,MAAM,SAAS,gBACA,YAAY,gBACX,eAAe,cACjB,SAAS,KACpB,YA+GF,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { ImageStyle, TextStyle, ViewStyle } from 'react-native';
|
|
2
|
+
import type { ColorKeysType } from './colors';
|
|
3
|
+
import type { SpacingKeysType } from './spacing';
|
|
2
4
|
export interface MarkedStyles {
|
|
3
5
|
container?: ViewStyle;
|
|
4
6
|
em?: TextStyle;
|
|
@@ -21,8 +23,8 @@ export interface MarkedStyles {
|
|
|
21
23
|
li?: TextStyle;
|
|
22
24
|
image?: ImageStyle;
|
|
23
25
|
}
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
export interface UserTheme {
|
|
27
|
+
colors?: Record<ColorKeysType, string>;
|
|
28
|
+
spacing?: Record<SpacingKeysType, number>;
|
|
27
29
|
}
|
|
28
30
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/theme/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/theme/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,c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6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-marked",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Markdown renderer for React Native powered by marked.js",
|
|
5
5
|
"main": "dist/commonjs/index",
|
|
6
6
|
"module": "dist/module/index",
|
|
@@ -53,34 +53,34 @@
|
|
|
53
53
|
"@evilmartians/lefthook": "1.1.3",
|
|
54
54
|
"@react-native-community/eslint-config": "3.1.0",
|
|
55
55
|
"@release-it/conventional-changelog": "5.1.1",
|
|
56
|
-
"@testing-library/jest-native": "5.1.
|
|
56
|
+
"@testing-library/jest-native": "5.1.2",
|
|
57
57
|
"@testing-library/react-native": "11.3.0",
|
|
58
58
|
"@types/jest": "29.2.0",
|
|
59
59
|
"@types/marked": "4.0.7",
|
|
60
|
-
"@types/react": "18.0.
|
|
60
|
+
"@types/react": "18.0.24",
|
|
61
61
|
"@types/react-native": "0.70.6",
|
|
62
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
63
|
-
"@typescript-eslint/parser": "5.
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "5.41.0",
|
|
63
|
+
"@typescript-eslint/parser": "5.41.0",
|
|
64
64
|
"commitlint": "17.1.2",
|
|
65
|
-
"eslint": "8.
|
|
65
|
+
"eslint": "8.26.0",
|
|
66
66
|
"eslint-config-prettier": "8.5.0",
|
|
67
67
|
"eslint-plugin-jest": "27.1.3",
|
|
68
68
|
"eslint-plugin-prettier": "4.2.1",
|
|
69
69
|
"eslint-plugin-react-native-a11y": "3.3.0",
|
|
70
|
-
"jest": "29.2.
|
|
71
|
-
"jest-environment-jsdom": "29.2.
|
|
72
|
-
"metro-react-native-babel-preset": "0.73.
|
|
70
|
+
"jest": "29.2.2",
|
|
71
|
+
"jest-environment-jsdom": "29.2.2",
|
|
72
|
+
"metro-react-native-babel-preset": "0.73.3",
|
|
73
73
|
"pod-install": "0.1.38",
|
|
74
74
|
"prettier": "2.7.1",
|
|
75
75
|
"react": "18.2.0",
|
|
76
|
-
"react-native": "0.70.
|
|
76
|
+
"react-native": "0.70.4",
|
|
77
77
|
"react-native-builder-bob": "0.20.0",
|
|
78
78
|
"react-test-renderer": "18.2.0",
|
|
79
79
|
"release-it": "15.5.0",
|
|
80
80
|
"typescript": "4.8.4"
|
|
81
81
|
},
|
|
82
82
|
"resolutions": {
|
|
83
|
-
"@types/react": "18.0.
|
|
83
|
+
"@types/react": "18.0.24"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
86
|
"react": "^16.8.6 || ^17.0.0 || ^18.0.0",
|
package/src/lib/Markdown.tsx
CHANGED
|
@@ -8,25 +8,21 @@ import type { MarkdownProps } from './types';
|
|
|
8
8
|
const Markdown = ({
|
|
9
9
|
value,
|
|
10
10
|
flatListProps,
|
|
11
|
+
theme,
|
|
12
|
+
baseUrl,
|
|
11
13
|
styles: userStyles,
|
|
12
14
|
}: MarkdownProps) => {
|
|
13
|
-
const
|
|
15
|
+
const colorScheme = useColorScheme();
|
|
14
16
|
const styles = useMemo(
|
|
15
|
-
() => getStyles(userStyles,
|
|
16
|
-
[userStyles,
|
|
17
|
+
() => getStyles(userStyles, colorScheme, theme),
|
|
18
|
+
[userStyles, colorScheme, theme]
|
|
17
19
|
);
|
|
18
20
|
|
|
19
21
|
const rnElements = useMemo(() => {
|
|
20
|
-
const parser = new Parser({
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
const tokens = marked.lexer(value, {
|
|
24
|
-
mangle: false,
|
|
25
|
-
gfm: true,
|
|
26
|
-
});
|
|
27
|
-
|
|
22
|
+
const parser = new Parser({ styles, baseUrl });
|
|
23
|
+
const tokens = marked.lexer(value, { mangle: false, gfm: true });
|
|
28
24
|
return parser.parse(tokens);
|
|
29
|
-
}, [value, styles]);
|
|
25
|
+
}, [value, styles, baseUrl]);
|
|
30
26
|
|
|
31
27
|
const renderItem = useCallback(({ item }: { item: ReactNode }) => {
|
|
32
28
|
return <>{item}</>;
|
package/src/lib/Parser.tsx
CHANGED
|
@@ -4,13 +4,16 @@ import type { marked } from 'marked';
|
|
|
4
4
|
import Renderer from './Renderer';
|
|
5
5
|
import type { MarkedStyles } from '../theme/types';
|
|
6
6
|
import type { ParserOptions } from './types';
|
|
7
|
+
import { getValidURL } from './../utils/url';
|
|
7
8
|
|
|
8
9
|
class Parser {
|
|
9
10
|
private renderer;
|
|
10
11
|
private styles: MarkedStyles;
|
|
11
12
|
private headingStylesMap: Record<number, TextStyle | undefined>;
|
|
13
|
+
private baseUrl: string;
|
|
12
14
|
constructor(options: ParserOptions) {
|
|
13
15
|
this.styles = { ...options.styles };
|
|
16
|
+
this.baseUrl = options.baseUrl ?? '';
|
|
14
17
|
this.renderer = new Renderer();
|
|
15
18
|
this.headingStylesMap = {
|
|
16
19
|
1: this.styles.h1,
|
|
@@ -115,9 +118,10 @@ class Parser {
|
|
|
115
118
|
...styles,
|
|
116
119
|
...this.styles.link, // To override color property
|
|
117
120
|
};
|
|
121
|
+
const href = getValidURL(this.baseUrl, token.href);
|
|
118
122
|
return this.renderer.getTextLinkNode(
|
|
119
123
|
this.parseInline(token.tokens, linkStyle),
|
|
120
|
-
|
|
124
|
+
href,
|
|
121
125
|
linkStyle
|
|
122
126
|
);
|
|
123
127
|
}
|
|
@@ -169,13 +173,20 @@ class Parser {
|
|
|
169
173
|
}
|
|
170
174
|
case 'text':
|
|
171
175
|
case 'html': {
|
|
176
|
+
if (token.type === 'html')
|
|
177
|
+
console.warn(
|
|
178
|
+
'react-native-marked: rendering html from markdown is not supported'
|
|
179
|
+
);
|
|
180
|
+
|
|
172
181
|
return this.renderer.getTextNode(token.raw, {
|
|
173
182
|
...this.styles.text,
|
|
174
183
|
...styles,
|
|
175
184
|
});
|
|
176
185
|
}
|
|
177
186
|
default: {
|
|
178
|
-
console.warn(
|
|
187
|
+
console.warn(
|
|
188
|
+
`react-native-marked: token with '${token.type}' type was not found.`
|
|
189
|
+
);
|
|
179
190
|
return null;
|
|
180
191
|
}
|
|
181
192
|
}
|
|
@@ -213,9 +224,10 @@ class Parser {
|
|
|
213
224
|
siblingNodes.push(this.parseInline([t]));
|
|
214
225
|
} else if (t.type === 'link') {
|
|
215
226
|
const imageToken = t.tokens[0] as marked.Tokens.Image;
|
|
227
|
+
const href = getValidURL(this.baseUrl, t.href);
|
|
216
228
|
siblingNodes.push(
|
|
217
229
|
this.renderer.getImageLinkNode(
|
|
218
|
-
|
|
230
|
+
href,
|
|
219
231
|
imageToken.href,
|
|
220
232
|
imageToken.text || imageToken.title,
|
|
221
233
|
this.styles.image
|
package/src/lib/types.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { FlatListProps } from 'react-native';
|
|
3
|
-
import type { MarkedStyles } from './../theme/types';
|
|
3
|
+
import type { MarkedStyles, UserTheme } from './../theme/types';
|
|
4
4
|
|
|
5
5
|
export interface ParserOptions {
|
|
6
6
|
styles?: MarkedStyles;
|
|
7
|
+
baseUrl?: string;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export interface MarkdownProps {
|
|
10
|
+
export interface MarkdownProps extends ParserOptions {
|
|
10
11
|
value: string;
|
|
11
12
|
flatListProps?: Omit<
|
|
12
13
|
FlatListProps<ReactNode>,
|
|
13
14
|
'data' | 'renderItem' | 'horizontal'
|
|
14
15
|
>;
|
|
15
|
-
|
|
16
|
+
theme?: UserTheme;
|
|
16
17
|
}
|
package/src/theme/colors.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
export type ColorKeysType = 'background' | 'code' | 'link' | 'text' | 'border';
|
|
2
|
+
export type ColorsPropType = Record<ColorKeysType, string>;
|
|
2
3
|
|
|
3
|
-
const colors: Record<'light' | 'dark',
|
|
4
|
+
const colors: Record<'light' | 'dark', ColorsPropType> = {
|
|
4
5
|
light: {
|
|
5
6
|
background: '#ffffff',
|
|
6
7
|
code: '#f6f8fa',
|