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.
Files changed (55) hide show
  1. package/README.md +33 -11
  2. package/dist/commonjs/lib/Markdown.js +7 -4
  3. package/dist/commonjs/lib/Markdown.js.map +1 -1
  4. package/dist/commonjs/lib/Parser.js +11 -3
  5. package/dist/commonjs/lib/Parser.js.map +1 -1
  6. package/dist/commonjs/theme/colors.js.map +1 -1
  7. package/dist/commonjs/theme/spacing.js +15 -0
  8. package/dist/commonjs/theme/spacing.js.map +1 -0
  9. package/dist/commonjs/theme/styles.js +37 -28
  10. package/dist/commonjs/theme/styles.js.map +1 -1
  11. package/dist/commonjs/utils/url.js +29 -0
  12. package/dist/commonjs/utils/url.js.map +1 -0
  13. package/dist/module/lib/Markdown.js +7 -4
  14. package/dist/module/lib/Markdown.js.map +1 -1
  15. package/dist/module/lib/Parser.js +10 -3
  16. package/dist/module/lib/Parser.js.map +1 -1
  17. package/dist/module/theme/colors.js.map +1 -1
  18. package/dist/module/theme/spacing.js +8 -0
  19. package/dist/module/theme/spacing.js.map +1 -0
  20. package/dist/module/theme/styles.js +34 -28
  21. package/dist/module/theme/styles.js.map +1 -1
  22. package/dist/module/utils/url.js +20 -0
  23. package/dist/module/utils/url.js.map +1 -0
  24. package/dist/typescript/lib/Markdown.d.ts +1 -1
  25. package/dist/typescript/lib/Markdown.d.ts.map +1 -1
  26. package/dist/typescript/lib/Parser.d.ts +1 -0
  27. package/dist/typescript/lib/Parser.d.ts.map +1 -1
  28. package/dist/typescript/lib/types.d.ts +4 -3
  29. package/dist/typescript/lib/types.d.ts.map +1 -1
  30. package/dist/typescript/theme/colors.d.ts +3 -2
  31. package/dist/typescript/theme/colors.d.ts.map +1 -1
  32. package/dist/typescript/theme/spacing.d.ts +4 -0
  33. package/dist/typescript/theme/spacing.d.ts.map +1 -0
  34. package/dist/typescript/theme/styles.d.ts +2 -2
  35. package/dist/typescript/theme/styles.d.ts.map +1 -1
  36. package/dist/typescript/theme/types.d.ts +5 -3
  37. package/dist/typescript/theme/types.d.ts.map +1 -1
  38. package/dist/typescript/utils/url.d.ts +2 -0
  39. package/dist/typescript/utils/url.d.ts.map +1 -0
  40. package/package.json +11 -11
  41. package/src/lib/Markdown.tsx +8 -12
  42. package/src/lib/Parser.tsx +15 -3
  43. package/src/lib/types.ts +4 -3
  44. package/src/theme/colors.ts +3 -2
  45. package/src/theme/spacing.ts +10 -0
  46. package/src/theme/styles.ts +33 -29
  47. package/src/theme/types.ts +5 -4
  48. package/src/utils/url.ts +19 -0
  49. package/dist/commonjs/theme/theme.js +0 -19
  50. package/dist/commonjs/theme/theme.js.map +0 -1
  51. package/dist/module/theme/theme.js +0 -7
  52. package/dist/module/theme/theme.js.map +0 -1
  53. package/dist/typescript/theme/theme.d.ts +0 -4
  54. package/dist/typescript/theme/theme.d.ts.map +0 -1
  55. package/src/theme/theme.ts +0 -9
@@ -1,30 +1,34 @@
1
1
  import { ColorSchemeName, StyleSheet } from 'react-native';
2
- import { getTheme } from './theme';
3
- import type { MarkedStyles, Theme } from './types';
2
+ import spacing from './spacing';
3
+ import colors, { type ColorsPropType } from './colors';
4
+ import type { MarkedStyles, UserTheme } from './types';
4
5
 
