react-native-marked 1.0.0-alpha.3 → 1.0.2

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 +7 -5
  2. package/dist/commonjs/components/MDImage.js +5 -22
  3. package/dist/commonjs/components/MDImage.js.map +1 -1
  4. package/dist/commonjs/lib/Markdown.js +19 -11
  5. package/dist/commonjs/lib/Markdown.js.map +1 -1
  6. package/dist/commonjs/lib/Parser.js +49 -130
  7. package/dist/commonjs/lib/Parser.js.map +1 -1
  8. package/dist/commonjs/lib/Renderer.js +19 -13
  9. package/dist/commonjs/lib/Renderer.js.map +1 -1
  10. package/dist/commonjs/theme/colors.js +25 -0
  11. package/dist/commonjs/theme/colors.js.map +1 -0
  12. package/dist/commonjs/theme/styles.js +113 -0
  13. package/dist/commonjs/theme/styles.js.map +1 -0
  14. package/dist/commonjs/theme/theme.js +19 -0
  15. package/dist/commonjs/theme/theme.js.map +1 -0
  16. package/dist/commonjs/{types → theme}/types.js +0 -0
  17. package/dist/commonjs/theme/types.js.map +1 -0
  18. package/dist/module/components/MDImage.js +6 -22
  19. package/dist/module/components/MDImage.js.map +1 -1
  20. package/dist/module/lib/Markdown.js +18 -12
  21. package/dist/module/lib/Markdown.js.map +1 -1
  22. package/dist/module/lib/Parser.js +50 -129
  23. package/dist/module/lib/Parser.js.map +1 -1
  24. package/dist/module/lib/Renderer.js +16 -13
  25. package/dist/module/lib/Renderer.js.map +1 -1
  26. package/dist/module/theme/colors.js +18 -0
  27. package/dist/module/theme/colors.js.map +1 -0
  28. package/dist/module/theme/styles.js +102 -0
  29. package/dist/module/theme/styles.js.map +1 -0
  30. package/dist/module/theme/theme.js +7 -0
  31. package/dist/module/theme/theme.js.map +1 -0
  32. package/dist/module/{types → theme}/types.js +0 -0
  33. package/dist/module/theme/types.js.map +1 -0
  34. package/dist/typescript/components/MDImage.d.ts +1 -2
  35. package/dist/typescript/lib/Markdown.d.ts +6 -5
  36. package/dist/typescript/lib/Parser.d.ts +7 -5
  37. package/dist/typescript/lib/Renderer.d.ts +6 -6
  38. package/dist/typescript/theme/colors.d.ts +3 -0
  39. package/dist/typescript/theme/styles.d.ts +4 -0
  40. package/dist/typescript/theme/theme.d.ts +3 -0
  41. package/dist/typescript/theme/types.d.ts +25 -0
  42. package/package.json +15 -9
  43. package/src/components/MDImage.tsx +5 -28
  44. package/src/lib/Markdown.tsx +28 -10
  45. package/src/lib/Parser.tsx +177 -0
  46. package/src/lib/Renderer.tsx +28 -13
  47. package/src/theme/colors.ts +20 -0
  48. package/src/theme/styles.ts +117 -0
  49. package/src/theme/theme.ts +9 -0
  50. package/src/theme/types.ts +28 -0
  51. package/dist/commonjs/types/types.js.map +0 -1
  52. package/dist/module/types/types.js.map +0 -1
  53. package/dist/typescript/types/types.d.ts +0 -23
  54. package/src/lib/Parser.ts +0 -256
  55. package/src/types/types.ts +0 -25
@@ -3,6 +3,9 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
3
3
  import * as React from 'react';
4
4
  import { Linking, ScrollView, View } from 'react-native';
5
5
  import { Text } from 'react-native';
6
+ import MarkedList from '@jsamr/react-native-li';
7
+ import Disc from '@jsamr/counter-style/presets/disc';
8
+ import Decimal from '@jsamr/counter-style/presets/decimal';
6
9
  import MDImage from './../components/MDImage';
7
10
  import { generateRandomString } from '../utils/string';
8
11
 
@@ -26,14 +29,14 @@ class Renderer {
26
29
  });
27
30
  }
28
31
 
