hs-react-native-custom-markdown 0.0.1

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 ADDED
@@ -0,0 +1,97 @@
1
+ This is a new [**React Native**](https://reactnative.dev) project, bootstrapped using [`@react-native-community/cli`](https://github.com/react-native-community/cli).
2
+
3
+ # Getting Started
4
+
5
+ > **Note**: Make sure you have completed the [Set Up Your Environment](https://reactnative.dev/docs/set-up-your-environment) guide before proceeding.
6
+
7
+ ## Step 1: Start Metro
8
+
9
+ First, you will need to run **Metro**, the JavaScript build tool for React Native.
10
+
11
+ To start the Metro dev server, run the following command from the root of your React Native project:
12
+
13
+ ```sh
14
+ # Using npm
15
+ npm start
16
+
17
+ # OR using Yarn
18
+ yarn start
19
+ ```
20
+
21
+ ## Step 2: Build and run your app
22
+
23
+ With Metro running, open a new terminal window/pane from the root of your React Native project, and use one of the following commands to build and run your Android or iOS app:
24
+
25
+ ### Android
26
+
27
+ ```sh
28
+ # Using npm
29
+ npm run android
30
+
31
+ # OR using Yarn
32
+ yarn android
33
+ ```
34
+
35
+ ### iOS
36
+
37
+ For iOS, remember to install CocoaPods dependencies (this only needs to be run on first clone or after updating native deps).
38
+
39
+ The first time you create a new project, run the Ruby bundler to install CocoaPods itself:
40
+
41
+ ```sh
42
+ bundle install
43
+ ```
44
+
45
+ Then, and every time you update your native dependencies, run:
46
+
47
+ ```sh
48
+ bundle exec pod install
49
+ ```
50
+
51
+ For more information, please visit [CocoaPods Getting Started guide](https://guides.cocoapods.org/using/getting-started.html).
52
+
53
+ ```sh
54
+ # Using npm
55
+ npm run ios
56
+
57
+ # OR using Yarn
58
+ yarn ios
59
+ ```
60
+
61
+ If everything is set up correctly, you should see your new app running in the Android Emulator, iOS Simulator, or your connected device.
62
+
63
+ This is one way to run your app — you can also build it directly from Android Studio or Xcode.
64
+
65
+ ## Step 3: Modify your app
66
+
67
+ Now that you have successfully run the app, let's make changes!
68
+
69
+ Open `App.tsx` in your text editor of choice and make some changes. When you save, your app will automatically update and reflect these changes — this is powered by [Fast Refresh](https://reactnative.dev/docs/fast-refresh).
70
+
71
+ When you want to forcefully reload, for example to reset the state of your app, you can perform a full reload:
72
+
73
+ - **Android**: Press the <kbd>R</kbd> key twice or select **"Reload"** from the **Dev Menu**, accessed via <kbd>Ctrl</kbd> + <kbd>M</kbd> (Windows/Linux) or <kbd>Cmd ⌘</kbd> + <kbd>M</kbd> (macOS).
74
+ - **iOS**: Press <kbd>R</kbd> in iOS Simulator.
75
+
76
+ ## Congratulations! :tada:
77
+
78
+ You've successfully run and modified your React Native App. :partying_face:
79
+
80
+ ### Now what?
81
+
82
+ - If you want to add this new React Native code to an existing application, check out the [Integration guide](https://reactnative.dev/docs/integration-with-existing-apps).
83
+ - If you're curious to learn more about React Native, check out the [docs](https://reactnative.dev/docs/getting-started).
84
+
85
+ # Troubleshooting
86
+
87
+ If you're having issues getting the above steps to work, see the [Troubleshooting](https://reactnative.dev/docs/troubleshooting) page.
88
+
89
+ # Learn More
90
+
91
+ To learn more about React Native, take a look at the following resources:
92
+
93
+ - [React Native Website](https://reactnative.dev) - learn more about React Native.
94
+ - [Getting Started](https://reactnative.dev/docs/environment-setup) - an **overview** of React Native and how setup your environment.
95
+ - [Learn the Basics](https://reactnative.dev/docs/getting-started) - a **guided tour** of the React Native **basics**.
96
+ - [Blog](https://reactnative.dev/blog) - read the latest official React Native **Blog** posts.
97
+ - [`@facebook/react-native`](https://github.com/facebook/react-native) - the Open Source; GitHub **repository** for React Native.
@@ -0,0 +1,3 @@
1
+ import CustomMarkdown from './src/CustomMarkdown';
2
+ export default CustomMarkdown;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,sBAAsB,CAAC;AAClD,eAAe,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const CustomMarkdown_1 = __importDefault(require("./src/CustomMarkdown"));
7
+ exports.default = CustomMarkdown_1.default;
@@ -0,0 +1,103 @@
1
+ import React from 'react';
2
+ type CustomMarkdownProps = {
3
+ content: string;
4
+ styles?: Partial<typeof defaultStyles>;
5
+ resolveImageSource?: (path: string) => any;
6
+ };
7
+ declare const CustomMarkdown: React.FC<CustomMarkdownProps>;
8
+ export default CustomMarkdown;
9
+ declare const defaultStyles: {
10
+ paragraph: {
11
+ fontSize: number;
12
+ lineHeight: number;
13
+ color: string;
14
+ marginBottom: number;
15
+ };
16
+ heading1: {
17
+ fontSize: number;
18
+ fontWeight: "bold";
19
+ marginVertical: number;
20
+ };
21
+ heading2: {
22
+ fontSize: number;
23
+ fontWeight: "bold";
24
+ marginVertical: number;
25
+ };
26
+ heading3: {
27
+ fontSize: number;
28
+ fontWeight: "bold";
29
+ marginVertical: number;
30
+ };
31
+ heading4: {
32
+ fontSize: number;
33
+ fontWeight: "bold";
34
+ marginVertical: number;
35
+ };
36
+ heading5: {
37
+ fontSize: number;
38
+ fontWeight: "bold";
39
+ marginVertical: number;
40
+ };
41
+ heading6: {
42
+ fontSize: number;
43
+ fontWeight: "bold";
44
+ marginVertical: number;
45
+ };
46
+ bold: {
47
+ fontWeight: "bold";
48
+ };
49
+ italic: {
50
+ fontStyle: "italic";
51
+ };
52
+ underline: {
53
+ textDecorationLine: "underline";
54
+ };
55
+ code: {
56
+ backgroundColor: string;
57
+ padding: number;
58
+ borderRadius: number;
59
+ };
60
+ codeBlock: {
61
+ backgroundColor: string;
62
+ padding: number;
63
+ borderRadius: number;
64
+ marginVertical: number;
65
+ };
66
+ blockquoteContainer: {
67
+ borderLeftWidth: number;
68
+ borderLeftColor: string;
69
+ paddingLeft: number;
70
+ marginVertical: number;
71
+ };
72
+ blockquoteText: {
73
+ fontStyle: "italic";
74
+ color: string;
75
+ };
76
+ bulletRow: {
77
+ flexDirection: "row";
78
+ alignItems: "flex-start";
79
+ marginBottom: number;
80
+ };
81
+ bullet: {
82
+ fontSize: number;
83
+ lineHeight: number;
84
+ marginRight: number;
85
+ fontWeight: "bold";
86
+ };
87
+ listText: {
88
+ flex: number;
89
+ fontSize: number;
90
+ lineHeight: number;
91
+ };
92
+ link: {
93
+ color: string;
94
+ textDecorationLine: "underline";
95
+ };
96
+ image: {
97
+ width: "100%";
98
+ height: number;
99
+ resizeMode: "contain";
100
+ marginVertical: number;
101
+ };
102
+ };
103
+ //# sourceMappingURL=CustomMarkdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CustomMarkdown.d.ts","sourceRoot":"","sources":["../../src/CustomMarkdown.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAc,MAAM,OAAO,CAAC;AASnC,KAAK,mBAAmB,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC,OAAO,aAAa,CAAC,CAAC;IACvC,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,CAAC;CAC5C,CAAC;AAEF,QAAA,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAoNjD,CAAC;AAEF,eAAe,cAAc,CAAC;AAE9B,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6FjB,CAAC"}
@@ -0,0 +1,250 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const react_1 = __importDefault(require("react"));
7
+ const react_native_1 = require("react-native");
8
+ const CustomMarkdown = ({ content, styles = {}, resolveImageSource, }) => {
9
+ const mergedStyles = Object.assign(Object.assign({}, defaultStyles), styles);
10
+ const parseInlineMarkdown = (text) => {
11
+ const elements = [];
12
+ let remaining = text;
13
+ let index = 0;
14
+ const applyRegex = (regex, style, isLink = false, isCode = false, isHtmlTag = false, renderText) => {
15
+ const match = regex.exec(remaining);
16
+ if (match) {
17
+ const [full, inner, link] = match;
18
+ const before = remaining.substring(0, match.index);
19
+ const after = remaining.substring(match.index + full.length);
20
+ if (before)
21
+ elements.push(before);
22
+ if (isLink) {
23
+ elements.push(<react_native_1.Text key={`link-${index++}`} style={style} onPress={() => react_native_1.Linking.openURL(link)}>
24
+ {inner}
25
+ </react_native_1.Text>);
26
+ }
27
+ else if (isHtmlTag && renderText) {
28
+ elements.push(<react_native_1.Text key={`html-${index++}`} style={style}>
29
+ {renderText(inner)}
30
+ </react_native_1.Text>);
31
+ }
32
+ else {
33
+ elements.push(<react_native_1.Text key={`styled-${index++}`} style={style}>
34
+ {inner}
35
+ </react_native_1.Text>);
36
+ }
37
+ remaining = after;
38
+ return true;
39
+ }
40
+ return false;
41
+ };
42
+ while (remaining.length) {
43
+ const patterns = [
44
+ { regex: /\*\*\*(.*?)\*\*\*/g, style: [mergedStyles.bold, mergedStyles.italic] },
45
+ { regex: /\*\*(.*?)\*\*/g, style: mergedStyles.bold },
46
+ { regex: /_(.*?)_/g, style: mergedStyles.italic },
47
+ { regex: /`([^`]+)`/g, style: mergedStyles.code, isCode: true },
48
+ { regex: /\[(.*?)\]\((.*?)\)/g, style: mergedStyles.link, isLink: true },
49
+ { regex: /<b>(.*?)<\/b>/i, style: mergedStyles.bold, isHtmlTag: true },
50
+ { regex: /<i>(.*?)<\/i>/i, style: mergedStyles.italic, isHtmlTag: true },
51
+ { regex: /<u>(.*?)<\/u>/i, style: mergedStyles.underline, isHtmlTag: true },
52
+ { regex: /<br\s*\/?>/i, style: mergedStyles.paragraph, isHtmlTag: true, renderText: () => '\n' },
53
+ ];
54
+ let matched = false;
55
+ for (const pattern of patterns) {
56
+ if (applyRegex(pattern.regex, pattern.style, pattern.isLink, pattern.isCode, pattern.isHtmlTag, pattern.renderText)) {
57
+ matched = true;
58
+ break;
59
+ }
60
+ }
61
+ if (!matched) {
62
+ elements.push(remaining);
63
+ break;
64
+ }
65
+ }
66
+ return <react_native_1.Text>{elements}</react_native_1.Text>;
67
+ };
68
+ const renderMarkdown = () => {
69
+ const lines = content.split('\n');
70
+ const result = [];
71
+ let inCodeBlock = false;
72
+ let codeBlockContent = [];
73
+ lines.forEach((line, index) => {
74
+ if (line.trim() === '```') {
75
+ inCodeBlock = !inCodeBlock;
76
+ if (!inCodeBlock) {
77
+ result.push(<react_native_1.View key={`code-${index}`} style={mergedStyles.codeBlock}>
78
+ <react_native_1.Text style={mergedStyles.code}>
79
+ {codeBlockContent.join('\n')}
80
+ </react_native_1.Text>
81
+ </react_native_1.View>);
82
+ codeBlockContent = [];
83
+ }
84
+ return;
85
+ }
86
+ if (inCodeBlock) {
87
+ codeBlockContent.push(line);
88
+ return;
89
+ }
90
+ // Image
91
+ const imgMatch = line.match(/!\[(.*?)\]\((.*?)\)/);
92
+ if (imgMatch) {
93
+ const altText = imgMatch[1];
94
+ const imgPath = imgMatch[2];
95
+ let source;
96
+ if (resolveImageSource) {
97
+ source = resolveImageSource(imgPath);
98
+ }
99
+ else {
100
+ source = { uri: imgPath }; // fallback: remote URL
101
+ }
102
+ result.push(<react_native_1.Image key={`img-${index}`} source={source} style={mergedStyles.image} accessibilityLabel={altText}/>);
103
+ return;
104
+ }
105
+ // Heading
106
+ const headingMatch = line.match(/^(#{1,6})\s+(.*)/);
107
+ if (headingMatch) {
108
+ const level = headingMatch[1].length;
109
+ const headingText = headingMatch[2];
110
+ const styleKey = `heading${level}`;
111
+ result.push(<react_native_1.Text key={`heading-${index}`} style={mergedStyles[styleKey]}>
112
+ {headingText}
113
+ </react_native_1.Text>);
114
+ return;
115
+ }
116
+ // Blockquote
117
+ if (line.startsWith('>')) {
118
+ result.push(<react_native_1.View key={`quote-${index}`} style={mergedStyles.blockquoteContainer}>
119
+ <react_native_1.Text style={mergedStyles.blockquoteText}>
120
+ {line.replace(/^>\s?/, '')}
121
+ </react_native_1.Text>
122
+ </react_native_1.View>);
123
+ return;
124
+ }
125
+ // Bullet list
126
+ if (line.trim().startsWith('- ')) {
127
+ result.push(<react_native_1.View key={`list-${index}`} style={mergedStyles.bulletRow}>
128
+ <react_native_1.Text style={mergedStyles.bullet}>{'\u2022'}</react_native_1.Text>
129
+ <react_native_1.Text style={mergedStyles.listText}>
130
+ {parseInlineMarkdown(line.replace('- ', ''))}
131
+ </react_native_1.Text>
132
+ </react_native_1.View>);
133
+ return;
134
+ }
135
+ // Numbered list
136
+ const numberedMatch = line.trim().match(/^(\d+)\.\s+(.*)/);
137
+ if (numberedMatch) {
138
+ result.push(<react_native_1.View key={`list-num-${index}`} style={mergedStyles.bulletRow}>
139
+ <react_native_1.Text style={mergedStyles.bullet}>{numberedMatch[1] + '.'}</react_native_1.Text>
140
+ <react_native_1.Text style={mergedStyles.listText}>
141
+ {parseInlineMarkdown(numberedMatch[2])}
142
+ </react_native_1.Text>
143
+ </react_native_1.View>);
144
+ return;
145
+ }
146
+ if (line.trim()) {
147
+ result.push(<react_native_1.Text key={`text-${index}`} style={mergedStyles.paragraph}>
148
+ {parseInlineMarkdown(line)}
149
+ </react_native_1.Text>);
150
+ }
151
+ });
152
+ return result;
153
+ };
154
+ return <react_native_1.View>{renderMarkdown()}</react_native_1.View>;
155
+ };
156
+ exports.default = CustomMarkdown;
157
+ const defaultStyles = react_native_1.StyleSheet.create({
158
+ paragraph: {
159
+ fontSize: 16,
160
+ lineHeight: 24,
161
+ color: '#333',
162
+ marginBottom: 8,
163
+ },
164
+ heading1: {
165
+ fontSize: 24,
166
+ fontWeight: 'bold',
167
+ marginVertical: 10,
168
+ },
169
+ heading2: {
170
+ fontSize: 22,
171
+ fontWeight: 'bold',
172
+ marginVertical: 8,
173
+ },
174
+ heading3: {
175
+ fontSize: 20,
176
+ fontWeight: 'bold',
177
+ marginVertical: 6,
178
+ },
179
+ heading4: {
180
+ fontSize: 18,
181
+ fontWeight: 'bold',
182
+ marginVertical: 4,
183
+ },
184
+ heading5: {
185
+ fontSize: 16,
186
+ fontWeight: 'bold',
187
+ marginVertical: 4,
188
+ },
189
+ heading6: {
190
+ fontSize: 14,
191
+ fontWeight: 'bold',
192
+ marginVertical: 2,
193
+ },
194
+ bold: {
195
+ fontWeight: 'bold',
196
+ },
197
+ italic: {
198
+ fontStyle: 'italic',
199
+ },
200
+ underline: {
201
+ textDecorationLine: 'underline',
202
+ },
203
+ code: {
204
+ backgroundColor: '#f4f4f4',
205
+ padding: 4,
206
+ borderRadius: 4,
207
+ },
208
+ codeBlock: {
209
+ backgroundColor: '#eee',
210
+ padding: 10,
211
+ borderRadius: 6,
212
+ marginVertical: 10,
213
+ },
214
+ blockquoteContainer: {
215
+ borderLeftWidth: 4,
216
+ borderLeftColor: '#ccc',
217
+ paddingLeft: 10,
218
+ marginVertical: 8,
219
+ },
220
+ blockquoteText: {
221
+ fontStyle: 'italic',
222
+ color: '#666',
223
+ },
224
+ bulletRow: {
225
+ flexDirection: 'row',
226
+ alignItems: 'flex-start',
227
+ marginBottom: 6,
228
+ },
229
+ bullet: {
230
+ fontSize: 16,
231
+ lineHeight: 24,
232
+ marginRight: 6,
233
+ fontWeight: 'bold',
234
+ },
235
+ listText: {
236
+ flex: 1,
237
+ fontSize: 16,
238
+ lineHeight: 24,
239
+ },
240
+ link: {
241
+ color: '#007AFF',
242
+ textDecorationLine: 'underline',
243
+ },
244
+ image: {
245
+ width: '100%',
246
+ height: 200,
247
+ resizeMode: 'contain',
248
+ marginVertical: 10,
249
+ },
250
+ });
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "hs-react-native-custom-markdown",
3
+ "version": "0.0.1",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "react-native": "dist/index.js",
7
+ "private": false,
8
+ "description": "A React Native component to render custom markdown content.",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/HerikaAFIDigital/custom-markdown-converter.git"
12
+ },
13
+ "author": "Herika Sethi",
14
+ "license": "MIT",
15
+ "keywords": [
16
+ "react-native",
17
+ "markdown",
18
+ "custom-markdown",
19
+ "markdown-renderer"
20
+ ],
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "scripts": {
26
+ "android": "react-native run-android",
27
+ "ios": "react-native run-ios",
28
+ "build": "tsc",
29
+ "lint": "eslint .",
30
+ "start": "react-native start",
31
+ "test": "jest"
32
+ },
33
+ "dependencies": {
34
+ "react": "19.1.0",
35
+ "react-native": "0.80.0",
36
+ "@react-native/new-app-screen": "0.80.0"
37
+ },
38
+ "devDependencies": {
39
+ "@babel/core": "^7.25.2",
40
+ "@babel/preset-env": "^7.25.3",
41
+ "@babel/runtime": "^7.25.0",
42
+ "@react-native-community/cli": "19.0.0",
43
+ "@react-native-community/cli-platform-android": "19.0.0",
44
+ "@react-native-community/cli-platform-ios": "19.0.0",
45
+ "@react-native/babel-preset": "0.80.0",
46
+ "@react-native/eslint-config": "0.80.0",
47
+ "@react-native/metro-config": "0.80.0",
48
+ "@react-native/typescript-config": "0.80.0",
49
+ "@types/jest": "^29.5.13",
50
+ "@types/react": "^19.1.0",
51
+ "@types/react-test-renderer": "^19.1.0",
52
+ "eslint": "^8.19.0",
53
+ "jest": "^29.6.3",
54
+ "prettier": "2.8.8",
55
+ "react-test-renderer": "19.1.0",
56
+ "typescript": "5.0.4"
57
+ },
58
+ "engines": {
59
+ "node": ">=18"
60
+ }
61
+ }