react-native-nitro-markdown 0.4.3 → 0.5.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 +417 -25
- package/android/src/main/java/com/margelo/nitro/com/nitromarkdown/HybridMarkdownSession.kt +46 -8
- package/android/src/main/java/com/nitromarkdown/NitroMarkdownPackage.kt +2 -1
- package/cpp/bindings/HybridMarkdownParser.cpp +216 -66
- package/cpp/bindings/HybridMarkdownParser.hpp +2 -0
- package/ios/HybridMarkdownSession.swift +51 -7
- package/lib/commonjs/MarkdownContext.js.map +1 -1
- package/lib/commonjs/headless.js +61 -5
- package/lib/commonjs/headless.js.map +1 -1
- package/lib/commonjs/index.js +9 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/markdown-stream.js +107 -13
- package/lib/commonjs/markdown-stream.js.map +1 -1
- package/lib/commonjs/markdown.js +191 -26
- package/lib/commonjs/markdown.js.map +1 -1
- package/lib/commonjs/renderers/code.js +21 -2
- package/lib/commonjs/renderers/code.js.map +1 -1
- package/lib/commonjs/renderers/table/cell-content.js +32 -0
- package/lib/commonjs/renderers/table/cell-content.js.map +1 -0
- package/lib/commonjs/renderers/table/index.js +310 -0
- package/lib/commonjs/renderers/table/index.js.map +1 -0
- package/lib/commonjs/renderers/table/table-reducer.js +29 -0
- package/lib/commonjs/renderers/table/table-reducer.js.map +1 -0
- package/lib/commonjs/renderers/table/table-utils.js +68 -0
- package/lib/commonjs/renderers/table/table-utils.js.map +1 -0
- package/lib/commonjs/renderers/table/types.js +6 -0
- package/lib/commonjs/renderers/table/types.js.map +1 -0
- package/lib/commonjs/renderers/table.js +6 -306
- package/lib/commonjs/renderers/table.js.map +1 -1
- package/lib/commonjs/theme.js +10 -1
- package/lib/commonjs/theme.js.map +1 -1
- package/lib/commonjs/use-markdown-stream.js +9 -1
- package/lib/commonjs/use-markdown-stream.js.map +1 -1
- package/lib/commonjs/utils/code-highlight.js +101 -0
- package/lib/commonjs/utils/code-highlight.js.map +1 -0
- package/lib/commonjs/utils/incremental-ast.js +153 -0
- package/lib/commonjs/utils/incremental-ast.js.map +1 -0
- package/lib/module/MarkdownContext.js.map +1 -1
- package/lib/module/headless.js +56 -4
- package/lib/module/headless.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/markdown-stream.js +108 -14
- package/lib/module/markdown-stream.js.map +1 -1
- package/lib/module/markdown.js +193 -28
- package/lib/module/markdown.js.map +1 -1
- package/lib/module/renderers/code.js +21 -2
- package/lib/module/renderers/code.js.map +1 -1
- package/lib/module/renderers/table/cell-content.js +27 -0
- package/lib/module/renderers/table/cell-content.js.map +1 -0
- package/lib/module/renderers/table/index.js +305 -0
- package/lib/module/renderers/table/index.js.map +1 -0
- package/lib/module/renderers/table/table-reducer.js +24 -0
- package/lib/module/renderers/table/table-reducer.js.map +1 -0
- package/lib/module/renderers/table/table-utils.js +62 -0
- package/lib/module/renderers/table/table-utils.js.map +1 -0
- package/lib/module/renderers/table/types.js +4 -0
- package/lib/module/renderers/table/types.js.map +1 -0
- package/lib/module/renderers/table.js +1 -305
- package/lib/module/renderers/table.js.map +1 -1
- package/lib/module/theme.js +10 -1
- package/lib/module/theme.js.map +1 -1
- package/lib/module/use-markdown-stream.js +9 -1
- package/lib/module/use-markdown-stream.js.map +1 -1
- package/lib/module/utils/code-highlight.js +97 -0
- package/lib/module/utils/code-highlight.js.map +1 -0
- package/lib/module/utils/incremental-ast.js +147 -0
- package/lib/module/utils/incremental-ast.js.map +1 -0
- package/lib/typescript/commonjs/Markdown.nitro.d.ts +2 -0
- package/lib/typescript/commonjs/Markdown.nitro.d.ts.map +1 -1
- package/lib/typescript/commonjs/MarkdownContext.d.ts +6 -0
- package/lib/typescript/commonjs/MarkdownContext.d.ts.map +1 -1
- package/lib/typescript/commonjs/headless.d.ts +18 -0
- package/lib/typescript/commonjs/headless.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +4 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/markdown-stream.d.ts +6 -1
- package/lib/typescript/commonjs/markdown-stream.d.ts.map +1 -1
- package/lib/typescript/commonjs/markdown.d.ts +77 -1
- package/lib/typescript/commonjs/markdown.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/code.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/table/cell-content.d.ts +15 -0
- package/lib/typescript/commonjs/renderers/table/cell-content.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/table/index.d.ts +11 -0
- package/lib/typescript/commonjs/renderers/table/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/table/table-reducer.d.ts +5 -0
- package/lib/typescript/commonjs/renderers/table/table-reducer.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/table/table-utils.d.ts +10 -0
- package/lib/typescript/commonjs/renderers/table/table-utils.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/table/types.d.ts +24 -0
- package/lib/typescript/commonjs/renderers/table/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/table.d.ts +1 -11
- package/lib/typescript/commonjs/renderers/table.d.ts.map +1 -1
- package/lib/typescript/commonjs/specs/MarkdownSession.nitro.d.ts +14 -2
- package/lib/typescript/commonjs/specs/MarkdownSession.nitro.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme.d.ts +18 -2
- package/lib/typescript/commonjs/theme.d.ts.map +1 -1
- package/lib/typescript/commonjs/use-markdown-stream.d.ts +4 -0
- package/lib/typescript/commonjs/use-markdown-stream.d.ts.map +1 -1
- package/lib/typescript/commonjs/utils/code-highlight.d.ts +8 -0
- package/lib/typescript/commonjs/utils/code-highlight.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/incremental-ast.d.ts +12 -0
- package/lib/typescript/commonjs/utils/incremental-ast.d.ts.map +1 -0
- package/lib/typescript/module/Markdown.nitro.d.ts +2 -0
- package/lib/typescript/module/Markdown.nitro.d.ts.map +1 -1
- package/lib/typescript/module/MarkdownContext.d.ts +6 -0
- package/lib/typescript/module/MarkdownContext.d.ts.map +1 -1
- package/lib/typescript/module/headless.d.ts +18 -0
- package/lib/typescript/module/headless.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +4 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/markdown-stream.d.ts +6 -1
- package/lib/typescript/module/markdown-stream.d.ts.map +1 -1
- package/lib/typescript/module/markdown.d.ts +77 -1
- package/lib/typescript/module/markdown.d.ts.map +1 -1
- package/lib/typescript/module/renderers/code.d.ts.map +1 -1
- package/lib/typescript/module/renderers/table/cell-content.d.ts +15 -0
- package/lib/typescript/module/renderers/table/cell-content.d.ts.map +1 -0
- package/lib/typescript/module/renderers/table/index.d.ts +11 -0
- package/lib/typescript/module/renderers/table/index.d.ts.map +1 -0
- package/lib/typescript/module/renderers/table/table-reducer.d.ts +5 -0
- package/lib/typescript/module/renderers/table/table-reducer.d.ts.map +1 -0
- package/lib/typescript/module/renderers/table/table-utils.d.ts +10 -0
- package/lib/typescript/module/renderers/table/table-utils.d.ts.map +1 -0
- package/lib/typescript/module/renderers/table/types.d.ts +24 -0
- package/lib/typescript/module/renderers/table/types.d.ts.map +1 -0
- package/lib/typescript/module/renderers/table.d.ts +1 -11
- package/lib/typescript/module/renderers/table.d.ts.map +1 -1
- package/lib/typescript/module/specs/MarkdownSession.nitro.d.ts +14 -2
- package/lib/typescript/module/specs/MarkdownSession.nitro.d.ts.map +1 -1
- package/lib/typescript/module/theme.d.ts +18 -2
- package/lib/typescript/module/theme.d.ts.map +1 -1
- package/lib/typescript/module/use-markdown-stream.d.ts +4 -0
- package/lib/typescript/module/use-markdown-stream.d.ts.map +1 -1
- package/lib/typescript/module/utils/code-highlight.d.ts +8 -0
- package/lib/typescript/module/utils/code-highlight.d.ts.map +1 -0
- package/lib/typescript/module/utils/incremental-ast.d.ts +12 -0
- package/lib/typescript/module/utils/incremental-ast.d.ts.map +1 -0
- package/nitrogen/generated/android/NitroMarkdownOnLoad.cpp +38 -26
- package/nitrogen/generated/android/NitroMarkdownOnLoad.hpp +13 -4
- package/nitrogen/generated/android/c++/JFunc_void_double_double.hpp +75 -0
- package/nitrogen/generated/android/c++/JHybridMarkdownSessionSpec.cpp +49 -34
- package/nitrogen/generated/android/c++/JHybridMarkdownSessionSpec.hpp +25 -24
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitromarkdown/Func_void_double_double.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitromarkdown/HybridMarkdownSessionSpec.kt +34 -21
- package/nitrogen/generated/ios/NitroMarkdown-Swift-Cxx-Bridge.cpp +8 -0
- package/nitrogen/generated/ios/NitroMarkdown-Swift-Cxx-Bridge.hpp +31 -0
- package/nitrogen/generated/ios/c++/HybridMarkdownSessionSpecSwift.hpp +34 -2
- package/nitrogen/generated/ios/swift/Func_void_double_double.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridMarkdownSessionSpec.swift +6 -2
- package/nitrogen/generated/ios/swift/HybridMarkdownSessionSpec_cxx.swift +57 -9
- package/nitrogen/generated/shared/c++/HybridMarkdownParserSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridMarkdownParserSpec.hpp +2 -0
- package/nitrogen/generated/shared/c++/HybridMarkdownSessionSpec.cpp +4 -0
- package/nitrogen/generated/shared/c++/HybridMarkdownSessionSpec.hpp +6 -2
- package/package.json +9 -5
- package/react-native-nitro-markdown.podspec +1 -1
- package/src/Markdown.nitro.ts +2 -0
- package/src/MarkdownContext.ts +6 -0
- package/src/headless.ts +54 -4
- package/src/index.ts +10 -0
- package/src/markdown-stream.tsx +163 -15
- package/src/markdown.tsx +381 -26
- package/src/renderers/code.tsx +32 -3
- package/src/renderers/table/cell-content.tsx +38 -0
- package/src/renderers/table/index.tsx +419 -0
- package/src/renderers/table/table-reducer.ts +36 -0
- package/src/renderers/table/table-utils.ts +81 -0
- package/src/renderers/table/types.ts +24 -0
- package/src/renderers/table.tsx +1 -401
- package/src/specs/MarkdownSession.nitro.ts +16 -2
- package/src/theme.ts +29 -1
- package/src/use-markdown-stream.ts +10 -0
- package/src/utils/code-highlight.ts +102 -0
- package/src/utils/incremental-ast.ts +224 -0
|
@@ -72,11 +72,13 @@ namespace margelo::nitro::Markdown {
|
|
|
72
72
|
|
|
73
73
|
public:
|
|
74
74
|
// Methods
|
|
75
|
-
inline
|
|
75
|
+
inline double append(const std::string& chunk) override {
|
|
76
76
|
auto __result = _swiftPart.append(chunk);
|
|
77
77
|
if (__result.hasError()) [[unlikely]] {
|
|
78
78
|
std::rethrow_exception(__result.error());
|
|
79
79
|
}
|
|
80
|
+
auto __value = std::move(__result.value());
|
|
81
|
+
return __value;
|
|
80
82
|
}
|
|
81
83
|
inline void clear() override {
|
|
82
84
|
auto __result = _swiftPart.clear();
|
|
@@ -92,7 +94,23 @@ namespace margelo::nitro::Markdown {
|
|
|
92
94
|
auto __value = std::move(__result.value());
|
|
93
95
|
return __value;
|
|
94
96
|
}
|
|
95
|
-
inline
|
|
97
|
+
inline double getLength() override {
|
|
98
|
+
auto __result = _swiftPart.getLength();
|
|
99
|
+
if (__result.hasError()) [[unlikely]] {
|
|
100
|
+
std::rethrow_exception(__result.error());
|
|
101
|
+
}
|
|
102
|
+
auto __value = std::move(__result.value());
|
|
103
|
+
return __value;
|
|
104
|
+
}
|
|
105
|
+
inline std::string getTextRange(double from, double to) override {
|
|
106
|
+
auto __result = _swiftPart.getTextRange(std::forward<decltype(from)>(from), std::forward<decltype(to)>(to));
|
|
107
|
+
if (__result.hasError()) [[unlikely]] {
|
|
108
|
+
std::rethrow_exception(__result.error());
|
|
109
|
+
}
|
|
110
|
+
auto __value = std::move(__result.value());
|
|
111
|
+
return __value;
|
|
112
|
+
}
|
|
113
|
+
inline std::function<void()> addListener(const std::function<void(double /* from */, double /* to */)>& listener) override {
|
|
96
114
|
auto __result = _swiftPart.addListener(listener);
|
|
97
115
|
if (__result.hasError()) [[unlikely]] {
|
|
98
116
|
std::rethrow_exception(__result.error());
|
|
@@ -100,6 +118,20 @@ namespace margelo::nitro::Markdown {
|
|
|
100
118
|
auto __value = std::move(__result.value());
|
|
101
119
|
return __value;
|
|
102
120
|
}
|
|
121
|
+
inline void reset(const std::string& text) override {
|
|
122
|
+
auto __result = _swiftPart.reset(text);
|
|
123
|
+
if (__result.hasError()) [[unlikely]] {
|
|
124
|
+
std::rethrow_exception(__result.error());
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
inline double replace(double from, double to, const std::string& text) override {
|
|
128
|
+
auto __result = _swiftPart.replace(std::forward<decltype(from)>(from), std::forward<decltype(to)>(to), text);
|
|
129
|
+
if (__result.hasError()) [[unlikely]] {
|
|
130
|
+
std::rethrow_exception(__result.error());
|
|
131
|
+
}
|
|
132
|
+
auto __value = std::move(__result.value());
|
|
133
|
+
return __value;
|
|
134
|
+
}
|
|
103
135
|
|
|
104
136
|
private:
|
|
105
137
|
NitroMarkdown::HybridMarkdownSessionSpec_cxx _swiftPart;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_double_double.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import NitroModules
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wraps a Swift `(_ from: Double, _ to: Double) -> Void` as a class.
|
|
12
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
13
|
+
*/
|
|
14
|
+
public final class Func_void_double_double {
|
|
15
|
+
public typealias bridge = margelo.nitro.Markdown.bridge.swift
|
|
16
|
+
|
|
17
|
+
private let closure: (_ from: Double, _ to: Double) -> Void
|
|
18
|
+
|
|
19
|
+
public init(_ closure: @escaping (_ from: Double, _ to: Double) -> Void) {
|
|
20
|
+
self.closure = closure
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@inline(__always)
|
|
24
|
+
public func call(from: Double, to: Double) -> Void {
|
|
25
|
+
self.closure(from, to)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
30
|
+
* This acquires one additional strong reference on the object!
|
|
31
|
+
*/
|
|
32
|
+
@inline(__always)
|
|
33
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
34
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Casts an unsafe pointer to a `Func_void_double_double`.
|
|
39
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_double_double>`.
|
|
40
|
+
* This removes one strong reference from the object!
|
|
41
|
+
*/
|
|
42
|
+
@inline(__always)
|
|
43
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_double_double {
|
|
44
|
+
return Unmanaged<Func_void_double_double>.fromOpaque(pointer).takeRetainedValue()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -13,10 +13,14 @@ public protocol HybridMarkdownSessionSpec_protocol: HybridObject {
|
|
|
13
13
|
var highlightPosition: Double { get set }
|
|
14
14
|
|
|
15
15
|
// Methods
|
|
16
|
-
func append(chunk: String) throws ->
|
|
16
|
+
func append(chunk: String) throws -> Double
|
|
17
17
|
func clear() throws -> Void
|
|
18
18
|
func getAllText() throws -> String
|
|
19
|
-
func
|
|
19
|
+
func getLength() throws -> Double
|
|
20
|
+
func getTextRange(from: Double, to: Double) throws -> String
|
|
21
|
+
func addListener(listener: @escaping (_ from: Double, _ to: Double) -> Void) throws -> () -> Void
|
|
22
|
+
func reset(text: String) throws -> Void
|
|
23
|
+
func replace(from: Double, to: Double, text: String) throws -> Double
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
public extension HybridMarkdownSessionSpec_protocol {
|
|
@@ -134,13 +134,14 @@ open class HybridMarkdownSessionSpec_cxx {
|
|
|
134
134
|
|
|
135
135
|
// Methods
|
|
136
136
|
@inline(__always)
|
|
137
|
-
public final func append(chunk: std.string) -> bridge.
|
|
137
|
+
public final func append(chunk: std.string) -> bridge.Result_double_ {
|
|
138
138
|
do {
|
|
139
|
-
try self.__implementation.append(chunk: String(chunk))
|
|
140
|
-
|
|
139
|
+
let __result = try self.__implementation.append(chunk: String(chunk))
|
|
140
|
+
let __resultCpp = __result
|
|
141
|
+
return bridge.create_Result_double_(__resultCpp)
|
|
141
142
|
} catch (let __error) {
|
|
142
143
|
let __exceptionPtr = __error.toCpp()
|
|
143
|
-
return bridge.
|
|
144
|
+
return bridge.create_Result_double_(__exceptionPtr)
|
|
144
145
|
}
|
|
145
146
|
}
|
|
146
147
|
|
|
@@ -168,12 +169,36 @@ open class HybridMarkdownSessionSpec_cxx {
|
|
|
168
169
|
}
|
|
169
170
|
|
|
170
171
|
@inline(__always)
|
|
171
|
-
public final func
|
|
172
|
+
public final func getLength() -> bridge.Result_double_ {
|
|
173
|
+
do {
|
|
174
|
+
let __result = try self.__implementation.getLength()
|
|
175
|
+
let __resultCpp = __result
|
|
176
|
+
return bridge.create_Result_double_(__resultCpp)
|
|
177
|
+
} catch (let __error) {
|
|
178
|
+
let __exceptionPtr = __error.toCpp()
|
|
179
|
+
return bridge.create_Result_double_(__exceptionPtr)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
@inline(__always)
|
|
184
|
+
public final func getTextRange(from: Double, to: Double) -> bridge.Result_std__string_ {
|
|
172
185
|
do {
|
|
173
|
-
let __result = try self.__implementation.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
186
|
+
let __result = try self.__implementation.getTextRange(from: from, to: to)
|
|
187
|
+
let __resultCpp = std.string(__result)
|
|
188
|
+
return bridge.create_Result_std__string_(__resultCpp)
|
|
189
|
+
} catch (let __error) {
|
|
190
|
+
let __exceptionPtr = __error.toCpp()
|
|
191
|
+
return bridge.create_Result_std__string_(__exceptionPtr)
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
@inline(__always)
|
|
196
|
+
public final func addListener(listener: bridge.Func_void_double_double) -> bridge.Result_std__function_void____ {
|
|
197
|
+
do {
|
|
198
|
+
let __result = try self.__implementation.addListener(listener: { () -> (Double, Double) -> Void in
|
|
199
|
+
let __wrappedFunction = bridge.wrap_Func_void_double_double(listener)
|
|
200
|
+
return { (__from: Double, __to: Double) -> Void in
|
|
201
|
+
__wrappedFunction.call(__from, __to)
|
|
177
202
|
}
|
|
178
203
|
}())
|
|
179
204
|
let __resultCpp = { () -> bridge.Func_void in
|
|
@@ -186,4 +211,27 @@ open class HybridMarkdownSessionSpec_cxx {
|
|
|
186
211
|
return bridge.create_Result_std__function_void____(__exceptionPtr)
|
|
187
212
|
}
|
|
188
213
|
}
|
|
214
|
+
|
|
215
|
+
@inline(__always)
|
|
216
|
+
public final func reset(text: std.string) -> bridge.Result_void_ {
|
|
217
|
+
do {
|
|
218
|
+
try self.__implementation.reset(text: String(text))
|
|
219
|
+
return bridge.create_Result_void_()
|
|
220
|
+
} catch (let __error) {
|
|
221
|
+
let __exceptionPtr = __error.toCpp()
|
|
222
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
@inline(__always)
|
|
227
|
+
public final func replace(from: Double, to: Double, text: std.string) -> bridge.Result_double_ {
|
|
228
|
+
do {
|
|
229
|
+
let __result = try self.__implementation.replace(from: from, to: to, text: String(text))
|
|
230
|
+
let __resultCpp = __result
|
|
231
|
+
return bridge.create_Result_double_(__resultCpp)
|
|
232
|
+
} catch (let __error) {
|
|
233
|
+
let __exceptionPtr = __error.toCpp()
|
|
234
|
+
return bridge.create_Result_double_(__exceptionPtr)
|
|
235
|
+
}
|
|
236
|
+
}
|
|
189
237
|
}
|
|
@@ -16,6 +16,8 @@ namespace margelo::nitro::Markdown {
|
|
|
16
16
|
registerHybrids(this, [](Prototype& prototype) {
|
|
17
17
|
prototype.registerHybridMethod("parse", &HybridMarkdownParserSpec::parse);
|
|
18
18
|
prototype.registerHybridMethod("parseWithOptions", &HybridMarkdownParserSpec::parseWithOptions);
|
|
19
|
+
prototype.registerHybridMethod("extractPlainText", &HybridMarkdownParserSpec::extractPlainText);
|
|
20
|
+
prototype.registerHybridMethod("extractPlainTextWithOptions", &HybridMarkdownParserSpec::extractPlainTextWithOptions);
|
|
19
21
|
});
|
|
20
22
|
}
|
|
21
23
|
|
|
@@ -52,6 +52,8 @@ namespace margelo::nitro::Markdown {
|
|
|
52
52
|
// Methods
|
|
53
53
|
virtual std::string parse(const std::string& text) = 0;
|
|
54
54
|
virtual std::string parseWithOptions(const std::string& text, const ParserOptions& options) = 0;
|
|
55
|
+
virtual std::string extractPlainText(const std::string& text) = 0;
|
|
56
|
+
virtual std::string extractPlainTextWithOptions(const std::string& text, const ParserOptions& options) = 0;
|
|
55
57
|
|
|
56
58
|
protected:
|
|
57
59
|
// Hybrid Setup
|
|
@@ -19,7 +19,11 @@ namespace margelo::nitro::Markdown {
|
|
|
19
19
|
prototype.registerHybridMethod("append", &HybridMarkdownSessionSpec::append);
|
|
20
20
|
prototype.registerHybridMethod("clear", &HybridMarkdownSessionSpec::clear);
|
|
21
21
|
prototype.registerHybridMethod("getAllText", &HybridMarkdownSessionSpec::getAllText);
|
|
22
|
+
prototype.registerHybridMethod("getLength", &HybridMarkdownSessionSpec::getLength);
|
|
23
|
+
prototype.registerHybridMethod("getTextRange", &HybridMarkdownSessionSpec::getTextRange);
|
|
22
24
|
prototype.registerHybridMethod("addListener", &HybridMarkdownSessionSpec::addListener);
|
|
25
|
+
prototype.registerHybridMethod("reset", &HybridMarkdownSessionSpec::reset);
|
|
26
|
+
prototype.registerHybridMethod("replace", &HybridMarkdownSessionSpec::replace);
|
|
23
27
|
});
|
|
24
28
|
}
|
|
25
29
|
|
|
@@ -50,10 +50,14 @@ namespace margelo::nitro::Markdown {
|
|
|
50
50
|
|
|
51
51
|
public:
|
|
52
52
|
// Methods
|
|
53
|
-
virtual
|
|
53
|
+
virtual double append(const std::string& chunk) = 0;
|
|
54
54
|
virtual void clear() = 0;
|
|
55
55
|
virtual std::string getAllText() = 0;
|
|
56
|
-
virtual
|
|
56
|
+
virtual double getLength() = 0;
|
|
57
|
+
virtual std::string getTextRange(double from, double to) = 0;
|
|
58
|
+
virtual std::function<void()> addListener(const std::function<void(double /* from */, double /* to */)>& listener) = 0;
|
|
59
|
+
virtual void reset(const std::string& text) = 0;
|
|
60
|
+
virtual double replace(double from, double to, const std::string& text) = 0;
|
|
57
61
|
|
|
58
62
|
protected:
|
|
59
63
|
// Hybrid Setup
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-markdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "High-performance Markdown parser for React Native using Nitro Modules and md4c",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"!scripts"
|
|
51
51
|
],
|
|
52
52
|
"scripts": {
|
|
53
|
-
"prebuild": "
|
|
53
|
+
"prebuild": "bun run codegen",
|
|
54
54
|
"build": "bob build",
|
|
55
55
|
"clean": "rimraf lib nitrogen/generated",
|
|
56
56
|
"codegen": "nitrogen --logLevel=\"debug\"",
|
|
@@ -61,7 +61,8 @@
|
|
|
61
61
|
"benchmark": "node ../../scripts/benchmark-comparison.js",
|
|
62
62
|
"prepack": "node -e \"const fs=require('fs'); fs.copyFileSync('../../README.md','./README.md'); fs.copyFileSync('../../LICENSE','./LICENSE')\"",
|
|
63
63
|
"postpack": "node -e \"const fs=require('fs'); if(fs.existsSync('./README.md'))fs.unlinkSync('./README.md'); if(fs.existsSync('./LICENSE'))fs.unlinkSync('./LICENSE')\"",
|
|
64
|
-
"test:cpp": "node scripts/test-cpp.js"
|
|
64
|
+
"test:cpp": "node scripts/test-cpp.js",
|
|
65
|
+
"size": "size-limit"
|
|
65
66
|
},
|
|
66
67
|
"keywords": [
|
|
67
68
|
"react-native",
|
|
@@ -87,16 +88,19 @@
|
|
|
87
88
|
"registry": "https://registry.npmjs.org/"
|
|
88
89
|
},
|
|
89
90
|
"devDependencies": {
|
|
91
|
+
"@size-limit/preset-small-lib": "^11.0.0",
|
|
90
92
|
"@types/react": "^19.2.14",
|
|
91
93
|
"@types/react-native": "^0.73.0",
|
|
94
|
+
"@types/react-test-renderer": "^19.1.0",
|
|
92
95
|
"react-native-builder-bob": "^0.40.18",
|
|
93
|
-
"react-
|
|
96
|
+
"react-test-renderer": "^19.2.4",
|
|
97
|
+
"size-limit": "^11.0.0",
|
|
94
98
|
"typescript": "^5.9.3"
|
|
95
99
|
},
|
|
96
100
|
"peerDependencies": {
|
|
97
101
|
"react": "*",
|
|
98
102
|
"react-native": ">=0.75.0",
|
|
99
|
-
"react-native-nitro-modules": "
|
|
103
|
+
"react-native-nitro-modules": ">=0.35.0",
|
|
100
104
|
"react-native-mathjax-svg": ">=0.9.0",
|
|
101
105
|
"react-native-svg": ">=13.0.0"
|
|
102
106
|
},
|
|
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
|
|
|
10
10
|
s.license = package["license"]
|
|
11
11
|
s.authors = package["author"]
|
|
12
12
|
|
|
13
|
-
s.platforms = { :ios => "
|
|
13
|
+
s.platforms = { :ios => "15.1" }
|
|
14
14
|
s.source = { :git => "https://github.com/JoaoPauloCMarra/react-native-nitro-markdown.git", :tag => "#{s.version}" }
|
|
15
15
|
s.module_name = "NitroMarkdown"
|
|
16
16
|
|
package/src/Markdown.nitro.ts
CHANGED
|
@@ -11,4 +11,6 @@ export interface MarkdownParser extends HybridObject<{
|
|
|
11
11
|
}> {
|
|
12
12
|
parse(text: string): string;
|
|
13
13
|
parseWithOptions(text: string, options: ParserOptions): string;
|
|
14
|
+
extractPlainText(text: string): string;
|
|
15
|
+
extractPlainTextWithOptions(text: string, options: ParserOptions): string;
|
|
14
16
|
}
|
package/src/MarkdownContext.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type NodeStyleOverrides,
|
|
12
12
|
type StylingStrategy,
|
|
13
13
|
} from "./theme";
|
|
14
|
+
import type { CodeHighlighter } from "./utils/code-highlight";
|
|
14
15
|
|
|
15
16
|
export type NodeRendererProps = {
|
|
16
17
|
node: MarkdownNode;
|
|
@@ -91,6 +92,11 @@ export type MarkdownContextValue = {
|
|
|
91
92
|
styles?: NodeStyleOverrides;
|
|
92
93
|
stylingStrategy: StylingStrategy;
|
|
93
94
|
onLinkPress?: LinkPressHandler;
|
|
95
|
+
highlightCode?: boolean | CodeHighlighter;
|
|
96
|
+
tableOptions?: {
|
|
97
|
+
minColumnWidth?: number;
|
|
98
|
+
measurementStabilizeMs?: number;
|
|
99
|
+
};
|
|
94
100
|
};
|
|
95
101
|
|
|
96
102
|
export const MarkdownContext = createContext<MarkdownContextValue>({
|
package/src/headless.ts
CHANGED
|
@@ -71,6 +71,10 @@ export type MarkdownNode = {
|
|
|
71
71
|
isHeader?: boolean;
|
|
72
72
|
/** Text alignment for table cells: 'left', 'center', or 'right'. */
|
|
73
73
|
align?: string;
|
|
74
|
+
/** Source start offset in original markdown text (when provided by native parser). */
|
|
75
|
+
beg?: number;
|
|
76
|
+
/** Source end offset in original markdown text (when provided by native parser). */
|
|
77
|
+
end?: number;
|
|
74
78
|
/** Nested child nodes for hierarchical elements like paragraphs, lists, and tables. */
|
|
75
79
|
children?: MarkdownNode[];
|
|
76
80
|
};
|
|
@@ -84,8 +88,12 @@ export const MarkdownParserModule =
|
|
|
84
88
|
* @returns The root node of the parsed AST
|
|
85
89
|
*/
|
|
86
90
|
export function parseMarkdown(text: string): MarkdownNode {
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
if (typeof MarkdownParserModule.parse === "function") {
|
|
92
|
+
const jsonStr = MarkdownParserModule.parse(text);
|
|
93
|
+
return JSON.parse(jsonStr) as MarkdownNode;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return { type: "document", children: [] };
|
|
89
97
|
}
|
|
90
98
|
|
|
91
99
|
/**
|
|
@@ -98,8 +106,38 @@ export function parseMarkdownWithOptions(
|
|
|
98
106
|
text: string,
|
|
99
107
|
options: ParserOptions,
|
|
100
108
|
): MarkdownNode {
|
|
101
|
-
|
|
102
|
-
|
|
109
|
+
if (typeof MarkdownParserModule.parseWithOptions === "function") {
|
|
110
|
+
const jsonStr = MarkdownParserModule.parseWithOptions(text, options);
|
|
111
|
+
return JSON.parse(jsonStr) as MarkdownNode;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return { type: "document", children: [] };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Parse markdown and return flattened plain text directly from native parser.
|
|
119
|
+
* Useful for search/indexing flows that don't need full AST rendering.
|
|
120
|
+
*/
|
|
121
|
+
export function extractPlainText(text: string): string {
|
|
122
|
+
if (typeof MarkdownParserModule.extractPlainText === "function") {
|
|
123
|
+
return MarkdownParserModule.extractPlainText(text);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return getFlattenedText(parseMarkdown(text));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Parse markdown with options and return flattened plain text from native parser.
|
|
131
|
+
*/
|
|
132
|
+
export function extractPlainTextWithOptions(
|
|
133
|
+
text: string,
|
|
134
|
+
options: ParserOptions,
|
|
135
|
+
): string {
|
|
136
|
+
if (typeof MarkdownParserModule.extractPlainTextWithOptions === "function") {
|
|
137
|
+
return MarkdownParserModule.extractPlainTextWithOptions(text, options);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return getFlattenedText(parseMarkdownWithOptions(text, options));
|
|
103
141
|
}
|
|
104
142
|
|
|
105
143
|
export type { MarkdownParser };
|
|
@@ -169,3 +207,15 @@ export const getFlattenedText = (node: MarkdownNode): string => {
|
|
|
169
207
|
return childrenText;
|
|
170
208
|
}
|
|
171
209
|
};
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Recursively removes `beg`/`end` source offset fields from an AST.
|
|
213
|
+
* Useful to reduce memory in environments that don't need source mapping.
|
|
214
|
+
*/
|
|
215
|
+
export function stripSourceOffsets(node: MarkdownNode): MarkdownNode {
|
|
216
|
+
const { beg: _beg, end: _end, children, ...rest } = node;
|
|
217
|
+
return {
|
|
218
|
+
...rest,
|
|
219
|
+
...(children ? { children: children.map(stripSourceOffsets) } : {}),
|
|
220
|
+
};
|
|
221
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
export * from "./headless";
|
|
2
2
|
|
|
3
3
|
export { Markdown } from "./markdown";
|
|
4
|
+
export type {
|
|
5
|
+
MarkdownProps,
|
|
6
|
+
AstTransform,
|
|
7
|
+
MarkdownPlugin,
|
|
8
|
+
MarkdownVirtualizationOptions,
|
|
9
|
+
} from "./markdown";
|
|
4
10
|
export { MarkdownStream } from "./markdown-stream";
|
|
11
|
+
export type { MarkdownStreamProps } from "./markdown-stream";
|
|
5
12
|
|
|
6
13
|
export { useMarkdownContext, MarkdownContext } from "./MarkdownContext";
|
|
7
14
|
export type {
|
|
@@ -48,3 +55,6 @@ export { MathInline, MathBlock } from "./renderers/math";
|
|
|
48
55
|
export { createMarkdownSession } from "./MarkdownSession";
|
|
49
56
|
export type { MarkdownSession } from "./MarkdownSession";
|
|
50
57
|
export { useMarkdownSession, useStream } from "./use-markdown-stream";
|
|
58
|
+
|
|
59
|
+
export type { HighlightedToken, TokenType, CodeHighlighter } from "./utils/code-highlight";
|
|
60
|
+
export { defaultHighlighter } from "./utils/code-highlight";
|