hs-react-native-custom-markdown 0.0.1 β†’ 0.0.4

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/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Herika Sethi
package/README.md CHANGED
@@ -1,97 +1,15 @@
1
- This is a new [**React Native**](https://reactnative.dev) project, bootstrapped using [`@react-native-community/cli`](https://github.com/react-native-community/cli).
1
+ # hs-react-native-custom-markdown
2
2
 
3
- # Getting Started
3
+ A lightweight React Native component to render custom markdown content, including custom image resolvers.
4
4
 
5
- > **Note**: Make sure you have completed the [Set Up Your Environment](https://reactnative.dev/docs/set-up-your-environment) guide before proceeding.
5
+ ## ✨ Features
6
6
 
7
- ## Step 1: Start Metro
7
+ - Parses and renders markdown content
8
+ - Supports custom image resolution logic
9
+ - Optimized for React Native apps
10
+ - Written in TypeScript
8
11
 
9
- First, you will need to run **Metro**, the JavaScript build tool for React Native.
12
+ ## πŸ“¦ Installation
10
13
 
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.
14
+ ```bash
15
+ npm install hs-react-native-custom-markdown
@@ -1,7 +1,9 @@
1
1
  import React from 'react';
2
+ import { StyleProp, TextStyle, ViewStyle, ImageStyle } from 'react-native';
3
+ type MarkdownStyle = StyleProp<TextStyle | ViewStyle | ImageStyle>;
2
4
  type CustomMarkdownProps = {
3
5
  content: string;
4
- styles?: Partial<typeof defaultStyles>;
6
+ styles?: Partial<Record<keyof typeof defaultStyles, MarkdownStyle>>;
5
7
  resolveImageSource?: (path: string) => any;
6
8
  };
7
9
  declare const CustomMarkdown: React.FC<CustomMarkdownProps>;
@@ -1 +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"}
1
+ {"version":3,"file":"CustomMarkdown.d.ts","sourceRoot":"","sources":["../../src/CustomMarkdown.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAc,MAAM,OAAO,CAAC;AACnC,OAAO,EAML,SAAS,EACT,SAAS,EACT,SAAS,EACT,UAAU,EACX,MAAM,cAAc,CAAC;AAEtB,KAAK,aAAa,GAAG,SAAS,CAAC,SAAS,GAAG,SAAS,GAAG,UAAU,CAAC,CAAC;AAEnE,KAAK,mBAAmB,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,OAAO,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC;IACpE,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,CAAC;CAC5C,CAAC;AAEF,QAAA,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAkNjD,CAAC;AAEF,eAAe,cAAc,CAAC;AAE9B,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6FjB,CAAC"}
@@ -6,12 +6,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const react_1 = __importDefault(require("react"));
7
7
  const react_native_1 = require("react-native");
8
8
  const CustomMarkdown = ({ content, styles = {}, resolveImageSource, }) => {
9
- const mergedStyles = Object.assign(Object.assign({}, defaultStyles), styles);
9
+ const getMergedStyle = (key) => {
10
+ return [defaultStyles[key], styles[key]];
11
+ };
10
12
  const parseInlineMarkdown = (text) => {
11
13
  const elements = [];
12
14
  let remaining = text;
13
15
  let index = 0;
14
- const applyRegex = (regex, style, isLink = false, isCode = false, isHtmlTag = false, renderText) => {
16
+ const applyRegex = (regex, styleKey, isLink = false, isCode = false, isHtmlTag = false, renderText) => {
15
17
  const match = regex.exec(remaining);
16
18
  if (match) {
17
19
  const [full, inner, link] = match;
@@ -20,17 +22,17 @@ const CustomMarkdown = ({ content, styles = {}, resolveImageSource, }) => {
20
22
  if (before)
21
23
  elements.push(before);
22
24
  if (isLink) {
23
- elements.push(<react_native_1.Text key={`link-${index++}`} style={style} onPress={() => react_native_1.Linking.openURL(link)}>
25
+ elements.push(<react_native_1.Text key={`link-${index++}`} style={getMergedStyle(styleKey)} onPress={() => react_native_1.Linking.openURL(link)}>
24
26
  {inner}
25
27
  </react_native_1.Text>);
26
28
  }
27
29
  else if (isHtmlTag && renderText) {
28
- elements.push(<react_native_1.Text key={`html-${index++}`} style={style}>
30
+ elements.push(<react_native_1.Text key={`html-${index++}`} style={getMergedStyle(styleKey)}>
29
31
  {renderText(inner)}
30
32
  </react_native_1.Text>);
31
33
  }
32
34
  else {
33
- elements.push(<react_native_1.Text key={`styled-${index++}`} style={style}>
35
+ elements.push(<react_native_1.Text key={`styled-${index++}`} style={getMergedStyle(styleKey)}>
34
36
  {inner}
35
37
  </react_native_1.Text>);
36
38
  }
@@ -41,19 +43,24 @@ const CustomMarkdown = ({ content, styles = {}, resolveImageSource, }) => {
41
43
  };
42
44
  while (remaining.length) {
43
45
  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' },
46
+ { regex: /\*\*\*(.*?)\*\*\*/g, style: ['bold', 'italic'] },
47
+ { regex: /\*\*(.*?)\*\*/g, style: ['bold'] },
48
+ { regex: /_(.*?)_/g, style: ['italic'] },
49
+ { regex: /`([^`]+)`/g, style: ['code'], isCode: true },
50
+ { regex: /\[(.*?)\]\((.*?)\)/g, style: ['link'], isLink: true },
51
+ { regex: /<b>(.*?)<\/b>/i, style: ['bold'], isHtmlTag: true },
52
+ { regex: /<i>(.*?)<\/i>/i, style: ['italic'], isHtmlTag: true },
53
+ { regex: /<u>(.*?)<\/u>/i, style: ['underline'], isHtmlTag: true },
54
+ {
55
+ regex: /<br\s*\/?>/i,
56
+ style: ['paragraph'],
57
+ isHtmlTag: true,
58
+ renderText: () => '\n',
59
+ },
53
60
  ];
54
61
  let matched = false;
55
62
  for (const pattern of patterns) {
56
- if (applyRegex(pattern.regex, pattern.style, pattern.isLink, pattern.isCode, pattern.isHtmlTag, pattern.renderText)) {
63
+ if (applyRegex(pattern.regex, pattern.style[0], pattern.isLink, pattern.isCode, pattern.isHtmlTag, pattern.renderText)) {
57
64
  matched = true;
58
65
  break;
59
66
  }
@@ -74,8 +81,8 @@ const CustomMarkdown = ({ content, styles = {}, resolveImageSource, }) => {
74
81
  if (line.trim() === '```') {
75
82
  inCodeBlock = !inCodeBlock;
76
83
  if (!inCodeBlock) {
77
- result.push(<react_native_1.View key={`code-${index}`} style={mergedStyles.codeBlock}>
78
- <react_native_1.Text style={mergedStyles.code}>
84
+ result.push(<react_native_1.View key={`code-${index}`} style={getMergedStyle('codeBlock')}>
85
+ <react_native_1.Text style={getMergedStyle('code')}>
79
86
  {codeBlockContent.join('\n')}
80
87
  </react_native_1.Text>
81
88
  </react_native_1.View>);
@@ -87,64 +94,55 @@ const CustomMarkdown = ({ content, styles = {}, resolveImageSource, }) => {
87
94
  codeBlockContent.push(line);
88
95
  return;
89
96
  }
90
- // Image
91
97
  const imgMatch = line.match(/!\[(.*?)\]\((.*?)\)/);
92
98
  if (imgMatch) {
93
99
  const altText = imgMatch[1];
94
100
  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}/>);
101
+ const source = resolveImageSource
102
+ ? resolveImageSource(imgPath)
103
+ : { uri: imgPath };
104
+ result.push(<react_native_1.Image key={`img-${index}`} source={source} style={getMergedStyle('image')} accessibilityLabel={altText}/>);
103
105
  return;
104
106
  }
105
- // Heading
106
107
  const headingMatch = line.match(/^(#{1,6})\s+(.*)/);
107
108
  if (headingMatch) {
108
109
  const level = headingMatch[1].length;
109
110
  const headingText = headingMatch[2];
110
111
  const styleKey = `heading${level}`;
111
- result.push(<react_native_1.Text key={`heading-${index}`} style={mergedStyles[styleKey]}>
112
+ result.push(<react_native_1.Text key={`heading-${index}`} style={getMergedStyle(styleKey)}>
112
113
  {headingText}
113
114
  </react_native_1.Text>);
114
115
  return;
115
116
  }
116
- // Blockquote
117
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}>
118
+ result.push(<react_native_1.View key={`quote-${index}`} style={getMergedStyle('blockquoteContainer')}>
119
+ <react_native_1.Text style={getMergedStyle('blockquoteText')}>
120
120
  {line.replace(/^>\s?/, '')}
121
121
  </react_native_1.Text>
122
122
  </react_native_1.View>);
123
123
  return;
124
124
  }
125
- // Bullet list
126
125
  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}>
126
+ result.push(<react_native_1.View key={`list-${index}`} style={getMergedStyle('bulletRow')}>
127
+ <react_native_1.Text style={getMergedStyle('bullet')}>{'\u2022'}</react_native_1.Text>
128
+ <react_native_1.Text style={getMergedStyle('listText')}>
130
129
  {parseInlineMarkdown(line.replace('- ', ''))}
131
130
  </react_native_1.Text>
132
131
  </react_native_1.View>);
133
132
  return;
134
133
  }
135
- // Numbered list
136
134
  const numberedMatch = line.trim().match(/^(\d+)\.\s+(.*)/);
137
135
  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}>
136
+ result.push(<react_native_1.View key={`list-num-${index}`} style={getMergedStyle('bulletRow')}>
137
+ <react_native_1.Text style={getMergedStyle('bullet')}>{numberedMatch[1] + '.'}</react_native_1.Text>
138
+ <react_native_1.Text style={getMergedStyle('listText')}>
141
139
  {parseInlineMarkdown(numberedMatch[2])}
142
140
  </react_native_1.Text>
143
141
  </react_native_1.View>);
144
142
  return;
145
143
  }
146
144
  if (line.trim()) {
147
- result.push(<react_native_1.Text key={`text-${index}`} style={mergedStyles.paragraph}>
145
+ result.push(<react_native_1.Text key={`text-${index}`} style={getMergedStyle('paragraph')}>
148
146
  {parseInlineMarkdown(line)}
149
147
  </react_native_1.Text>);
150
148
  }
package/package.json CHANGED
@@ -1,15 +1,11 @@
1
1
  {
2
2
  "name": "hs-react-native-custom-markdown",
3
- "version": "0.0.1",
3
+ "version": "0.0.4",
4
+ "description": "A React Native component to render custom markdown content.",
4
5
  "main": "dist/index.js",
5
6
  "types": "dist/index.d.ts",
6
7
  "react-native": "dist/index.js",
7
8
  "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
9
  "author": "Herika Sethi",
14
10
  "license": "MIT",
15
11
  "keywords": [
@@ -18,6 +14,10 @@
18
14
  "custom-markdown",
19
15
  "markdown-renderer"
20
16
  ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/HerikaAFIDigital/custom-markdown-converter.git"
20
+ },
21
21
  "files": [
22
22
  "dist",
23
23
  "README.md"
@@ -30,12 +30,13 @@
30
30
  "start": "react-native start",
31
31
  "test": "jest"
32
32
  },
33
- "dependencies": {
34
- "react": "19.1.0",
35
- "react-native": "0.80.0",
36
- "@react-native/new-app-screen": "0.80.0"
33
+ "peerDependencies": {
34
+ "react": "*",
35
+ "react-native": "*"
37
36
  },
38
37
  "devDependencies": {
38
+ "react": "19.1.0",
39
+ "react-native": "0.80.0",
39
40
  "@babel/core": "^7.25.2",
40
41
  "@babel/preset-env": "^7.25.3",
41
42
  "@babel/runtime": "^7.25.0",