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
package/src/theme/styles.ts
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
import { ColorSchemeName, StyleSheet } from 'react-native';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import spacing from './spacing';
|
|
3
|
+
import colors, { type ColorsPropType } from './colors';
|
|
4
|
+
import type { MarkedStyles, UserTheme } from './types';
|
|
4
5
|
|
|
5
|
-
const getFontStyles = (
|
|
6
|
+
const getFontStyles = (mdColors: ColorsPropType) => {
|
|
6
7
|
return StyleSheet.create({
|
|
7
8
|
regular: {
|
|
8
9
|
fontSize: 16,
|
|
9
10
|
lineHeight: 24,
|
|
10
|
-
color:
|
|
11
|
+
color: mdColors.text,
|
|
11
12
|
},
|
|
12
13
|
heading: {
|
|
13
14
|
fontWeight: '500',
|
|
14
|
-
color:
|
|
15
|
+
color: mdColors.text,
|
|
15
16
|
},
|
|
16
17
|
});
|
|
17
18
|
};
|
|
18
19
|
|
|
19
20
|
const getStyles = (
|
|
20
21
|
userStyles?: MarkedStyles,
|
|
21
|
-
colorScheme?: ColorSchemeName
|
|
22
|
+
colorScheme?: ColorSchemeName,
|
|
23
|
+
userTheme?: UserTheme
|
|
22
24
|
): MarkedStyles => {
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
+
const mdColors = { ...colors[colorScheme || 'light'], ...userTheme?.colors };
|
|
26
|
+
const mdSpacing = { ...spacing, ...userTheme?.spacing };
|
|
27
|
+
|
|
28
|
+
const fontStyle = getFontStyles(mdColors);
|
|
25
29
|
const defaultStyles = StyleSheet.create<MarkedStyles>({
|
|
26
30
|
container: {
|
|
27
|
-
backgroundColor:
|
|
31
|
+
backgroundColor: mdColors.background,
|
|
28
32
|
},
|
|
29
33
|
em: {
|
|
30
34
|
...fontStyle.regular,
|
|
@@ -44,76 +48,76 @@ const getStyles = (
|
|
|
44
48
|
},
|
|
45
49
|
paragraph: {
|
|
46
50
|
...fontStyle.regular,
|
|
47
|
-
paddingVertical:
|
|
51
|
+
paddingVertical: mdSpacing.m,
|
|
48
52
|
},
|
|
49
53
|
link: {
|
|
50
54
|
...fontStyle.regular,
|
|
51
55
|
fontStyle: 'italic',
|
|
52
|
-
color:
|
|
56
|
+
color: mdColors.link,
|
|
53
57
|
},
|
|
54
58
|
blockquote: {
|
|
55
|
-
borderLeftColor:
|
|
56
|
-
paddingLeft:
|
|
57
|
-
borderLeftWidth:
|
|
59
|
+
borderLeftColor: mdColors.border,
|
|
60
|
+
paddingLeft: mdSpacing.l,
|
|
61
|
+
borderLeftWidth: mdSpacing.s,
|
|
58
62
|
opacity: 0.8,
|
|
59
63
|
},
|
|
60
64
|
h1: {
|
|
61
65
|
fontSize: 32,
|
|
62
66
|
lineHeight: 40,
|
|
63
67
|
fontWeight: 'bold',
|
|
64
|
-
marginVertical:
|
|
68
|
+
marginVertical: mdSpacing.m,
|
|
65
69
|
letterSpacing: 0,
|
|
66
|
-
paddingBottom:
|
|
67
|
-
borderBottomColor:
|
|
70
|
+
paddingBottom: mdSpacing.s,
|
|
71
|
+
borderBottomColor: mdColors.border,
|
|
68
72
|
borderBottomWidth: 1,
|
|
69
73
|
},
|
|
70
74
|
h2: {
|
|
71
75
|
...fontStyle.heading,
|
|
72
76
|
fontSize: 28,
|
|
73
77
|
lineHeight: 36,
|
|
74
|
-
marginVertical:
|
|
75
|
-
paddingBottom:
|
|
76
|
-
borderBottomColor:
|
|
78
|
+
marginVertical: mdSpacing.m,
|
|
79
|
+
paddingBottom: mdSpacing.s,
|
|
80
|
+
borderBottomColor: mdColors.border,
|
|
77
81
|
borderBottomWidth: 1,
|
|
78
82
|
},
|
|
79
83
|
h3: {
|
|
80
84
|
...fontStyle.heading,
|
|
81
85
|
fontSize: 24,
|
|
82
86
|
lineHeight: 32,
|
|
83
|
-
marginVertical:
|
|
87
|
+
marginVertical: mdSpacing.s,
|
|
84
88
|
},
|
|
85
89
|
h4: {
|
|
86
90
|
...fontStyle.heading,
|
|
87
91
|
fontSize: 22,
|
|
88
92
|
lineHeight: 28,
|
|
89
|
-
marginVertical:
|
|
93
|
+
marginVertical: mdSpacing.s,
|
|
90
94
|
},
|
|
91
95
|
h5: {
|
|
92
96
|
...fontStyle.regular,
|
|
93
97
|
...fontStyle.heading,
|
|
94
|
-
marginVertical:
|
|
98
|
+
marginVertical: mdSpacing.xs,
|
|
95
99
|
},
|
|
96
100
|
h6: {
|
|
97
101
|
...fontStyle.heading,
|
|
98
102
|
fontSize: 14,
|
|
99
103
|
lineHeight: 20,
|
|
100
|
-
marginVertical:
|
|
104
|
+
marginVertical: mdSpacing.xs,
|
|
101
105
|
},
|
|
102
106
|
codespan: {
|
|
103
107
|
...fontStyle.regular,
|
|
104
108
|
fontStyle: 'italic',
|
|
105
|
-
backgroundColor:
|
|
109
|
+
backgroundColor: mdColors.code,
|
|
106
110
|
fontWeight: '300',
|
|
107
111
|
},
|
|
108
112
|
code: {
|
|
109
|
-
padding:
|
|
110
|
-
backgroundColor:
|
|
113
|
+
padding: mdSpacing.l,
|
|
114
|
+
backgroundColor: mdColors.code,
|
|
111
115
|
minWidth: '100%',
|
|
112
116
|
},
|
|
113
117
|
hr: {
|
|
114
118
|
borderBottomWidth: 1,
|
|
115
|
-
borderBottomColor:
|
|
116
|
-
marginVertical:
|
|
119
|
+
borderBottomColor: mdColors.border,
|
|
120
|
+
marginVertical: mdSpacing.s,
|
|
117
121
|
},
|
|
118
122
|
li: {
|
|
119
123
|
...fontStyle.regular,
|
package/src/theme/types.ts
CHANGED
|
@@ -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
|
|
|
3
5
|
export interface MarkedStyles {
|
|
4
6
|
container?: ViewStyle;
|
|
@@ -23,8 +25,7 @@ export interface MarkedStyles {
|
|
|
23
25
|
image?: ImageStyle;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
export
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
colors: Record<ColorKeys, string>;
|
|
28
|
+
export interface UserTheme {
|
|
29
|
+
colors?: Record<ColorKeysType, string>;
|
|
30
|
+
spacing?: Record<SpacingKeysType, number>;
|
|
30
31
|
}
|
package/src/utils/url.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const getValidURL = (prefix: string, path: string) => {
|
|
2
|
+
// remove trailing slash from prefix
|
|
3
|
+
if (prefix.endsWith('/')) {
|
|
4
|
+
prefix = prefix.slice(0, -1);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// path is valid url
|
|
8
|
+
if (path.startsWith('https') || path.startsWith('http')) {
|
|
9
|
+
return path;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// absolute path
|
|
13
|
+
if (path.startsWith('/')) {
|
|
14
|
+
return `${prefix}${path}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// relative path
|
|
18
|
+
return `${prefix}/${path}`;
|
|
19
|
+
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getTheme = void 0;
|
|
7
|
-
|
|
8
|
-
var _colors = _interopRequireDefault(require("./colors"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
const getTheme = theme => {
|
|
13
|
-
return {
|
|
14
|
-
colors: _colors.default[theme || 'light']
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
exports.getTheme = getTheme;
|
|
19
|
-
//# sourceMappingURL=theme.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["getTheme","theme","colors"],"sourceRoot":"../../src","sources":["theme.ts"],"mappings":";;;;;;;AACA;;;;AAGO,MAAMA,QAAQ,GAAIC,KAAD,IAAmC;EACzD,OAAO;IACLC,MAAM,EAAEA,eAAA,CAAOD,KAAK,IAAI,OAAhB;EADH,CAAP;AAGD,CAJM"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["colors","getTheme","theme"],"sourceRoot":"../../src","sources":["theme.ts"],"mappings":"AACA,OAAOA,MAAP,MAAmB,UAAnB;AAGA,OAAO,MAAMC,QAAQ,GAAIC,KAAD,IAAmC;EACzD,OAAO;IACLF,MAAM,EAAEA,MAAM,CAACE,KAAK,IAAI,OAAV;EADT,CAAP;AAGD,CAJM"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../src/theme/theme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,eAAO,MAAM,QAAQ,UAAW,eAAe,KAAG,KAIjD,CAAC"}
|
package/src/theme/theme.ts
DELETED