29
- getParagraph(children, styles) {
32
+ getViewNode(children, styles) {
30
33
  return /*#__PURE__*/React.createElement(View, {
31
34
  key: generateRandomString(),
32
35
  style: styles
33
36
  }, children);
34
37
  }
35
38
 
36
- getCodeBlock(text, containerStyle, textStyle) {
39
+ getCodeBlockNode(text, containerStyle, textStyle) {
37
40
  return /*#__PURE__*/React.createElement(ScrollView, {
38
41
  contentContainerStyle: containerStyle,
39
42
  horizontal: true
@@ -42,28 +45,28 @@ class Renderer {
42
45
  }, text));
43
46
  }
44
47
 
45
- getBlockquote(children, styles) {
48
+ getBlockquoteNode(children, styles) {
46
49
  return /*#__PURE__*/React.createElement(View, {
47
50
  key: generateRandomString(),
48
51
  style: styles
49
52
  }, children);
50
53
  }
51
54
 
52
- getHeading(text, styles) {
53
- return /*#__PURE__*/React.createElement(Text, {
54
- key: generateRandomString(),
55
- style: styles
56
- }, text);
57
- }
58
-
59
- getImage(uri, width) {
55
+ getImageNode(uri) {
60
56
  return /*#__PURE__*/React.createElement(MDImage, {
61
57
  key: generateRandomString(),
62
- uri: uri,
63
- width: width
58
+ uri: uri
64
59
  });
65
60
  }
66
61
 
62
+ getListNode(ordered, li, listStyle, textStyle) {
63
+ return /*#__PURE__*/React.createElement(MarkedList, {
64
+ counterRenderer: ordered ? Decimal : Disc,
65
+ markerTextStyle: textStyle,
66
+ markerBoxStyle: listStyle
67
+ }, li.map(node => node));
68
+ }
69
+
67
70
  }
68
71
 
69
72
  export default Renderer;
@@ -1 +1 @@
1
- {"version":3,"names":["React","Linking","ScrollView","View","Text","MDImage","generateRandomString","Renderer","href","openURL","children","styles","text","onLinkPress","getParagraph","getCodeBlock","containerStyle","textStyle","getBlockquote","getHeading","getImage","uri","width"],"sources":["Renderer.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Linking, ScrollView, View, ViewStyle } from 'react-native';\nimport type { StyleProp, TextStyle } from 'react-native';\nimport { Text } from 'react-native';\nimport MDImage from './../components/MDImage';\nimport { generateRandomString } from '../utils/string';\n\nclass Renderer {\n private onLinkPress = (href: string) => () => Linking.openURL(href);\n\n getTextNode = (\n children: string | React.ReactNode[],\n styles: StyleProp<TextStyle>\n ) => {\n return (\n <Text key={generateRandomString()} style={styles}>\n {children}\n </Text>\n );\n };\n\n getLinkNode = (text: string, href: string, styles: StyleProp<TextStyle>) => {\n return (\n <Text\n key={generateRandomString()}\n onPress={this.onLinkPress(href)}\n style={styles}\n >\n {text}\n </Text>\n );\n };\n\n getParagraph(children: React.ReactNode[], styles: StyleProp<ViewStyle>) {\n return (\n <View key={generateRandomString()} style={styles}>\n {children}\n </View>\n );\n }\n\n getCodeBlock(\n text: string,\n containerStyle: StyleProp<ViewStyle>,\n textStyle: StyleProp<TextStyle>\n ) {\n return (\n <ScrollView contentContainerStyle={containerStyle} horizontal>\n <Text style={textStyle}>{text}</Text>\n </ScrollView>\n );\n }\n\n getBlockquote(children: React.ReactNode[], styles: StyleProp<ViewStyle>) {\n return (\n <View key={generateRandomString()} style={styles}>\n {children}\n </View>\n );\n }\n\n getHeading(text: string, styles: StyleProp<TextStyle>) {\n return (\n <Text key={generateRandomString()} style={styles}>\n {text}\n </Text>\n );\n }\n\n getImage(uri: string, width: number) {\n return <MDImage key={generateRandomString()} uri={uri} width={width} />;\n }\n}\n\nexport default Renderer;\n"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,OAAT,EAAkBC,UAAlB,EAA8BC,IAA9B,QAAqD,cAArD;AAEA,SAASC,IAAT,QAAqB,cAArB;AACA,OAAOC,OAAP,MAAoB,yBAApB;AACA,SAASC,oBAAT,QAAqC,iBAArC;;AAEA,MAAMC,QAAN,CAAe;EAAA;IAAA,qCACUC,IAAD,IAAkB,MAAMP,OAAO,CAACQ,OAAR,CAAgBD,IAAhB,CADjC;;IAAA,qCAGC,CACZE,QADY,EAEZC,MAFY,KAGT;MACH,oBACE,oBAAC,IAAD;QAAM,GAAG,EAAEL,oBAAoB,EAA/B;QAAmC,KAAK,EAAEK;MAA1C,GACGD,QADH,CADF;IAKD,CAZY;;IAAA,qCAcC,CAACE,IAAD,EAAeJ,IAAf,EAA6BG,MAA7B,KAA8D;MAC1E,oBACE,oBAAC,IAAD;QACE,GAAG,EAAEL,oBAAoB,EAD3B;QAEE,OAAO,EAAE,KAAKO,WAAL,CAAiBL,IAAjB,CAFX;QAGE,KAAK,EAAEG;MAHT,GAKGC,IALH,CADF;IASD,CAxBY;EAAA;;EA0BbE,YAAY,CAACJ,QAAD,EAA8BC,MAA9B,EAA4D;IACtE,oBACE,oBAAC,IAAD;MAAM,GAAG,EAAEL,oBAAoB,EAA/B;MAAmC,KAAK,EAAEK;IAA1C,GACGD,QADH,CADF;EAKD;;EAEDK,YAAY,CACVH,IADU,EAEVI,cAFU,EAGVC,SAHU,EAIV;IACA,oBACE,oBAAC,UAAD;MAAY,qBAAqB,EAAED,cAAnC;MAAmD,UAAU;IAA7D,gBACE,oBAAC,IAAD;MAAM,KAAK,EAAEC;IAAb,GAAyBL,IAAzB,CADF,CADF;EAKD;;EAEDM,aAAa,CAACR,QAAD,EAA8BC,MAA9B,EAA4D;IACvE,oBACE,oBAAC,IAAD;MAAM,GAAG,EAAEL,oBAAoB,EAA/B;MAAmC,KAAK,EAAEK;IAA1C,GACGD,QADH,CADF;EAKD;;EAEDS,UAAU,CAACP,IAAD,EAAeD,MAAf,EAA6C;IACrD,oBACE,oBAAC,IAAD;MAAM,GAAG,EAAEL,oBAAoB,EAA/B;MAAmC,KAAK,EAAEK;IAA1C,GACGC,IADH,CADF;EAKD;;EAEDQ,QAAQ,CAACC,GAAD,EAAcC,KAAd,EAA6B;IACnC,oBAAO,oBAAC,OAAD;MAAS,GAAG,EAAEhB,oBAAoB,EAAlC;MAAsC,GAAG,EAAEe,GAA3C;MAAgD,KAAK,EAAEC;IAAvD,EAAP;EACD;;AAhEY;;AAmEf,eAAef,QAAf"}
1
+ {"version":3,"names":["React","Linking","ScrollView","View","Text","MarkedList","Disc","Decimal","MDImage","generateRandomString","Renderer","href","openURL","children","styles","text","onLinkPress","getViewNode","getCodeBlockNode","containerStyle","textStyle","getBlockquoteNode","getImageNode","uri","getListNode","ordered","li","listStyle","map","node"],"sources":["Renderer.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Linking, ScrollView, View, ViewStyle } from 'react-native';\nimport { Text, StyleProp, TextStyle } from 'react-native';\nimport MarkedList from '@jsamr/react-native-li';\nimport Disc from '@jsamr/counter-style/presets/disc';\nimport Decimal from '@jsamr/counter-style/presets/decimal';\nimport MDImage from './../components/MDImage';\n\nimport { generateRandomString } from '../utils/string';\n\nclass Renderer {\n private onLinkPress = (href: string) => () => Linking.openURL(href);\n\n getTextNode = (\n children: string | React.ReactNode[],\n styles: StyleProp<TextStyle>\n ) => {\n return (\n <Text key={generateRandomString()} style={styles}>\n {children}\n </Text>\n );\n };\n\n getLinkNode = (text: string, href: string, styles: StyleProp<TextStyle>) => {\n return (\n <Text\n key={generateRandomString()}\n onPress={this.onLinkPress(href)}\n style={styles}\n >\n {text}\n </Text>\n );\n };\n\n getViewNode(\n children: React.ReactNode[] | null,\n styles: StyleProp<ViewStyle>\n ) {\n return (\n <View key={generateRandomString()} style={styles}>\n {children}\n </View>\n );\n }\n\n getCodeBlockNode(\n text: string,\n containerStyle: StyleProp<ViewStyle>,\n textStyle: StyleProp<TextStyle>\n ) {\n return (\n <ScrollView contentContainerStyle={containerStyle} horizontal>\n <Text style={textStyle}>{text}</Text>\n </ScrollView>\n );\n }\n\n getBlockquoteNode(children: React.ReactNode[], styles: StyleProp<ViewStyle>) {\n return (\n <View key={generateRandomString()} style={styles}>\n {children}\n </View>\n );\n }\n\n getImageNode(uri: string) {\n return <MDImage key={generateRandomString()} uri={uri} />;\n }\n\n getListNode(\n ordered: boolean,\n li: React.ReactNode[],\n listStyle: ViewStyle | undefined,\n textStyle: TextStyle | undefined\n ) {\n return (\n <MarkedList\n counterRenderer={ordered ? Decimal : Disc}\n markerTextStyle={textStyle}\n markerBoxStyle={listStyle}\n >\n {li.map((node) => node)}\n </MarkedList>\n );\n }\n}\n\nexport default Renderer;\n"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,OAAT,EAAkBC,UAAlB,EAA8BC,IAA9B,QAAqD,cAArD;AACA,SAASC,IAAT,QAA2C,cAA3C;AACA,OAAOC,UAAP,MAAuB,wBAAvB;AACA,OAAOC,IAAP,MAAiB,mCAAjB;AACA,OAAOC,OAAP,MAAoB,sCAApB;AACA,OAAOC,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OADS,EAETC,EAFS,EAGTC,SAHS,EAITP,SAJS,EAKT;IACA,oBACE,oBAAC,UAAD;MACE,eAAe,EAAEK,OAAO,GAAGlB,OAAH,GAAaD,IADvC;MAEE,eAAe,EAAEc,SAFnB;MAGE,cAAc,EAAEO;IAHlB,GAKGD,EAAE,CAACE,GAAH,CAAQC,IAAD,IAAUA,IAAjB,CALH,CADF;EASD;;AA5EY;;AA+Ef,eAAenB,QAAf"}
@@ -0,0 +1,18 @@
1
+ const colors = {
2
+ light: {
3
+ background: '#ffffff',
4
+ code: '#f6f8fa',
5
+ link: '#58a6ff',
6
+ text: '#333333',
7
+ border: '#d0d7de'
8
+ },
9
+ dark: {
10
+ background: '#000000',
11
+ code: '#161b22',
12
+ link: '#58a6ff',
13
+ text: '#ffffff',
14
+ border: '#30363d'
15
+ }
16
+ };
17
+ export default colors;
18
+ //# sourceMappingURL=colors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["colors","light","background","code","link","text","border","dark"],"sources":["colors.ts"],"sourcesContent":["import type { ColorKeys } from './types';\n\nconst colors: Record<'light' | 'dark', Record<ColorKeys, string>> = {\n light: {\n background: '#ffffff',\n code: '#f6f8fa',\n link: '#58a6ff',\n text: '#333333',\n border: '#d0d7de',\n },\n dark: {\n background: '#000000',\n code: '#161b22',\n link: '#58a6ff',\n text: '#ffffff',\n border: '#30363d',\n },\n};\n\nexport default colors;\n"],"mappings":"AAEA,MAAMA,MAA2D,GAAG;EAClEC,KAAK,EAAE;IACLC,UAAU,EAAE,SADP;IAELC,IAAI,EAAE,SAFD;IAGLC,IAAI,EAAE,SAHD;IAILC,IAAI,EAAE,SAJD;IAKLC,MAAM,EAAE;EALH,CAD2D;EAQlEC,IAAI,EAAE;IACJL,UAAU,EAAE,SADR;IAEJC,IAAI,EAAE,SAFF;IAGJC,IAAI,EAAE,SAHF;IAIJC,IAAI,EAAE,SAJF;IAKJC,MAAM,EAAE;EALJ;AAR4D,CAApE;AAiBA,eAAeN,MAAf"}
@@ -0,0 +1,102 @@
1
+ import { StyleSheet } from 'react-native';
2
+ import { getTheme } from './theme';
3
+
4
+ const getFontStyles = theme => {
5
+ return StyleSheet.create({
6
+ regular: {
7
+ fontSize: 16,
8
+ lineHeight: 24,
9
+ color: theme.colors.text
10
+ },
11
+ heading: {
12
+ fontWeight: '500',
13
+ color: theme.colors.text
14
+ }
15
+ });
16
+ };
17
+
18
+ const getStyles = (userStyles, colorScheme) => {
19
+ const theme = getTheme(colorScheme || 'light');
20
+ const fontStyle = getFontStyles(theme);
21
+ const defaultStyles = StyleSheet.create({
22
+ container: {
23
+ backgroundColor: theme.colors.background
24
+ },
25
+ em: { ...fontStyle.regular,
26
+ fontStyle: 'italic'
27
+ },
28
+ strong: { ...fontStyle.regular,
29
+ fontWeight: 'bold'
30
+ },
31
+ text: { ...fontStyle.regular
32
+ },
33
+ paragraph: { ...fontStyle.regular,
34
+ paddingVertical: 8
35
+ },
36
+ link: { ...fontStyle.regular,
37
+ fontStyle: 'italic',
38
+ color: theme.colors.link
39
+ },
40
+ blockquote: {
41
+ borderLeftColor: theme.colors.border,
42
+ paddingLeft: 16,
43
+ borderLeftWidth: 5,
44
+ opacity: 0.8
45
+ },
46
+ h1: {
47
+ fontSize: 32,
48
+ lineHeight: 40,
49
+ fontWeight: 'bold',
50
+ marginVertical: 8,
51
+ letterSpacing: 0
52
+ },
53
+ h2: { ...fontStyle.heading,
54
+ fontSize: 28,
55
+ lineHeight: 36,
56
+ marginVertical: 8
57
+ },
58
+ h3: { ...fontStyle.heading,
59
+ fontSize: 24,
60
+ lineHeight: 32,
61
+ marginVertical: 4
62
+ },
63
+ h4: { ...fontStyle.heading,
64
+ fontSize: 22,
65
+ lineHeight: 28,
66
+ marginVertical: 4
67
+ },
68
+ h5: { ...fontStyle.regular,
69
+ ...fontStyle.heading,
70
+ marginVertical: 2
71
+ },
72
+ h6: { ...fontStyle.heading,
73
+ fontSize: 14,
74
+ lineHeight: 20,
75
+ marginVertical: 2
76
+ },
77
+ codespan: { ...fontStyle.regular,
78
+ fontStyle: 'italic',
79
+ backgroundColor: theme.colors.code,
80
+ fontWeight: '300'
81
+ },
82
+ code: {
83
+ padding: 16,
84
+ backgroundColor: theme.colors.code,
85
+ minWidth: '100%'
86
+ },
87
+ hr: {
88
+ borderBottomWidth: 1,
89
+ borderBottomColor: theme.colors.border,
90
+ marginVertical: 4
91
+ },
92
+ li: { ...fontStyle.regular,
93
+ flexShrink: 1
94
+ }
95
+ });
96
+ return { ...defaultStyles,
97
+ ...userStyles
98
+ };
99
+ };
100
+
101
+ export default getStyles;
102
+ //# sourceMappingURL=styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["StyleSheet","getTheme","getFontStyles","theme","create","regular","fontSize","lineHeight","color","colors","text","heading","fontWeight","getStyles","userStyles","colorScheme","fontStyle","defaultStyles","container","backgroundColor","background","em","strong","paragraph","paddingVertical","link","blockquote","borderLeftColor","border","paddingLeft","borderLeftWidth","opacity","h1","marginVertical","letterSpacing","h2","h3","h4","h5","h6","codespan","code","padding","minWidth","hr","borderBottomWidth","borderBottomColor","li","flexShrink"],"sources":["styles.ts"],"sourcesContent":["import { ColorSchemeName, StyleSheet } from 'react-native';\nimport { getTheme } from './theme';\nimport type { MarkedStyles, Theme } from './types';\n\nconst getFontStyles = (theme: Theme) => {\n return StyleSheet.create({\n regular: {\n fontSize: 16,\n lineHeight: 24,\n color: theme.colors.text,\n },\n heading: {\n fontWeight: '500',\n color: theme.colors.text,\n },\n });\n};\n\nconst getStyles = (\n userStyles?: MarkedStyles,\n colorScheme?: ColorSchemeName\n): MarkedStyles => {\n const theme = getTheme(colorScheme || 'light');\n const fontStyle = getFontStyles(theme);\n const defaultStyles = StyleSheet.create<MarkedStyles>({\n container: {\n backgroundColor: theme.colors.background,\n },\n em: {\n ...fontStyle.regular,\n fontStyle: 'italic',\n },\n strong: {\n ...fontStyle.regular,\n fontWeight: 'bold',\n },\n text: { ...fontStyle.regular },\n paragraph: {\n ...fontStyle.regular,\n paddingVertical: 8,\n },\n link: {\n ...fontStyle.regular,\n fontStyle: 'italic',\n color: theme.colors.link,\n },\n blockquote: {\n borderLeftColor: theme.colors.border,\n paddingLeft: 16,\n borderLeftWidth: 5,\n opacity: 0.8,\n },\n h1: {\n fontSize: 32,\n lineHeight: 40,\n fontWeight: 'bold',\n marginVertical: 8,\n letterSpacing: 0,\n },\n h2: {\n ...fontStyle.heading,\n fontSize: 28,\n lineHeight: 36,\n marginVertical: 8,\n },\n h3: {\n ...fontStyle.heading,\n fontSize: 24,\n lineHeight: 32,\n marginVertical: 4,\n },\n h4: {\n ...fontStyle.heading,\n fontSize: 22,\n lineHeight: 28,\n marginVertical: 4,\n },\n h5: {\n ...fontStyle.regular,\n ...fontStyle.heading,\n marginVertical: 2,\n },\n h6: {\n ...fontStyle.heading,\n fontSize: 14,\n lineHeight: 20,\n marginVertical: 2,\n },\n codespan: {\n ...fontStyle.regular,\n fontStyle: 'italic',\n backgroundColor: theme.colors.code,\n fontWeight: '300',\n },\n code: {\n padding: 16,\n backgroundColor: theme.colors.code,\n minWidth: '100%',\n },\n hr: {\n borderBottomWidth: 1,\n borderBottomColor: theme.colors.border,\n marginVertical: 4,\n },\n li: {\n ...fontStyle.regular,\n flexShrink: 1,\n },\n });\n\n return {\n ...defaultStyles,\n ...userStyles,\n };\n};\n\nexport default getStyles;\n"],"mappings":"AAAA,SAA0BA,UAA1B,QAA4C,cAA5C;AACA,SAASC,QAAT,QAAyB,SAAzB;;AAGA,MAAMC,aAAa,GAAIC,KAAD,IAAkB;EACtC,OAAOH,UAAU,CAACI,MAAX,CAAkB;IACvBC,OAAO,EAAE;MACPC,QAAQ,EAAE,EADH;MAEPC,UAAU,EAAE,EAFL;MAGPC,KAAK,EAAEL,KAAK,CAACM,MAAN,CAAaC;IAHb,CADc;IAMvBC,OAAO,EAAE;MACPC,UAAU,EAAE,KADL;MAEPJ,KAAK,EAAEL,KAAK,CAACM,MAAN,CAAaC;IAFb;EANc,CAAlB,CA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 'light']
5
+ };
6
+ };
7
+ //# sourceMappingURL=theme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["colors","getTheme","theme"],"sources":["theme.ts"],"sourcesContent":["import type { ColorSchemeName } from 'react-native';\nimport colors from './colors';\nimport type { Theme } from './types';\n\nexport const getTheme = (theme: ColorSchemeName): Theme => {\n return {\n colors: colors[theme || 'light'],\n };\n};\n"],"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"}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { TextStyle, ViewStyle } from 'react-native';\n\nexport interface MarkedStyles {\n container?: ViewStyle;\n em?: TextStyle;\n strong?: TextStyle;\n text?: TextStyle;\n paragraph?: ViewStyle;\n link?: TextStyle;\n blockquote?: ViewStyle;\n h1?: TextStyle;\n h2?: TextStyle;\n h3?: TextStyle;\n h4?: TextStyle;\n h5?: TextStyle;\n h6?: TextStyle;\n codespan?: TextStyle;\n code?: ViewStyle;\n hr?: ViewStyle;\n list?: ViewStyle;\n li?: TextStyle;\n}\n\nexport type ColorKeys = 'background' | 'code' | 'link' | 'text' | 'border';\n\nexport interface Theme {\n colors: Record<ColorKeys, string>;\n}\n"],"mappings":""}
@@ -1,7 +1,6 @@
1
1
  import React from 'react';
2
2
  interface MDImageProps {
3
3
  uri: string;
4
- width: number;
5
4
  }
6
- declare const _default: React.MemoExoticComponent<({ uri, width }: MDImageProps) => JSX.Element | null>;
5
+ declare const _default: React.MemoExoticComponent<({ uri }: MDImageProps) => JSX.Element>;
7
6
  export default _default;
@@ -1,9 +1,10 @@
1
- import { ReactNode } from 'react';
1
+ import React, { ReactNode } from 'react';
2
2
  import { FlatListProps } from 'react-native';
3
+ import type { MarkedStyles } from '../theme/types';
3
4
  interface MarkdownProps {
4
5
  value: string;
5
- contentWidth: number;
6
- listProps?: Omit<FlatListProps<ReactNode>, 'data' | 'renderItem' | 'horizontal'>;
6
+ flatListProps?: Omit<FlatListProps<ReactNode>, 'data' | 'renderItem' | 'horizontal'>;
7
+ styles?: MarkedStyles;
7
8
  }
8
- declare const Markdown: ({ value, contentWidth, listProps }: MarkdownProps) => JSX.Element;
9
- export default Markdown;
9
+ declare const _default: React.MemoExoticComponent<({ value, flatListProps, styles: userStyles, }: MarkdownProps) => JSX.Element>;
10
+ export default _default;
@@ -1,14 +1,16 @@
1
1
  /// <reference types="react" />
2
2
  import type { marked } from 'marked';
3
- import { ImageStyle, StyleProp, TextStyle, ViewStyle } from 'react-native';
4
- import type { ParserOptions } from '../types/types';
3
+ import type { ImageStyle, StyleProp, TextStyle, ViewStyle } from 'react-native';
4
+ import type { MarkedStyles } from '../theme/types';
5
+ interface ParserOptions {
6
+ styles?: MarkedStyles;
7
+ }
5
8
  declare class Parser {
6
9
  private renderer;
7
10
  private styles;
8
- private options;
11
+ private headingStylesMap;
9
12
  constructor(options: ParserOptions);
10
13
  parse(tokens: marked.Token[]): import("react").ReactNode[];
11
- parseBlocks(tokens: marked.Token[], styleObj?: StyleProp<ViewStyle | TextStyle | ImageStyle>): import("react").ReactNode[];
12
- parseInline(tokens: marked.Token[], styleObj?: StyleProp<ViewStyle | TextStyle | ImageStyle>): import("react").ReactNode[];
14
+ parseInline(tokens: marked.Token[], styles?: StyleProp<ViewStyle | TextStyle | ImageStyle>): import("react").ReactNode[];
13
15
  }
14
16
  export default Parser;
@@ -1,14 +1,14 @@
1
1
  import * as React from 'react';
2
2
  import { ViewStyle } from 'react-native';
3
- import type { StyleProp, TextStyle } from 'react-native';
3
+ import { StyleProp, TextStyle } from 'react-native';
4
4
  declare class Renderer {
5
5
  private onLinkPress;
6
6
  getTextNode: (children: string | React.ReactNode[], styles: StyleProp<TextStyle>) => JSX.Element;
7
7
  getLinkNode: (text: string, href: string, styles: StyleProp<TextStyle>) => JSX.Element;
8
- getParagraph(children: React.ReactNode[], styles: StyleProp<ViewStyle>): JSX.Element;
9
- getCodeBlock(text: string, containerStyle: StyleProp<ViewStyle>, textStyle: StyleProp<TextStyle>): JSX.Element;
10
- getBlockquote(children: React.ReactNode[], styles: StyleProp<ViewStyle>): JSX.Element;
11
- getHeading(text: string, styles: StyleProp<TextStyle>): JSX.Element;
12
- getImage(uri: string, width: number): JSX.Element;
8
+ getViewNode(children: React.ReactNode[] | null, styles: StyleProp<ViewStyle>): JSX.Element;
9
+ getCodeBlockNode(text: string, containerStyle: StyleProp<ViewStyle>, textStyle: StyleProp<TextStyle>): JSX.Element;
10
+ getBlockquoteNode(children: React.ReactNode[], styles: StyleProp<ViewStyle>): JSX.Element;
11
+ getImageNode(uri: string): JSX.Element;
12
+ getListNode(ordered: boolean, li: React.ReactNode[], listStyle: ViewStyle | undefined, textStyle: TextStyle | undefined): JSX.Element;
13
13
  }
14
14
  export default Renderer;
@@ -0,0 +1,3 @@
1
+ import type { ColorKeys } from './types';
2
+ declare const colors: Record<'light' | 'dark', Record<ColorKeys, string>>;
3
+ export default colors;
@@ -0,0 +1,4 @@
1
+ import { ColorSchemeName } from 'react-native';
2
+ import type { MarkedStyles } from './types';
3
+ declare const getStyles: (userStyles?: MarkedStyles, colorScheme?: ColorSchemeName) => MarkedStyles;
4
+ export default getStyles;
@@ -0,0 +1,3 @@
1
+ import type { ColorSchemeName } from 'react-native';
2
+ import type { Theme } from './types';
3
+ export declare const getTheme: (theme: ColorSchemeName) => Theme;
@@ -0,0 +1,25 @@
1
+ import type { TextStyle, ViewStyle } from 'react-native';
2
+ export interface MarkedStyles {
3
+ container?: ViewStyle;
4
+ em?: TextStyle;
5
+ strong?: TextStyle;
6
+ text?: TextStyle;
7
+ paragraph?: ViewStyle;
8
+ link?: TextStyle;
9
+ blockquote?: ViewStyle;
10
+ h1?: TextStyle;
11
+ h2?: TextStyle;
12
+ h3?: TextStyle;
13
+ h4?: TextStyle;
14
+ h5?: TextStyle;
15
+ h6?: TextStyle;
16
+ codespan?: TextStyle;
17
+ code?: ViewStyle;
18
+ hr?: ViewStyle;
19
+ list?: ViewStyle;
20
+ li?: TextStyle;
21
+ }
22
+ export declare type ColorKeys = 'background' | 'code' | 'link' | 'text' | 'border';
23
+ export interface Theme {
24
+ colors: Record<ColorKeys, string>;
25
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-marked",
3
- "version": "1.0.0-alpha.3",
4
- "description": "test",
3
+ "version": "1.0.2",
4
+ "description": "Markdown renderer for React Native powered by marked.js",
5
5
  "main": "dist/commonjs/index",
6
6
  "module": "dist/module/index",
7
7
  "types": "dist/typescript/index.d.ts",
@@ -27,12 +27,12 @@
27
27
  "lint": "eslint \"**/*.{js,ts,tsx}\"",
28
28
  "build": "bob build",
29
29
  "prepare": "npm run build",
30
- "release": "release-it --preRelease=alpha"
30
+ "release": "release-it"
31
31
  },
32
32
  "keywords": [
33
33
  "react-native",
34
- "ios",
35
- "android"
34
+ "markdown",
35
+ "react-native markdown"
36
36
  ],
37
37
  "repository": "https://github.com/gmsgowtham/react-native-marked",
38
38
  "author": "Gowtham G <webappsbygowtham@gmail.com> (https://github.com/gmsgowtham)",
@@ -46,7 +46,9 @@
46
46
  },
47
47
  "devDependencies": {
48
48
  "@arkweid/lefthook": "^0.7.7",
49
+ "@babel/core": "^7.19.0",
49
50
  "@babel/eslint-parser": "^7.18.2",
51
+ "@babel/preset-env": "^7.19.0",
50
52
  "@commitlint/config-conventional": "^17.0.2",
51
53
  "@react-native-community/eslint-config": "^3.0.2",
52
54
  "@release-it/conventional-changelog": "^5.0.0",
@@ -66,7 +68,7 @@
66
68
  "react": "17.0.2",
67
69
  "react-native": "0.68.2",
68
70
  "react-native-builder-bob": "^0.18.3",
69
- "release-it": "^15.0.0",
71
+ "release-it": "^15.4.1",
70
72
  "typescript": "^4.5.2"
71
73
  },
72
74
  "resolutions": {
@@ -103,7 +105,8 @@
103
105
  "revert",
104
106
  "style",
105
107
  "test",
106
- "todo"
108
+ "todo",
109
+ "bump"
107
110
  ]
108
111
  ]
109
112
  }
@@ -143,7 +146,8 @@
143
146
  "trailingComma": "es5",
144
147
  "useTabs": false
145
148
  }
146
- ]
149
+ ],
150
+ "@typescript-eslint/ban-ts-comment": "off"
147
151
  }
