react-native-nitro-markdown 0.4.3 → 0.5.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/README.md +351 -22
- package/android/src/main/java/com/margelo/nitro/com/nitromarkdown/HybridMarkdownSession.kt +27 -8
- package/cpp/bindings/HybridMarkdownParser.cpp +216 -66
- package/cpp/bindings/HybridMarkdownParser.hpp +2 -0
- package/ios/HybridMarkdownSession.swift +33 -7
- package/lib/commonjs/headless.js +41 -5
- package/lib/commonjs/headless.js.map +1 -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 +180 -25
- package/lib/commonjs/markdown.js.map +1 -1
- package/lib/commonjs/renderers/code.js +1 -0
- package/lib/commonjs/renderers/code.js.map +1 -1
- package/lib/commonjs/renderers/table.js +116 -24
- package/lib/commonjs/renderers/table.js.map +1 -1
- package/lib/commonjs/utils/incremental-ast.js +153 -0
- package/lib/commonjs/utils/incremental-ast.js.map +1 -0
- package/lib/module/headless.js +37 -4
- package/lib/module/headless.js.map +1 -1
- 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 +182 -27
- package/lib/module/markdown.js.map +1 -1
- package/lib/module/renderers/code.js +1 -0
- package/lib/module/renderers/code.js.map +1 -1
- package/lib/module/renderers/table.js +116 -24
- package/lib/module/renderers/table.js.map +1 -1
- 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/headless.d.ts +13 -0
- package/lib/typescript/commonjs/headless.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +2 -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 +53 -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.d.ts +1 -1
- package/lib/typescript/commonjs/renderers/table.d.ts.map +1 -1
- package/lib/typescript/commonjs/specs/MarkdownSession.nitro.d.ts +5 -2
- package/lib/typescript/commonjs/specs/MarkdownSession.nitro.d.ts.map +1 -1
- 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/headless.d.ts +13 -0
- package/lib/typescript/module/headless.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +2 -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 +53 -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.d.ts +1 -1
- package/lib/typescript/module/renderers/table.d.ts.map +1 -1
- package/lib/typescript/module/specs/MarkdownSession.nitro.d.ts +5 -2
- package/lib/typescript/module/specs/MarkdownSession.nitro.d.ts.map +1 -1
- 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 +2 -0
- package/nitrogen/generated/android/c++/JFunc_void_double_double.hpp +75 -0
- package/nitrogen/generated/android/c++/JHybridMarkdownSessionSpec.cpp +18 -6
- package/nitrogen/generated/android/c++/JHybridMarkdownSessionSpec.hpp +4 -2
- 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 +11 -3
- 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 +20 -2
- package/nitrogen/generated/ios/swift/Func_void_double_double.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridMarkdownSessionSpec.swift +4 -2
- package/nitrogen/generated/ios/swift/HybridMarkdownSessionSpec_cxx.swift +34 -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 +2 -0
- package/nitrogen/generated/shared/c++/HybridMarkdownSessionSpec.hpp +4 -2
- package/package.json +4 -3
- package/src/Markdown.nitro.ts +2 -0
- package/src/headless.ts +42 -4
- package/src/index.ts +7 -0
- package/src/markdown-stream.tsx +163 -15
- package/src/markdown.tsx +339 -24
- package/src/renderers/code.tsx +5 -1
- package/src/renderers/table.tsx +212 -66
- package/src/specs/MarkdownSession.nitro.ts +6 -2
- package/src/utils/incremental-ast.ts +224 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_double_double.kt
|
|
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
|
+
package com.margelo.nitro.com.nitromarkdown
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.jni.HybridData
|
|
12
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
13
|
+
import dalvik.annotation.optimization.FastNative
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Represents the JavaScript callback `(from: number, to: number) => void`.
|
|
18
|
+
* This can be either implemented in C++ (in which case it might be a callback coming from JS),
|
|
19
|
+
* or in Kotlin/Java (in which case it is a native callback).
|
|
20
|
+
*/
|
|
21
|
+
@DoNotStrip
|
|
22
|
+
@Keep
|
|
23
|
+
@Suppress("ClassName", "RedundantUnitReturnType")
|
|
24
|
+
fun interface Func_void_double_double: (Double, Double) -> Unit {
|
|
25
|
+
/**
|
|
26
|
+
* Call the given JS callback.
|
|
27
|
+
* @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted.
|
|
28
|
+
*/
|
|
29
|
+
@DoNotStrip
|
|
30
|
+
@Keep
|
|
31
|
+
override fun invoke(from: Double, to: Double): Unit
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Represents the JavaScript callback `(from: number, to: number) => void`.
|
|
36
|
+
* This is implemented in C++, via a `std::function<...>`.
|
|
37
|
+
* The callback might be coming from JS.
|
|
38
|
+
*/
|
|
39
|
+
@DoNotStrip
|
|
40
|
+
@Keep
|
|
41
|
+
@Suppress(
|
|
42
|
+
"KotlinJniMissingFunction", "unused",
|
|
43
|
+
"RedundantSuppression", "RedundantUnitReturnType", "FunctionName",
|
|
44
|
+
"ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName",
|
|
45
|
+
)
|
|
46
|
+
class Func_void_double_double_cxx: Func_void_double_double {
|
|
47
|
+
@DoNotStrip
|
|
48
|
+
@Keep
|
|
49
|
+
private val mHybridData: HybridData
|
|
50
|
+
|
|
51
|
+
@DoNotStrip
|
|
52
|
+
@Keep
|
|
53
|
+
private constructor(hybridData: HybridData) {
|
|
54
|
+
mHybridData = hybridData
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@DoNotStrip
|
|
58
|
+
@Keep
|
|
59
|
+
override fun invoke(from: Double, to: Double): Unit
|
|
60
|
+
= invoke_cxx(from,to)
|
|
61
|
+
|
|
62
|
+
@FastNative
|
|
63
|
+
private external fun invoke_cxx(from: Double, to: Double): Unit
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Represents the JavaScript callback `(from: number, to: number) => void`.
|
|
68
|
+
* This is implemented in Java/Kotlin, via a `(Double, Double) -> Unit`.
|
|
69
|
+
* The callback is always coming from native.
|
|
70
|
+
*/
|
|
71
|
+
@DoNotStrip
|
|
72
|
+
@Keep
|
|
73
|
+
@Suppress("ClassName", "RedundantUnitReturnType", "unused")
|
|
74
|
+
class Func_void_double_double_java(private val function: (Double, Double) -> Unit): Func_void_double_double {
|
|
75
|
+
@DoNotStrip
|
|
76
|
+
@Keep
|
|
77
|
+
override fun invoke(from: Double, to: Double): Unit {
|
|
78
|
+
return this.function(from, to)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -51,7 +51,7 @@ abstract class HybridMarkdownSessionSpec: HybridObject() {
|
|
|
51
51
|
// Methods
|
|
52
52
|
@DoNotStrip
|
|
53
53
|
@Keep
|
|
54
|
-
abstract fun append(chunk: String):
|
|
54
|
+
abstract fun append(chunk: String): Double
|
|
55
55
|
|
|
56
56
|
@DoNotStrip
|
|
57
57
|
@Keep
|
|
@@ -61,11 +61,19 @@ abstract class HybridMarkdownSessionSpec: HybridObject() {
|
|
|
61
61
|
@Keep
|
|
62
62
|
abstract fun getAllText(): String
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
@DoNotStrip
|
|
65
|
+
@Keep
|
|
66
|
+
abstract fun getLength(): Double
|
|
67
|
+
|
|
68
|
+
@DoNotStrip
|
|
69
|
+
@Keep
|
|
70
|
+
abstract fun getTextRange(from: Double, to: Double): String
|
|
71
|
+
|
|
72
|
+
abstract fun addListener(listener: (from: Double, to: Double) -> Unit): () -> Unit
|
|
65
73
|
|
|
66
74
|
@DoNotStrip
|
|
67
75
|
@Keep
|
|
68
|
-
private fun addListener_cxx(listener:
|
|
76
|
+
private fun addListener_cxx(listener: Func_void_double_double): Func_void {
|
|
69
77
|
val __result = addListener(listener)
|
|
70
78
|
return Func_void_java(__result)
|
|
71
79
|
}
|
|
@@ -22,6 +22,14 @@ namespace margelo::nitro::Markdown::bridge::swift {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
// pragma MARK: std::function<void(double /* from */, double /* to */)>
|
|
26
|
+
Func_void_double_double create_Func_void_double_double(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
27
|
+
auto swiftClosure = NitroMarkdown::Func_void_double_double::fromUnsafe(swiftClosureWrapper);
|
|
28
|
+
return [swiftClosure = std::move(swiftClosure)](double from, double to) mutable -> void {
|
|
29
|
+
swiftClosure.call(from, to);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
25
33
|
// pragma MARK: std::shared_ptr<HybridMarkdownSessionSpec>
|
|
26
34
|
std::shared_ptr<HybridMarkdownSessionSpec> create_std__shared_ptr_HybridMarkdownSessionSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
|
|
27
35
|
NitroMarkdown::HybridMarkdownSessionSpec_cxx swiftPart = NitroMarkdown::HybridMarkdownSessionSpec_cxx::fromUnsafe(swiftUnsafePointer);
|
|
@@ -51,6 +51,28 @@ namespace margelo::nitro::Markdown::bridge::swift {
|
|
|
51
51
|
return Func_void_Wrapper(std::move(value));
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
// pragma MARK: std::function<void(double /* from */, double /* to */)>
|
|
55
|
+
/**
|
|
56
|
+
* Specialized version of `std::function<void(double, double)>`.
|
|
57
|
+
*/
|
|
58
|
+
using Func_void_double_double = std::function<void(double /* from */, double /* to */)>;
|
|
59
|
+
/**
|
|
60
|
+
* Wrapper class for a `std::function<void(double / * from * /, double / * to * /)>`, this can be used from Swift.
|
|
61
|
+
*/
|
|
62
|
+
class Func_void_double_double_Wrapper final {
|
|
63
|
+
public:
|
|
64
|
+
explicit Func_void_double_double_Wrapper(std::function<void(double /* from */, double /* to */)>&& func): _function(std::make_unique<std::function<void(double /* from */, double /* to */)>>(std::move(func))) {}
|
|
65
|
+
inline void call(double from, double to) const noexcept {
|
|
66
|
+
_function->operator()(from, to);
|
|
67
|
+
}
|
|
68
|
+
private:
|
|
69
|
+
std::unique_ptr<std::function<void(double /* from */, double /* to */)>> _function;
|
|
70
|
+
} SWIFT_NONCOPYABLE;
|
|
71
|
+
Func_void_double_double create_Func_void_double_double(void* NON_NULL swiftClosureWrapper) noexcept;
|
|
72
|
+
inline Func_void_double_double_Wrapper wrap_Func_void_double_double(Func_void_double_double value) noexcept {
|
|
73
|
+
return Func_void_double_double_Wrapper(std::move(value));
|
|
74
|
+
}
|
|
75
|
+
|
|
54
76
|
// pragma MARK: std::shared_ptr<HybridMarkdownSessionSpec>
|
|
55
77
|
/**
|
|
56
78
|
* Specialized version of `std::shared_ptr<HybridMarkdownSessionSpec>`.
|
|
@@ -63,6 +85,15 @@ namespace margelo::nitro::Markdown::bridge::swift {
|
|
|
63
85
|
using std__weak_ptr_HybridMarkdownSessionSpec_ = std::weak_ptr<HybridMarkdownSessionSpec>;
|
|
64
86
|
inline std__weak_ptr_HybridMarkdownSessionSpec_ weakify_std__shared_ptr_HybridMarkdownSessionSpec_(const std::shared_ptr<HybridMarkdownSessionSpec>& strong) noexcept { return strong; }
|
|
65
87
|
|
|
88
|
+
// pragma MARK: Result<double>
|
|
89
|
+
using Result_double_ = Result<double>;
|
|
90
|
+
inline Result_double_ create_Result_double_(double value) noexcept {
|
|
91
|
+
return Result<double>::withValue(std::move(value));
|
|
92
|
+
}
|
|
93
|
+
inline Result_double_ create_Result_double_(const std::exception_ptr& error) noexcept {
|
|
94
|
+
return Result<double>::withError(error);
|
|
95
|
+
}
|
|
96
|
+
|
|
66
97
|
// pragma MARK: Result<void>
|
|
67
98
|
using Result_void_ = Result<void>;
|
|
68
99
|
inline Result_void_ create_Result_void_() noexcept {
|
|
@@ -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());
|
|
@@ -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,12 @@ 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
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
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_ {
|
|
185
|
+
do {
|
|
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____ {
|
|
172
197
|
do {
|
|
173
|
-
let __result = try self.__implementation.addListener(listener: { () -> () -> Void in
|
|
174
|
-
let __wrappedFunction = bridge.
|
|
175
|
-
return { () -> Void in
|
|
176
|
-
__wrappedFunction.call()
|
|
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
|
|
@@ -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,6 +19,8 @@ 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);
|
|
23
25
|
});
|
|
24
26
|
}
|
|
@@ -50,10 +50,12 @@ 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;
|
|
57
59
|
|
|
58
60
|
protected:
|
|
59
61
|
// 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.0",
|
|
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\"",
|
|
@@ -89,8 +89,9 @@
|
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@types/react": "^19.2.14",
|
|
91
91
|
"@types/react-native": "^0.73.0",
|
|
92
|
+
"@types/react-test-renderer": "^19.1.0",
|
|
92
93
|
"react-native-builder-bob": "^0.40.18",
|
|
93
|
-
"react-
|
|
94
|
+
"react-test-renderer": "^19.2.4",
|
|
94
95
|
"typescript": "^5.9.3"
|
|
95
96
|
},
|
|
96
97
|
"peerDependencies": {
|
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/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 };
|
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 {
|