react-native-swiftui-markdown 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # react-native-swiftui-markdown
2
+
3
+ A lightweight React Native component for rendering Markdown content with native iOS performance using SwiftUI.
4
+
5
+ ## Features
6
+
7
+ - ✅ Markdown rendering with native performance
8
+ - ✅ Support for headings, bold, italic, lists, code blocks
9
+ - ✅ Customizable fonts and colors
10
+ - ✅ TypeScript support
11
+ - 🍎 iOS 15.0+ (Android support coming soon)
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install react-native-swiftui-markdown
17
+ # or
18
+ yarn add react-native-swiftui-markdown
19
+ ```
20
+
21
+ ### iOS Setup
22
+
23
+ ```bash
24
+ cd ios && pod install
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ### Basic Example
30
+
31
+ ```tsx
32
+ import React from 'react';
33
+ import { SafeAreaView, StyleSheet } from 'react-native';
34
+ import MarkdownView from 'react-native-swiftui-markdown';
35
+
36
+ export default function App() {
37
+ const markdown = `
38
+ # Hello, Markdown!
39
+
40
+ This is **bold** text and this is *italic*.
41
+
42
+ - List item 1
43
+ - List item 2
44
+
45
+ \`\`\`javascript
46
+ const greeting = "Hello, World!";
47
+ console.log(greeting);
48
+ \`\`\`
49
+ `;
50
+
51
+ return (
52
+ <SafeAreaView style={styles.container}>
53
+ <MarkdownView
54
+ markdown={markdown}
55
+ style={styles.markdown}
56
+ />
57
+ </SafeAreaView>
58
+ );
59
+ }
60
+
61
+ const styles = StyleSheet.create({
62
+ container: {
63
+ flex: 1,
64
+ },
65
+ markdown: {
66
+ flex: 1,
67
+ padding: 16,
68
+ },
69
+ });
70
+ ```
71
+
72
+ ### Customization
73
+
74
+ ```tsx
75
+ <MarkdownView
76
+ markdown={content}
77
+ h1FontSize={32}
78
+ h2FontSize={26}
79
+ h3FontSize={20}
80
+ tintColor="#007AFF"
81
+ codeBlockTintColor="#FF6B6B"
82
+ inlineCodeTintColor="#4ECDC4"
83
+ style={{ flex: 1, padding: 16 }}
84
+ />
85
+ ```
86
+
87
+ ## Props
88
+
89
+ | Prop | Type | Default | Description |
90
+ |------|------|---------|-------------|
91
+ | `markdown` | `string` | **required** | Markdown content to render |
92
+ | `style` | `ViewStyle` | - | Container style |
93
+ | `h1FontSize` | `number` | `34` | Font size for H1 headings |
94
+ | `h2FontSize` | `number` | `28` | Font size for H2 headings |
95
+ | `h3FontSize` | `number` | `22` | Font size for H3 headings |
96
+ | `h4FontSize` | `number` | `20` | Font size for H4 headings |
97
+ | `h5FontSize` | `number` | `18` | Font size for H5 headings |
98
+ | `h6FontSize` | `number` | `16` | Font size for H6 headings |
99
+ | `fontFamily` | `string` | - | Base font family |
100
+ | `tintColor` | `string` | - | Tint color for headings |
101
+ | `codeBlockTintColor` | `string` | - | Tint color for code blocks |
102
+ | `inlineCodeTintColor` | `string` | - | Tint color for inline code |
103
+ | `quoteTintColor` | `string` | - | Tint color for quotes |
104
+
105
+ ## Supported Markdown Features
106
+
107
+ - ✅ Headings (H1-H6)
108
+ - ✅ Bold (`**text**`)
109
+ - ✅ Italic (`*text*`)
110
+ - ✅ Inline code (`` `code` ``)
111
+ - ✅ Code blocks (` ``` `)
112
+ - ✅ Unordered lists (`- item`)
113
+ - 🔄 More features coming soon
114
+
115
+ ## Platform Support
116
+
117
+ - ✅ iOS 15.0+
118
+ - ⏳ Android (planned)
119
+
120
+ ## Requirements
121
+
122
+ - React Native 0.60+
123
+ - iOS 15.0+
124
+ - Not compatible with Expo Go (use Expo dev client or bare workflow)
125
+
126
+ ## License
127
+
128
+ MIT
129
+
130
+ ## Contributing
131
+
132
+ Contributions are welcome! Please feel free to submit a Pull Request.
@@ -0,0 +1,3 @@
1
+ #import <React/RCTViewManager.h>
2
+ #import <React/RCTBridgeModule.h>
3
+ #import <React/RCTView.h>
@@ -0,0 +1,21 @@
1
+ #import <React/RCTViewManager.h>
2
+
3
+ @interface RCT_EXTERN_MODULE(RNMarkdownViewManager, RCTViewManager)
4
+
5
+ RCT_EXPORT_VIEW_PROPERTY(markdown, NSString)
6
+ RCT_EXPORT_VIEW_PROPERTY(h1FontSize, NSNumber)
7
+ RCT_EXPORT_VIEW_PROPERTY(h2FontSize, NSNumber)
8
+ RCT_EXPORT_VIEW_PROPERTY(h3FontSize, NSNumber)
9
+ RCT_EXPORT_VIEW_PROPERTY(h4FontSize, NSNumber)
10
+ RCT_EXPORT_VIEW_PROPERTY(h5FontSize, NSNumber)
11
+ RCT_EXPORT_VIEW_PROPERTY(h6FontSize, NSNumber)
12
+ RCT_EXPORT_VIEW_PROPERTY(fontFamily, NSString)
13
+ RCT_EXPORT_VIEW_PROPERTY(tintColor, UIColor)
14
+ RCT_EXPORT_VIEW_PROPERTY(codeBlockTintColor, UIColor)
15
+ RCT_EXPORT_VIEW_PROPERTY(inlineCodeTintColor, UIColor)
16
+ RCT_EXPORT_VIEW_PROPERTY(quoteTintColor, UIColor)
17
+ RCT_EXPORT_VIEW_PROPERTY(enableLatex, BOOL)
18
+ RCT_EXPORT_VIEW_PROPERTY(enableSyntaxHighlighting, BOOL)
19
+ RCT_EXPORT_VIEW_PROPERTY(syntaxTheme, NSString)
20
+
21
+ @end
@@ -0,0 +1,252 @@
1
+ import Foundation
2
+ import SwiftUI
3
+ #if __has_include(<React/RCTViewManager.h>)
4
+ import React
5
+ #elseif __has_include("RCTViewManager.h")
6
+ import React
7
+ #else
8
+ @_exported import React
9
+ #endif
10
+
11
+ @objc(RNMarkdownViewManager)
12
+ class RNMarkdownViewManager: RCTViewManager {
13
+
14
+ override func view() -> UIView! {
15
+ return RNMarkdownViewWrapper()
16
+ }
17
+
18
+ override static func requiresMainQueueSetup() -> Bool {
19
+ return true
20
+ }
21
+ }
22
+
23
+ class RNMarkdownViewWrapper: UIView {
24
+
25
+ private var hostingController: UIHostingController<RNMarkdownViewContent>?
26
+
27
+ @objc var markdown: String = "" {
28
+ didSet {
29
+ updateContent()
30
+ }
31
+ }
32
+
33
+ @objc var h1FontSize: NSNumber = 34 {
34
+ didSet {
35
+ updateContent()
36
+ }
37
+ }
38
+
39
+ @objc var h2FontSize: NSNumber = 28 {
40
+ didSet {
41
+ updateContent()
42
+ }
43
+ }
44
+
45
+ @objc var h3FontSize: NSNumber = 22 {
46
+ didSet {
47
+ updateContent()
48
+ }
49
+ }
50
+
51
+ @objc var fontFamily: String? {
52
+ didSet {
53
+ updateContent()
54
+ }
55
+ }
56
+
57
+ @objc var tintColor: UIColor? {
58
+ didSet {
59
+ updateContent()
60
+ }
61
+ }
62
+
63
+ @objc var codeBlockTintColor: UIColor? {
64
+ didSet {
65
+ updateContent()
66
+ }
67
+ }
68
+
69
+ @objc var inlineCodeTintColor: UIColor? {
70
+ didSet {
71
+ updateContent()
72
+ }
73
+ }
74
+
75
+ @objc var quoteTintColor: UIColor? {
76
+ didSet {
77
+ updateContent()
78
+ }
79
+ }
80
+
81
+ @objc var enableLatex: Bool = true {
82
+ didSet {
83
+ updateContent()
84
+ }
85
+ }
86
+
87
+ @objc var enableSyntaxHighlighting: Bool = true {
88
+ didSet {
89
+ updateContent()
90
+ }
91
+ }
92
+
93
+ @objc var syntaxTheme: String? {
94
+ didSet {
95
+ updateContent()
96
+ }
97
+ }
98
+
99
+ override init(frame: CGRect) {
100
+ super.init(frame: frame)
101
+ setupHostingController()
102
+ }
103
+
104
+ required init?(coder: NSCoder) {
105
+ fatalError("init(coder:) has not been implemented")
106
+ }
107
+
108
+ private func setupHostingController() {
109
+ let contentView = RNMarkdownViewContent(
110
+ markdown: markdown,
111
+ config: makeConfig()
112
+ )
113
+
114
+ let controller = UIHostingController(rootView: contentView)
115
+ controller.view.backgroundColor = .clear
116
+ controller.view.translatesAutoresizingMaskIntoConstraints = false
117
+
118
+ addSubview(controller.view)
119
+
120
+ NSLayoutConstraint.activate([
121
+ controller.view.topAnchor.constraint(equalTo: topAnchor),
122
+ controller.view.leadingAnchor.constraint(equalTo: leadingAnchor),
123
+ controller.view.trailingAnchor.constraint(equalTo: trailingAnchor),
124
+ controller.view.bottomAnchor.constraint(equalTo: bottomAnchor)
125
+ ])
126
+
127
+ hostingController = controller
128
+ }
129
+
130
+ private func makeConfig() -> MarkdownConfig {
131
+ return MarkdownConfig(
132
+ h1FontSize: CGFloat(truncating: h1FontSize),
133
+ h2FontSize: CGFloat(truncating: h2FontSize),
134
+ h3FontSize: CGFloat(truncating: h3FontSize),
135
+ fontFamily: fontFamily,
136
+ tintColor: tintColor.map { Color($0) },
137
+ codeBlockTintColor: codeBlockTintColor.map { Color($0) },
138
+ inlineCodeTintColor: inlineCodeTintColor.map { Color($0) },
139
+ quoteTintColor: quoteTintColor.map { Color($0) },
140
+ enableLatex: enableLatex,
141
+ enableSyntaxHighlighting: enableSyntaxHighlighting,
142
+ syntaxTheme: syntaxTheme
143
+ )
144
+ }
145
+
146
+ private func updateContent() {
147
+ hostingController?.rootView = RNMarkdownViewContent(
148
+ markdown: markdown,
149
+ config: makeConfig()
150
+ )
151
+ }
152
+
153
+ override func layoutSubviews() {
154
+ super.layoutSubviews()
155
+ hostingController?.view.frame = bounds
156
+ }
157
+ }
158
+
159
+ struct MarkdownConfig {
160
+ let h1FontSize: CGFloat
161
+ let h2FontSize: CGFloat
162
+ let h3FontSize: CGFloat
163
+ let fontFamily: String?
164
+ let tintColor: Color?
165
+ let codeBlockTintColor: Color?
166
+ let inlineCodeTintColor: Color?
167
+ let quoteTintColor: Color?
168
+ let enableLatex: Bool
169
+ let enableSyntaxHighlighting: Bool
170
+ let syntaxTheme: String?
171
+ }
172
+
173
+ struct RNMarkdownViewContent: View {
174
+ let markdown: String
175
+ let config: MarkdownConfig
176
+
177
+ var body: some View {
178
+ ScrollView {
179
+ VStack(alignment: .leading, spacing: 8) {
180
+ renderMarkdown(markdown)
181
+ }
182
+ .padding(8)
183
+ }
184
+ }
185
+
186
+ @ViewBuilder
187
+ private func renderMarkdown(_ text: String) -> some View {
188
+ let lines = text.components(separatedBy: .newlines)
189
+ ForEach(Array(lines.enumerated()), id: \.offset) { index, line in
190
+ renderLine(line)
191
+ }
192
+ }
193
+
194
+ @ViewBuilder
195
+ private func renderLine(_ line: String) -> some View {
196
+ if line.hasPrefix("# ") {
197
+ Text(line.dropFirst(2))
198
+ .font(.system(size: config.h1FontSize, weight: .bold))
199
+ .foregroundColor(config.tintColor ?? .primary)
200
+ } else if line.hasPrefix("## ") {
201
+ Text(line.dropFirst(3))
202
+ .font(.system(size: config.h2FontSize, weight: .bold))
203
+ .foregroundColor(config.tintColor ?? .primary)
204
+ } else if line.hasPrefix("### ") {
205
+ Text(line.dropFirst(4))
206
+ .font(.system(size: config.h3FontSize, weight: .semibold))
207
+ .foregroundColor(config.tintColor ?? .primary)
208
+ } else if line.hasPrefix("- ") || line.hasPrefix("* ") {
209
+ HStack(alignment: .top, spacing: 8) {
210
+ Text("•")
211
+ Text(line.dropFirst(2))
212
+ }
213
+ } else if !line.isEmpty {
214
+ Text(parseInlineMarkdown(line))
215
+ } else {
216
+ Text(" ")
217
+ .font(.system(size: 4))
218
+ }
219
+ }
220
+
221
+ private func parseInlineMarkdown(_ text: String) -> AttributedString {
222
+ var result = AttributedString(text)
223
+
224
+ // Bold **text**
225
+ if let range = text.range(of: "\\*\\*(.+?)\\*\\*", options: .regularExpression) {
226
+ let content = String(text[range]).replacingOccurrences(of: "**", with: "")
227
+ var attr = AttributedString(content)
228
+ attr.font = .boldSystemFont(ofSize: 16)
229
+ return attr
230
+ }
231
+
232
+ // Italic *text*
233
+ if let range = text.range(of: "\\*(.+?)\\*", options: .regularExpression) {
234
+ let content = String(text[range]).replacingOccurrences(of: "*", with: "")
235
+ var attr = AttributedString(content)
236
+ attr.font = .italicSystemFont(ofSize: 16)
237
+ return attr
238
+ }
239
+
240
+ // Code `text`
241
+ if let range = text.range(of: "`(.+?)`", options: .regularExpression) {
242
+ let content = String(text[range]).replacingOccurrences(of: "`", with: "")
243
+ var attr = AttributedString(content)
244
+ attr.font = .monospacedSystemFont(ofSize: 14, weight: .regular)
245
+ attr.foregroundColor = config.inlineCodeTintColor ?? .secondary
246
+ attr.backgroundColor = config.inlineCodeTintColor?.opacity(0.1) ?? Color.gray.opacity(0.1)
247
+ return attr
248
+ }
249
+
250
+ return result
251
+ }
252
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.MarkdownView = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _reactNative = require("react-native");
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ const LINKING_ERROR = `The package 'react-native-markdown-view' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
11
+ ios: "- You have run 'pod install'\n",
12
+ default: ''
13
+ }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
14
+ const ComponentName = 'RNMarkdownView';
15
+ const RNMarkdownViewNative = _reactNative.UIManager.getViewManagerConfig(ComponentName) != null ? (0, _reactNative.requireNativeComponent)(ComponentName) : () => {
16
+ throw new Error(LINKING_ERROR);
17
+ };
18
+ const MarkdownView = props => {
19
+ if (_reactNative.Platform.OS !== 'ios') {
20
+ console.warn('MarkdownView is currently only supported on iOS. Falling back to empty view.');
21
+ return null;
22
+ }
23
+ return /*#__PURE__*/_react.default.createElement(RNMarkdownViewNative, props);
24
+ };
25
+ exports.MarkdownView = MarkdownView;
26
+ var _default = exports.default = MarkdownView;
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","e","__esModule","default","LINKING_ERROR","Platform","select","ios","ComponentName","RNMarkdownViewNative","UIManager","getViewManagerConfig","requireNativeComponent","Error","MarkdownView","props","OS","console","warn","createElement","exports","_default"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAMsB,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEtB,MAAMG,aAAa,GACjB,qFAAqF,GACrFC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEJ,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAgEjC,MAAMK,aAAa,GAAG,gBAAgB;AAEtC,MAAMC,oBAAoB,GACxBC,sBAAS,CAACC,oBAAoB,CAACH,aAAa,CAAC,IAAI,IAAI,GACjD,IAAAI,mCAAsB,EAAoBJ,aAAa,CAAC,GACxD,MAAM;EACJ,MAAM,IAAIK,KAAK,CAACT,aAAa,CAAC;AAChC,CAAC;AAEA,MAAMU,YAAyC,GAAIC,KAAK,IAAK;EAClE,IAAIV,qBAAQ,CAACW,EAAE,KAAK,KAAK,EAAE;IACzBC,OAAO,CAACC,IAAI,CACV,8EACF,CAAC;IACD,OAAO,IAAI;EACb;EAEA,oBAAOrB,MAAA,CAAAM,OAAA,CAAAgB,aAAA,CAACV,oBAAoB,EAAKM,KAAQ,CAAC;AAC5C,CAAC;AAACK,OAAA,CAAAN,YAAA,GAAAA,YAAA;AAAA,IAAAO,QAAA,GAAAD,OAAA,CAAAjB,OAAA,GAEaW,YAAY","ignoreList":[]}
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { requireNativeComponent, UIManager, Platform } from 'react-native';
3
+ const LINKING_ERROR = `The package 'react-native-markdown-view' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
4
+ ios: "- You have run 'pod install'\n",
5
+ default: ''
6
+ }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
7
+ const ComponentName = 'RNMarkdownView';
8
+ const RNMarkdownViewNative = UIManager.getViewManagerConfig(ComponentName) != null ? requireNativeComponent(ComponentName) : () => {
9
+ throw new Error(LINKING_ERROR);
10
+ };
11
+ export const MarkdownView = props => {
12
+ if (Platform.OS !== 'ios') {
13
+ console.warn('MarkdownView is currently only supported on iOS. Falling back to empty view.');
14
+ return null;
15
+ }
16
+ return /*#__PURE__*/React.createElement(RNMarkdownViewNative, props);
17
+ };
18
+ export default MarkdownView;
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","requireNativeComponent","UIManager","Platform","LINKING_ERROR","select","ios","default","ComponentName","RNMarkdownViewNative","getViewManagerConfig","Error","MarkdownView","props","OS","console","warn","createElement"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SACEC,sBAAsB,EACtBC,SAAS,EACTC,QAAQ,QAGH,cAAc;AAErB,MAAMC,aAAa,GACjB,qFAAqF,GACrFD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAgEjC,MAAMC,aAAa,GAAG,gBAAgB;AAEtC,MAAMC,oBAAoB,GACxBP,SAAS,CAACQ,oBAAoB,CAACF,aAAa,CAAC,IAAI,IAAI,GACjDP,sBAAsB,CAAoBO,aAAa,CAAC,GACxD,MAAM;EACJ,MAAM,IAAIG,KAAK,CAACP,aAAa,CAAC;AAChC,CAAC;AAEP,OAAO,MAAMQ,YAAyC,GAAIC,KAAK,IAAK;EAClE,IAAIV,QAAQ,CAACW,EAAE,KAAK,KAAK,EAAE;IACzBC,OAAO,CAACC,IAAI,CACV,8EACF,CAAC;IACD,OAAO,IAAI;EACb;EAEA,oBAAOhB,KAAA,CAAAiB,aAAA,CAACR,oBAAoB,EAAKI,KAAQ,CAAC;AAC5C,CAAC;AAED,eAAeD,YAAY","ignoreList":[]}
@@ -0,0 +1,55 @@
1
+ import React from 'react';
2
+ import { ViewStyle, StyleProp } from 'react-native';
3
+ export interface MarkdownViewProps {
4
+ /**
5
+ * Markdown content to render
6
+ */
7
+ markdown: string;
8
+ /**
9
+ * Style for the container view
10
+ */
11
+ style?: StyleProp<ViewStyle>;
12
+ /**
13
+ * Font size for different heading levels
14
+ */
15
+ h1FontSize?: number;
16
+ h2FontSize?: number;
17
+ h3FontSize?: number;
18
+ h4FontSize?: number;
19
+ h5FontSize?: number;
20
+ h6FontSize?: number;
21
+ /**
22
+ * Base font family
23
+ */
24
+ fontFamily?: string;
25
+ /**
26
+ * Tint color for links and other interactive elements
27
+ */
28
+ tintColor?: string;
29
+ /**
30
+ * Code block tint color
31
+ */
32
+ codeBlockTintColor?: string;
33
+ /**
34
+ * Inline code tint color
35
+ */
36
+ inlineCodeTintColor?: string;
37
+ /**
38
+ * Quote block tint color
39
+ */
40
+ quoteTintColor?: string;
41
+ /**
42
+ * Enable LaTeX math rendering
43
+ */
44
+ enableLatex?: boolean;
45
+ /**
46
+ * Enable syntax highlighting for code blocks
47
+ */
48
+ enableSyntaxHighlighting?: boolean;
49
+ /**
50
+ * Syntax highlighting theme name
51
+ */
52
+ syntaxTheme?: string;
53
+ }
54
+ export declare const MarkdownView: React.FC<MarkdownViewProps>;
55
+ export default MarkdownView;
package/package.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "name": "react-native-swiftui-markdown",
3
+ "version": "0.1.0",
4
+ "description": "A lightweight React Native Markdown renderer with native iOS performance using SwiftUI",
5
+ "author": "tinglinzh",
6
+ "main": "lib/commonjs/index.js",
7
+ "module": "lib/module/index.js",
8
+ "types": "lib/typescript/index.d.ts",
9
+ "react-native": "src/index.tsx",
10
+ "source": "src/index.tsx",
11
+ "files": [
12
+ "src",
13
+ "lib",
14
+ "android",
15
+ "ios",
16
+ "cpp",
17
+ "*.podspec",
18
+ "!lib/typescript/example",
19
+ "!ios/build",
20
+ "!android/build",
21
+ "!android/gradle",
22
+ "!android/gradlew",
23
+ "!android/gradlew.bat",
24
+ "!android/local.properties",
25
+ "!**/__tests__",
26
+ "!**/__fixtures__",
27
+ "!**/__mocks__",
28
+ "!**/.*"
29
+ ],
30
+ "scripts": {
31
+ "test": "jest",
32
+ "typecheck": "tsc --noEmit",
33
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
34
+ "prepare": "bob build",
35
+ "release": "release-it",
36
+ "prepack": "bob build"
37
+ },
38
+ "keywords": [
39
+ "react-native",
40
+ "ios",
41
+ "markdown",
42
+ "swiftui",
43
+ "commonmark",
44
+ "latex",
45
+ "syntax-highlighting"
46
+ ],
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://github.com/tinglinzh/react-native-swiftui-markdown.git"
50
+ },
51
+ "license": "MIT",
52
+ "bugs": {
53
+ "url": "https://github.com/tinglinzh/react-native-swiftui-markdown/issues"
54
+ },
55
+ "homepage": "https://github.com/tinglinzh/react-native-swiftui-markdown#readme",
56
+ "publishConfig": {
57
+ "registry": "https://registry.npmjs.org/"
58
+ },
59
+ "devDependencies": {
60
+ "@react-native/eslint-config": "^0.73.2",
61
+ "@types/react": "^18.3.28",
62
+ "@types/react-native": "^0.73.0",
63
+ "eslint": "^8.57.1",
64
+ "prettier": "^3.8.1",
65
+ "react": "^18.2.0",
66
+ "react-native": "^0.73.0",
67
+ "react-native-builder-bob": "^0.23.2",
68
+ "release-it": "^16.3.0",
69
+ "typescript": "^5.9.3"
70
+ },
71
+ "peerDependencies": {
72
+ "react": "*",
73
+ "react-native": "*"
74
+ },
75
+ "engines": {
76
+ "node": ">= 18.0.0"
77
+ },
78
+ "react-native-builder-bob": {
79
+ "source": "src",
80
+ "output": "lib",
81
+ "targets": [
82
+ "commonjs",
83
+ "module"
84
+ ]
85
+ }
86
+ }
@@ -0,0 +1,21 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "react-native-markdown-view"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => "15.0" }
14
+ s.source = { :git => "https://github.com/yourusername/react-native-markdown-view.git", :tag => "#{s.version}" }
15
+
16
+ s.source_files = "ios/**/*.{h,m,mm,swift}"
17
+
18
+ s.dependency "React-Core"
19
+
20
+ s.swift_version = '5.5'
21
+ end
package/src/index.tsx ADDED
@@ -0,0 +1,98 @@
1
+ import React from 'react';
2
+ import {
3
+ requireNativeComponent,
4
+ UIManager,
5
+ Platform,
6
+ ViewStyle,
7
+ StyleProp,
8
+ } from 'react-native';
9
+
10
+ const LINKING_ERROR =
11
+ `The package 'react-native-markdown-view' doesn't seem to be linked. Make sure: \n\n` +
12
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
13
+ '- You rebuilt the app after installing the package\n' +
14
+ '- You are not using Expo Go\n';
15
+
16
+ export interface MarkdownViewProps {
17
+ /**
18
+ * Markdown content to render
19
+ */
20
+ markdown: string;
21
+
22
+ /**
23
+ * Style for the container view
24
+ */
25
+ style?: StyleProp<ViewStyle>;
26
+
27
+ /**
28
+ * Font size for different heading levels
29
+ */
30
+ h1FontSize?: number;
31
+ h2FontSize?: number;
32
+ h3FontSize?: number;
33
+ h4FontSize?: number;
34
+ h5FontSize?: number;
35
+ h6FontSize?: number;
36
+
37
+ /**
38
+ * Base font family
39
+ */
40
+ fontFamily?: string;
41
+
42
+ /**
43
+ * Tint color for links and other interactive elements
44
+ */
45
+ tintColor?: string;
46
+
47
+ /**
48
+ * Code block tint color
49
+ */
50
+ codeBlockTintColor?: string;
51
+
52
+ /**
53
+ * Inline code tint color
54
+ */
55
+ inlineCodeTintColor?: string;
56
+
57
+ /**
58
+ * Quote block tint color
59
+ */
60
+ quoteTintColor?: string;
61
+
62
+ /**
63
+ * Enable LaTeX math rendering
64
+ */
65
+ enableLatex?: boolean;
66
+
67
+ /**
68
+ * Enable syntax highlighting for code blocks
69
+ */
70
+ enableSyntaxHighlighting?: boolean;
71
+
72
+ /**
73
+ * Syntax highlighting theme name
74
+ */
75
+ syntaxTheme?: string;
76
+ }
77
+
78
+ const ComponentName = 'RNMarkdownView';
79
+
80
+ const RNMarkdownViewNative =
81
+ UIManager.getViewManagerConfig(ComponentName) != null
82
+ ? requireNativeComponent<MarkdownViewProps>(ComponentName)
83
+ : () => {
84
+ throw new Error(LINKING_ERROR);
85
+ };
86
+
87
+ export const MarkdownView: React.FC<MarkdownViewProps> = (props) => {
88
+ if (Platform.OS !== 'ios') {
89
+ console.warn(
90
+ 'MarkdownView is currently only supported on iOS. Falling back to empty view.'
91
+ );
92
+ return null;
93
+ }
94
+
95
+ return <RNMarkdownViewNative {...props} />;
96
+ };
97
+
98
+ export default MarkdownView;