148
152
  },
149
153
  "eslintIgnore": [
@@ -173,7 +177,9 @@
173
177
  ]
174
178
  },
175
179
  "dependencies": {
180
+ "@jsamr/counter-style": "^2.0.2",
181
+ "@jsamr/react-native-li": "^2.3.1",
176
182
  "marked": "^4.0.18",
177
- "react-native-fast-image": "^8.5.11"
183
+ "react-native-fit-image": "^1.5.5"
178
184
  }
179
185
  }
@@ -1,40 +1,17 @@
1
- import React, { memo, useEffect, useState } from 'react';
1
+ import React, { memo, useEffect } from 'react';
2
2
  import { Image } from 'react-native';
3
- import FastImage from 'react-native-fast-image';
3
+ import FitImage from 'react-native-fit-image';
4
4
 
5
5
  interface MDImageProps {
6
6
  uri: string;
7
- width: number;
8
7
  }
9
8
 
10
- const MDImage = ({ uri, width }: MDImageProps) => {
11
- const [height, setHeight] = useState<number>(0);
12
-
9
+ const MDImage = ({ uri }: MDImageProps) => {
13
10
  useEffect(() => {
14
11
  Image.prefetch(uri);
15
- Image.getSize(uri, (iWidth, iHeight) => {
16
- const heightCalc = width * (iHeight / iWidth);
17
- setHeight(heightCalc);
18
- });
19
- }, [uri, width, height]);
20
-
21
- if (height < 1) {
22
- return null;
23
- }
12
+ }, [uri]);
24
13
 