5
- const getFontStyles = (theme: Theme) => {
6
+ const getFontStyles = (mdColors: ColorsPropType) => {
6
7
  return StyleSheet.create({
7
8
  regular: {
8
9
  fontSize: 16,
9
10
  lineHeight: 24,
10
- color: theme.colors.text,
11
+ color: mdColors.text,
11
12
  },
12
13
  heading: {
13
14
  fontWeight: '500',
14
- color: theme.colors.text,
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 theme = getTheme(colorScheme || 'light');
24
- const fontStyle = getFontStyles(theme);
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: theme.colors.background,
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: 8,
51
+ paddingVertical: mdSpacing.m,
48
52
  },
49
53
  link: {
50
54
  ...fontStyle.regular,
51
55
  fontStyle: 'italic',
52
- color: theme.colors.link,
56
+ color: mdColors.link,
53
57
  },
54
58
  blockquote: {
55
- borderLeftColor: theme.colors.border,
56
- paddingLeft: 16,
57
- borderLeftWidth: 5,
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: 8,
68
+ marginVertical: mdSpacing.m,
65
69
  letterSpacing: 0,
66
- paddingBottom: 4,
67
- borderBottomColor: theme.colors.border,
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: 8,
75
- paddingBottom: 4,
76
- borderBottomColor: theme.colors.border,
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: 4,
87
+ marginVertical: mdSpacing.s,
84
88
  },
85
89
  h4: {
86
90
  ...fontStyle.heading,
87
91
  fontSize: 22,
88
92
  lineHeight: 28,
89
- marginVertical: 4,
93
+ marginVertical: mdSpacing.s,
90
94
  },
91
95
  h5: {
92
96
  ...fontStyle.regular,
93
97
  ...fontStyle.heading,
94
- marginVertical: 2,
98
+ marginVertical: mdSpacing.xs,
95
99
  },
96
100
  h6: {
97
101
  ...fontStyle.heading,
98
102
  fontSize: 14,
99
103
  lineHeight: 20,
100
- marginVertical: 2,
104
+ marginVertical: mdSpacing.xs,
101
105
  },
102
106
  codespan: {
103
107
  ...fontStyle.regular,
104
108
  fontStyle: 'italic',
105
- backgroundColor: theme.colors.code,
109
+ backgroundColor: mdColors.code,
106
110
  fontWeight: '300',
107
111
  },
108
112
  code: {
109
- padding: 16,
110
- backgroundColor: theme.colors.code,
113
+ padding: mdSpacing.l,
114
+ backgroundColor: mdColors.code,
111
115
  minWidth: '100%',
112
116
  },
113
117
  hr: {
114
118
  borderBottomWidth: 1,
115
- borderBottomColor: theme.colors.border,
116
- marginVertical: 4,
119
+ borderBottomColor: mdColors.border,
120
+ marginVertical: mdSpacing.s,
117
121
  },
118
122
  li: {
119
123
  ...fontStyle.regular,
@@ -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 type ColorKeys = 'background' | 'code' | 'link' | 'text' | 'border';
27
-
28
- export interface Theme {
29
- colors: Record<ColorKeys, string>;
28
+ export interface UserTheme {
29
+ colors?: Record<ColorKeysType, string>;
30
+ spacing?: Record<SpacingKeysType, number>;
30
31
  }
@@ -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,7 +0,0 @@
1
- import colors from './colors';
2
- export const getTheme = theme => {
3
- return {
4
- colors: colors[theme || 'light']
5
- };
6
- };
7
- //# sourceMappingURL=theme.js.map
@@ -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,4 +0,0 @@
1
- import type { ColorSchemeName } from 'react-native';
2
- import type { Theme } from './types';
3
- export declare const getTheme: (theme: ColorSchemeName) => Theme;
4
- //# sourceMappingURL=theme.d.ts.map
@@ -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"}
@@ -1,9 +0,0 @@
1
- import type { ColorSchemeName } from 'react-native';
2
- import colors from './colors';
3
- import type { Theme } from './types';
4
-
5
- export const getTheme = (theme: ColorSchemeName): Theme => {
6
- return {
7
- colors: colors[theme || 'light'],
8
- };
9
- };