25
- return (
26
- <FastImage
27
- fallback
28
- source={{ uri }}
29
- style={[
30
- {
31
- width: width,
32
- height: height,
33
- },
34
- ]}
35
- resizeMode={FastImage.resizeMode.cover}
36
- />
37
- );
14
+ return <FitImage source={{ uri }} resizeMode="cover" />;
38
15
  };
39
16
 
40
17
  export default memo(MDImage);
@@ -1,21 +1,38 @@
1
- import React, { ReactNode, useCallback } from 'react';
1
+ import React, { memo, ReactNode, useCallback, useMemo } from 'react';
2
+ import { FlatList, FlatListProps, useColorScheme } from 'react-native';
2
3
  import { marked } from 'marked';
3
4
  import Parser from './Parser';
4
- import { FlatList, FlatListProps } from 'react-native';
5
+ import getStyles from '../theme/styles';
6
+ import type { MarkedStyles } from '../theme/types';
5
7
 
6
8
  interface MarkdownProps {
7
9
  value: string;
8
- contentWidth: number;
9
- listProps?: Omit<
10
+ flatListProps?: Omit<
10
11
  FlatListProps<ReactNode>,
11
12
  'data' | 'renderItem' | 'horizontal'
12
13
  >;
14
+ styles?: MarkedStyles;
13
15
  }
14
16
 
15
- const Markdown = ({ value, contentWidth, listProps }: MarkdownProps) => {
16
- const tokens = marked.lexer(value.trim());
17
- const parser = new Parser({ contentWidth });
18
- const rnElements = parser.parse(tokens);
17
+ const Markdown = ({
18
+ value,
19
+ flatListProps,
20
+ styles: userStyles,
21
+ }: MarkdownProps) => {
22
+ const systemTheme = useColorScheme();
23
+ const styles = useMemo(
24
+ () => getStyles(userStyles, systemTheme),
25
+ [userStyles, systemTheme]
26
+ );
27
+
28
+ const rnElements = useMemo(() => {
29
+ const parser = new Parser({
30
+ styles,
31
+ });
32
+ const tokens = marked.lexer(value.trim());
33
+
34
+ return parser.parse(tokens);
35
+ }, [value, styles]);
19
36
 
20
37
  const renderItem = useCallback(({ item }: { item: ReactNode }) => {
21
38
  return <>{item}</>;
@@ -29,11 +46,12 @@ const Markdown = ({ value, contentWidth, listProps }: MarkdownProps) => {
29
46
  maxToRenderPerBatch={8}
30
47
  initialNumToRender={8}
31
48
  removeClippedSubviews
32
- {...listProps}
49
+ style={styles.container}
50
+ {...flatListProps}
33
51
  data={rnElements}
34
52
  renderItem={renderItem}
35
53
  />
36
54
  );
37
55
  };
38
56
 
39
- export default Markdown;
57
+ export default memo(Markdown);