react-native-nitro-markdown 0.1.2 → 0.2.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/LICENSE +21 -0
- package/README.md +142 -84
- package/android/src/main/cpp/cpp-adapter.cpp +1 -1
- package/android/src/main/java/com/margelo/nitro/com/nitromarkdown/HybridMarkdownSession.kt +61 -0
- package/android/src/main/java/com/nitromarkdown/NitroMarkdownPackage.kt +5 -1
- package/cpp/bindings/HybridMarkdownParser.cpp +2 -2
- package/cpp/bindings/HybridMarkdownParser.hpp +2 -2
- package/cpp/bindings/HybridMarkdownSession.cpp +0 -0
- package/cpp/core/MarkdownSessionCore.cpp +0 -0
- package/ios/HybridMarkdownSession.swift +64 -0
- package/lib/commonjs/MarkdownContext.js +21 -0
- package/lib/commonjs/MarkdownContext.js.map +1 -0
- package/lib/commonjs/MarkdownSession.js +11 -0
- package/lib/commonjs/MarkdownSession.js.map +1 -0
- package/lib/commonjs/default-markdown-renderer.js +220 -0
- package/lib/commonjs/default-markdown-renderer.js.map +1 -0
- package/lib/commonjs/headless.js +50 -0
- package/lib/commonjs/headless.js.map +1 -0
- package/lib/commonjs/index.js +185 -13
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/markdown-stream.js +32 -0
- package/lib/commonjs/markdown-stream.js.map +1 -0
- package/lib/commonjs/markdown.js +326 -0
- package/lib/commonjs/markdown.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/renderers/blockquote.js +36 -0
- package/lib/commonjs/renderers/blockquote.js.map +1 -0
- package/lib/commonjs/renderers/code.js +92 -0
- package/lib/commonjs/renderers/code.js.map +1 -0
- package/lib/commonjs/renderers/heading.js +62 -0
- package/lib/commonjs/renderers/heading.js.map +1 -0
- package/lib/commonjs/renderers/horizontal-rule.js +27 -0
- package/lib/commonjs/renderers/horizontal-rule.js.map +1 -0
- package/lib/commonjs/renderers/image.js +159 -0
- package/lib/commonjs/renderers/image.js.map +1 -0
- package/lib/commonjs/renderers/link.js +37 -0
- package/lib/commonjs/renderers/link.js.map +1 -0
- package/lib/commonjs/renderers/list.js +114 -0
- package/lib/commonjs/renderers/list.js.map +1 -0
- package/lib/commonjs/renderers/math.js +151 -0
- package/lib/commonjs/renderers/math.js.map +1 -0
- package/lib/commonjs/renderers/paragraph.js +44 -0
- package/lib/commonjs/renderers/paragraph.js.map +1 -0
- package/lib/commonjs/renderers/table.js +283 -0
- package/lib/commonjs/renderers/table.js.map +1 -0
- package/lib/commonjs/specs/MarkdownSession.nitro.js +6 -0
- package/lib/commonjs/specs/MarkdownSession.nitro.js.map +1 -0
- package/lib/commonjs/theme.js +58 -0
- package/lib/commonjs/theme.js.map +1 -0
- package/lib/commonjs/use-markdown-stream.js +71 -0
- package/lib/commonjs/use-markdown-stream.js.map +1 -0
- package/lib/module/MarkdownContext.js +17 -0
- package/lib/module/MarkdownContext.js.map +1 -0
- package/lib/module/MarkdownSession.js +7 -0
- package/lib/module/MarkdownSession.js.map +1 -0
- package/lib/module/default-markdown-renderer.js +215 -0
- package/lib/module/default-markdown-renderer.js.map +1 -0
- package/lib/module/headless.js +44 -0
- package/lib/module/headless.js.map +1 -0
- package/lib/module/index.js +36 -10
- package/lib/module/index.js.map +1 -1
- package/lib/module/markdown-stream.js +27 -0
- package/lib/module/markdown-stream.js.map +1 -0
- package/lib/module/markdown.js +321 -0
- package/lib/module/markdown.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/renderers/blockquote.js +31 -0
- package/lib/module/renderers/blockquote.js.map +1 -0
- package/lib/module/renderers/code.js +86 -0
- package/lib/module/renderers/code.js.map +1 -0
- package/lib/module/renderers/heading.js +57 -0
- package/lib/module/renderers/heading.js.map +1 -0
- package/lib/module/renderers/horizontal-rule.js +22 -0
- package/lib/module/renderers/horizontal-rule.js.map +1 -0
- package/lib/module/renderers/image.js +154 -0
- package/lib/module/renderers/image.js.map +1 -0
- package/lib/module/renderers/link.js +32 -0
- package/lib/module/renderers/link.js.map +1 -0
- package/lib/module/renderers/list.js +107 -0
- package/lib/module/renderers/list.js.map +1 -0
- package/lib/module/renderers/math.js +145 -0
- package/lib/module/renderers/math.js.map +1 -0
- package/lib/module/renderers/paragraph.js +39 -0
- package/lib/module/renderers/paragraph.js.map +1 -0
- package/lib/module/renderers/table.js +278 -0
- package/lib/module/renderers/table.js.map +1 -0
- package/lib/module/specs/MarkdownSession.nitro.js +4 -0
- package/lib/module/specs/MarkdownSession.nitro.js.map +1 -0
- package/lib/module/theme.js +54 -0
- package/lib/module/theme.js.map +1 -0
- package/lib/module/use-markdown-stream.js +66 -0
- package/lib/module/use-markdown-stream.js.map +1 -0
- package/lib/typescript/commonjs/Markdown.nitro.d.ts.map +1 -0
- package/lib/typescript/commonjs/MarkdownContext.d.ts +26 -0
- package/lib/typescript/commonjs/MarkdownContext.d.ts.map +1 -0
- package/lib/typescript/commonjs/MarkdownSession.d.ts +4 -0
- package/lib/typescript/commonjs/MarkdownSession.d.ts.map +1 -0
- package/lib/typescript/commonjs/default-markdown-renderer.d.ts +10 -0
- package/lib/typescript/commonjs/default-markdown-renderer.d.ts.map +1 -0
- package/lib/typescript/commonjs/headless.d.ts +50 -0
- package/lib/typescript/commonjs/headless.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +34 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/markdown-stream.d.ts +15 -0
- package/lib/typescript/commonjs/markdown-stream.d.ts.map +1 -0
- package/lib/typescript/commonjs/markdown.d.ts +29 -0
- package/lib/typescript/commonjs/markdown.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/renderers/blockquote.d.ts +9 -0
- package/lib/typescript/commonjs/renderers/blockquote.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/code.d.ts +15 -0
- package/lib/typescript/commonjs/renderers/code.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/heading.d.ts +10 -0
- package/lib/typescript/commonjs/renderers/heading.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/horizontal-rule.d.ts +3 -0
- package/lib/typescript/commonjs/renderers/horizontal-rule.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/image.d.ts +11 -0
- package/lib/typescript/commonjs/renderers/image.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/link.d.ts +10 -0
- package/lib/typescript/commonjs/renderers/link.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/list.d.ts +22 -0
- package/lib/typescript/commonjs/renderers/list.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/math.d.ts +15 -0
- package/lib/typescript/commonjs/renderers/math.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/paragraph.d.ts +15 -0
- package/lib/typescript/commonjs/renderers/paragraph.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/table.d.ts +10 -0
- package/lib/typescript/commonjs/renderers/table.d.ts.map +1 -0
- package/lib/typescript/commonjs/specs/MarkdownSession.nitro.d.ts +12 -0
- package/lib/typescript/commonjs/specs/MarkdownSession.nitro.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme.d.ts +52 -0
- package/lib/typescript/commonjs/theme.d.ts.map +1 -0
- package/lib/typescript/commonjs/use-markdown-stream.d.ts +22 -0
- package/lib/typescript/commonjs/use-markdown-stream.d.ts.map +1 -0
- package/lib/typescript/module/Markdown.nitro.d.ts +13 -0
- package/lib/typescript/module/Markdown.nitro.d.ts.map +1 -0
- package/lib/typescript/module/MarkdownContext.d.ts +26 -0
- package/lib/typescript/module/MarkdownContext.d.ts.map +1 -0
- package/lib/typescript/module/MarkdownSession.d.ts +4 -0
- package/lib/typescript/module/MarkdownSession.d.ts.map +1 -0
- package/lib/typescript/module/default-markdown-renderer.d.ts +10 -0
- package/lib/typescript/module/default-markdown-renderer.d.ts.map +1 -0
- package/lib/typescript/module/headless.d.ts +50 -0
- package/lib/typescript/module/headless.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +34 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/markdown-stream.d.ts +15 -0
- package/lib/typescript/module/markdown-stream.d.ts.map +1 -0
- package/lib/typescript/module/markdown.d.ts +29 -0
- package/lib/typescript/module/markdown.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/renderers/blockquote.d.ts +9 -0
- package/lib/typescript/module/renderers/blockquote.d.ts.map +1 -0
- package/lib/typescript/module/renderers/code.d.ts +15 -0
- package/lib/typescript/module/renderers/code.d.ts.map +1 -0
- package/lib/typescript/module/renderers/heading.d.ts +10 -0
- package/lib/typescript/module/renderers/heading.d.ts.map +1 -0
- package/lib/typescript/module/renderers/horizontal-rule.d.ts +3 -0
- package/lib/typescript/module/renderers/horizontal-rule.d.ts.map +1 -0
- package/lib/typescript/module/renderers/image.d.ts +11 -0
- package/lib/typescript/module/renderers/image.d.ts.map +1 -0
- package/lib/typescript/module/renderers/link.d.ts +10 -0
- package/lib/typescript/module/renderers/link.d.ts.map +1 -0
- package/lib/typescript/module/renderers/list.d.ts +22 -0
- package/lib/typescript/module/renderers/list.d.ts.map +1 -0
- package/lib/typescript/module/renderers/math.d.ts +15 -0
- package/lib/typescript/module/renderers/math.d.ts.map +1 -0
- package/lib/typescript/module/renderers/paragraph.d.ts +15 -0
- package/lib/typescript/module/renderers/paragraph.d.ts.map +1 -0
- package/lib/typescript/module/renderers/table.d.ts +10 -0
- package/lib/typescript/module/renderers/table.d.ts.map +1 -0
- package/lib/typescript/module/specs/MarkdownSession.nitro.d.ts +12 -0
- package/lib/typescript/module/specs/MarkdownSession.nitro.d.ts.map +1 -0
- package/lib/typescript/module/theme.d.ts +52 -0
- package/lib/typescript/module/theme.d.ts.map +1 -0
- package/lib/typescript/module/use-markdown-stream.d.ts +22 -0
- package/lib/typescript/module/use-markdown-stream.d.ts.map +1 -0
- package/nitro.json +5 -2
- package/nitrogen/generated/android/NitroMarkdown+autolinking.cmake +3 -2
- package/nitrogen/generated/android/NitroMarkdown+autolinking.gradle +1 -1
- package/nitrogen/generated/android/NitroMarkdownOnLoad.cpp +17 -5
- package/nitrogen/generated/android/NitroMarkdownOnLoad.hpp +4 -4
- package/nitrogen/generated/android/c++/JFunc_void.hpp +75 -0
- package/nitrogen/generated/android/c++/JHybridMarkdownSessionSpec.cpp +91 -0
- package/nitrogen/generated/android/c++/JHybridMarkdownSessionSpec.hpp +70 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitromarkdown/Func_void.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitromarkdown/HybridMarkdownSessionSpec.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitromarkdown/NitroMarkdownOnLoad.kt +1 -1
- package/nitrogen/generated/ios/NitroMarkdown+autolinking.rb +2 -2
- package/nitrogen/generated/ios/NitroMarkdown-Swift-Cxx-Bridge.cpp +28 -4
- package/nitrogen/generated/ios/NitroMarkdown-Swift-Cxx-Bridge.hpp +72 -6
- package/nitrogen/generated/ios/NitroMarkdown-Swift-Cxx-Umbrella.hpp +11 -4
- package/nitrogen/generated/ios/NitroMarkdownAutolinking.mm +11 -3
- package/nitrogen/generated/ios/NitroMarkdownAutolinking.swift +16 -3
- package/nitrogen/generated/ios/c++/HybridMarkdownSessionSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridMarkdownSessionSpecSwift.hpp +108 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridMarkdownSessionSpec.swift +59 -0
- package/nitrogen/generated/ios/swift/HybridMarkdownSessionSpec_cxx.swift +190 -0
- package/nitrogen/generated/shared/c++/HybridMarkdownParserSpec.cpp +3 -3
- package/nitrogen/generated/shared/c++/HybridMarkdownParserSpec.hpp +4 -4
- package/nitrogen/generated/shared/c++/HybridMarkdownSessionSpec.cpp +26 -0
- package/nitrogen/generated/shared/c++/HybridMarkdownSessionSpec.hpp +67 -0
- package/nitrogen/generated/shared/c++/ParserOptions.hpp +22 -14
- package/package.json +45 -7
- package/react-native-nitro-markdown.podspec +5 -5
- package/src/MarkdownContext.ts +41 -0
- package/src/MarkdownSession.ts +8 -0
- package/src/default-markdown-renderer.tsx +266 -0
- package/src/headless.ts +106 -0
- package/src/index.ts +41 -59
- package/src/markdown-stream.tsx +32 -0
- package/src/markdown.tsx +415 -0
- package/src/renderers/blockquote.tsx +31 -0
- package/src/renderers/code.tsx +88 -0
- package/src/renderers/heading.tsx +66 -0
- package/src/renderers/horizontal-rule.tsx +20 -0
- package/src/renderers/image.tsx +160 -0
- package/src/renderers/link.tsx +38 -0
- package/src/renderers/list.tsx +125 -0
- package/src/renderers/math.tsx +164 -0
- package/src/renderers/paragraph.tsx +53 -0
- package/src/renderers/table.tsx +345 -0
- package/src/specs/MarkdownSession.nitro.ts +16 -0
- package/src/theme.ts +52 -0
- package/src/use-markdown-stream.ts +83 -0
- package/ios/NitroMarkdown-Bridging-Header.h +0 -14
- package/lib/commonjs/MarkdownJS.reference.js +0 -114
- package/lib/commonjs/MarkdownJS.reference.js.map +0 -1
- package/lib/module/MarkdownJS.reference.js +0 -107
- package/lib/module/MarkdownJS.reference.js.map +0 -1
- package/lib/typescript/Markdown.nitro.d.ts.map +0 -1
- package/lib/typescript/MarkdownJS.reference.d.ts +0 -33
- package/lib/typescript/MarkdownJS.reference.d.ts.map +0 -1
- package/lib/typescript/index.d.ts +0 -22
- package/lib/typescript/index.d.ts.map +0 -1
- package/src/MarkdownJS.reference.ts +0 -122
- /package/lib/typescript/{Markdown.nitro.d.ts → commonjs/Markdown.nitro.d.ts} +0 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridMarkdownSessionSpec_cxx.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 Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A class implementation that bridges HybridMarkdownSessionSpec over to C++.
|
|
13
|
+
* In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
|
|
14
|
+
*
|
|
15
|
+
* Also, some Swift types need to be bridged with special handling:
|
|
16
|
+
* - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
|
|
17
|
+
* - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
|
|
18
|
+
* - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
|
|
19
|
+
*/
|
|
20
|
+
open class HybridMarkdownSessionSpec_cxx {
|
|
21
|
+
/**
|
|
22
|
+
* The Swift <> C++ bridge's namespace (`margelo::nitro::Markdown::bridge::swift`)
|
|
23
|
+
* from `NitroMarkdown-Swift-Cxx-Bridge.hpp`.
|
|
24
|
+
* This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
|
|
25
|
+
*/
|
|
26
|
+
public typealias bridge = margelo.nitro.Markdown.bridge.swift
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Holds an instance of the `HybridMarkdownSessionSpec` Swift protocol.
|
|
30
|
+
*/
|
|
31
|
+
private var __implementation: any HybridMarkdownSessionSpec
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Holds a weak pointer to the C++ class that wraps the Swift class.
|
|
35
|
+
*/
|
|
36
|
+
private var __cxxPart: bridge.std__weak_ptr_HybridMarkdownSessionSpec_
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create a new `HybridMarkdownSessionSpec_cxx` that wraps the given `HybridMarkdownSessionSpec`.
|
|
40
|
+
* All properties and methods bridge to C++ types.
|
|
41
|
+
*/
|
|
42
|
+
public init(_ implementation: any HybridMarkdownSessionSpec) {
|
|
43
|
+
self.__implementation = implementation
|
|
44
|
+
self.__cxxPart = .init()
|
|
45
|
+
/* no base class */
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get the actual `HybridMarkdownSessionSpec` instance this class wraps.
|
|
50
|
+
*/
|
|
51
|
+
@inline(__always)
|
|
52
|
+
public func getHybridMarkdownSessionSpec() -> any HybridMarkdownSessionSpec {
|
|
53
|
+
return __implementation
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
58
|
+
* This acquires one additional strong reference on the object!
|
|
59
|
+
*/
|
|
60
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
61
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Casts an unsafe pointer to a `HybridMarkdownSessionSpec_cxx`.
|
|
66
|
+
* The pointer has to be a retained opaque `Unmanaged<HybridMarkdownSessionSpec_cxx>`.
|
|
67
|
+
* This removes one strong reference from the object!
|
|
68
|
+
*/
|
|
69
|
+
public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridMarkdownSessionSpec_cxx {
|
|
70
|
+
return Unmanaged<HybridMarkdownSessionSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gets (or creates) the C++ part of this Hybrid Object.
|
|
75
|
+
* The C++ part is a `std::shared_ptr<HybridMarkdownSessionSpec>`.
|
|
76
|
+
*/
|
|
77
|
+
public func getCxxPart() -> bridge.std__shared_ptr_HybridMarkdownSessionSpec_ {
|
|
78
|
+
let cachedCxxPart = self.__cxxPart.lock()
|
|
79
|
+
if Bool(fromCxx: cachedCxxPart) {
|
|
80
|
+
return cachedCxxPart
|
|
81
|
+
} else {
|
|
82
|
+
let newCxxPart = bridge.create_std__shared_ptr_HybridMarkdownSessionSpec_(self.toUnsafe())
|
|
83
|
+
__cxxPart = bridge.weakify_std__shared_ptr_HybridMarkdownSessionSpec_(newCxxPart)
|
|
84
|
+
return newCxxPart
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get the memory size of the Swift class (plus size of any other allocations)
|
|
92
|
+
* so the JS VM can properly track it and garbage-collect the JS object if needed.
|
|
93
|
+
*/
|
|
94
|
+
@inline(__always)
|
|
95
|
+
public var memorySize: Int {
|
|
96
|
+
return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Compares this object with the given [other] object for reference equality.
|
|
101
|
+
*/
|
|
102
|
+
@inline(__always)
|
|
103
|
+
public func equals(other: HybridMarkdownSessionSpec_cxx) -> Bool {
|
|
104
|
+
return self.__implementation === other.__implementation
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Call dispose() on the Swift class.
|
|
109
|
+
* This _may_ be called manually from JS.
|
|
110
|
+
*/
|
|
111
|
+
@inline(__always)
|
|
112
|
+
public func dispose() {
|
|
113
|
+
self.__implementation.dispose()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Call toString() on the Swift class.
|
|
118
|
+
*/
|
|
119
|
+
@inline(__always)
|
|
120
|
+
public func toString() -> String {
|
|
121
|
+
return self.__implementation.toString()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Properties
|
|
125
|
+
public final var highlightPosition: Double {
|
|
126
|
+
@inline(__always)
|
|
127
|
+
get {
|
|
128
|
+
return self.__implementation.highlightPosition
|
|
129
|
+
}
|
|
130
|
+
@inline(__always)
|
|
131
|
+
set {
|
|
132
|
+
self.__implementation.highlightPosition = newValue
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Methods
|
|
137
|
+
@inline(__always)
|
|
138
|
+
public final func append(chunk: std.string) -> bridge.Result_void_ {
|
|
139
|
+
do {
|
|
140
|
+
try self.__implementation.append(chunk: String(chunk))
|
|
141
|
+
return bridge.create_Result_void_()
|
|
142
|
+
} catch (let __error) {
|
|
143
|
+
let __exceptionPtr = __error.toCpp()
|
|
144
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@inline(__always)
|
|
149
|
+
public final func clear() -> bridge.Result_void_ {
|
|
150
|
+
do {
|
|
151
|
+
try self.__implementation.clear()
|
|
152
|
+
return bridge.create_Result_void_()
|
|
153
|
+
} catch (let __error) {
|
|
154
|
+
let __exceptionPtr = __error.toCpp()
|
|
155
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
@inline(__always)
|
|
160
|
+
public final func getAllText() -> bridge.Result_std__string_ {
|
|
161
|
+
do {
|
|
162
|
+
let __result = try self.__implementation.getAllText()
|
|
163
|
+
let __resultCpp = std.string(__result)
|
|
164
|
+
return bridge.create_Result_std__string_(__resultCpp)
|
|
165
|
+
} catch (let __error) {
|
|
166
|
+
let __exceptionPtr = __error.toCpp()
|
|
167
|
+
return bridge.create_Result_std__string_(__exceptionPtr)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
@inline(__always)
|
|
172
|
+
public final func addListener(listener: bridge.Func_void) -> bridge.Result_std__function_void____ {
|
|
173
|
+
do {
|
|
174
|
+
let __result = try self.__implementation.addListener(listener: { () -> () -> Void in
|
|
175
|
+
let __wrappedFunction = bridge.wrap_Func_void(listener)
|
|
176
|
+
return { () -> Void in
|
|
177
|
+
__wrappedFunction.call()
|
|
178
|
+
}
|
|
179
|
+
}())
|
|
180
|
+
let __resultCpp = { () -> bridge.Func_void in
|
|
181
|
+
let __closureWrapper = Func_void(__result)
|
|
182
|
+
return bridge.create_Func_void(__closureWrapper.toUnsafe())
|
|
183
|
+
}()
|
|
184
|
+
return bridge.create_Result_std__function_void____(__resultCpp)
|
|
185
|
+
} catch (let __error) {
|
|
186
|
+
let __exceptionPtr = __error.toCpp()
|
|
187
|
+
return bridge.create_Result_std__function_void____(__exceptionPtr)
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
/// HybridMarkdownParserSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridMarkdownParserSpec.hpp"
|
|
9
9
|
|
|
10
|
-
namespace margelo::nitro::
|
|
10
|
+
namespace margelo::nitro::Markdown {
|
|
11
11
|
|
|
12
12
|
void HybridMarkdownParserSpec::loadHybridMethods() {
|
|
13
13
|
// load base methods/properties
|
|
@@ -19,4 +19,4 @@ namespace margelo::nitro::NitroMarkdown {
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
} // namespace margelo::nitro::
|
|
22
|
+
} // namespace margelo::nitro::Markdown
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridMarkdownParserSpec.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
#endif
|
|
15
15
|
|
|
16
16
|
// Forward declaration of `ParserOptions` to properly resolve imports.
|
|
17
|
-
namespace margelo::nitro::
|
|
17
|
+
namespace margelo::nitro::Markdown { struct ParserOptions; }
|
|
18
18
|
|
|
19
19
|
#include <string>
|
|
20
20
|
#include "ParserOptions.hpp"
|
|
21
21
|
|
|
22
|
-
namespace margelo::nitro::
|
|
22
|
+
namespace margelo::nitro::Markdown {
|
|
23
23
|
|
|
24
24
|
using namespace margelo::nitro;
|
|
25
25
|
|
|
@@ -62,4 +62,4 @@ namespace margelo::nitro::NitroMarkdown {
|
|
|
62
62
|
static constexpr auto TAG = "MarkdownParser";
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
-
} // namespace margelo::nitro::
|
|
65
|
+
} // namespace margelo::nitro::Markdown
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridMarkdownSessionSpec.cpp
|
|
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
|
+
#include "HybridMarkdownSessionSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::Markdown {
|
|
11
|
+
|
|
12
|
+
void HybridMarkdownSessionSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridGetter("highlightPosition", &HybridMarkdownSessionSpec::getHighlightPosition);
|
|
18
|
+
prototype.registerHybridSetter("highlightPosition", &HybridMarkdownSessionSpec::setHighlightPosition);
|
|
19
|
+
prototype.registerHybridMethod("append", &HybridMarkdownSessionSpec::append);
|
|
20
|
+
prototype.registerHybridMethod("clear", &HybridMarkdownSessionSpec::clear);
|
|
21
|
+
prototype.registerHybridMethod("getAllText", &HybridMarkdownSessionSpec::getAllText);
|
|
22
|
+
prototype.registerHybridMethod("addListener", &HybridMarkdownSessionSpec::addListener);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
} // namespace margelo::nitro::Markdown
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridMarkdownSessionSpec.hpp
|
|
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
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
#include <string>
|
|
19
|
+
#include <functional>
|
|
20
|
+
|
|
21
|
+
namespace margelo::nitro::Markdown {
|
|
22
|
+
|
|
23
|
+
using namespace margelo::nitro;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* An abstract base class for `MarkdownSession`
|
|
27
|
+
* Inherit this class to create instances of `HybridMarkdownSessionSpec` in C++.
|
|
28
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
29
|
+
* @example
|
|
30
|
+
* ```cpp
|
|
31
|
+
* class HybridMarkdownSession: public HybridMarkdownSessionSpec {
|
|
32
|
+
* public:
|
|
33
|
+
* HybridMarkdownSession(...): HybridObject(TAG) { ... }
|
|
34
|
+
* // ...
|
|
35
|
+
* };
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
class HybridMarkdownSessionSpec: public virtual HybridObject {
|
|
39
|
+
public:
|
|
40
|
+
// Constructor
|
|
41
|
+
explicit HybridMarkdownSessionSpec(): HybridObject(TAG) { }
|
|
42
|
+
|
|
43
|
+
// Destructor
|
|
44
|
+
~HybridMarkdownSessionSpec() override = default;
|
|
45
|
+
|
|
46
|
+
public:
|
|
47
|
+
// Properties
|
|
48
|
+
virtual double getHighlightPosition() = 0;
|
|
49
|
+
virtual void setHighlightPosition(double highlightPosition) = 0;
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
// Methods
|
|
53
|
+
virtual void append(const std::string& chunk) = 0;
|
|
54
|
+
virtual void clear() = 0;
|
|
55
|
+
virtual std::string getAllText() = 0;
|
|
56
|
+
virtual std::function<void()> addListener(const std::function<void()>& listener) = 0;
|
|
57
|
+
|
|
58
|
+
protected:
|
|
59
|
+
// Hybrid Setup
|
|
60
|
+
void loadHybridMethods() override;
|
|
61
|
+
|
|
62
|
+
protected:
|
|
63
|
+
// Tag for logging
|
|
64
|
+
static constexpr auto TAG = "MarkdownSession";
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
} // namespace margelo::nitro::Markdown
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// ParserOptions.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
@@ -22,17 +22,22 @@
|
|
|
22
22
|
#else
|
|
23
23
|
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
24
|
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
25
30
|
|
|
26
31
|
|
|
27
32
|
|
|
28
33
|
#include <optional>
|
|
29
34
|
|
|
30
|
-
namespace margelo::nitro::
|
|
35
|
+
namespace margelo::nitro::Markdown {
|
|
31
36
|
|
|
32
37
|
/**
|
|
33
38
|
* A struct which can be represented as a JavaScript object (ParserOptions).
|
|
34
39
|
*/
|
|
35
|
-
struct ParserOptions {
|
|
40
|
+
struct ParserOptions final {
|
|
36
41
|
public:
|
|
37
42
|
std::optional<bool> gfm SWIFT_PRIVATE;
|
|
38
43
|
std::optional<bool> math SWIFT_PRIVATE;
|
|
@@ -40,26 +45,29 @@ namespace margelo::nitro::NitroMarkdown {
|
|
|
40
45
|
public:
|
|
41
46
|
ParserOptions() = default;
|
|
42
47
|
explicit ParserOptions(std::optional<bool> gfm, std::optional<bool> math): gfm(gfm), math(math) {}
|
|
48
|
+
|
|
49
|
+
public:
|
|
50
|
+
friend bool operator==(const ParserOptions& lhs, const ParserOptions& rhs) = default;
|
|
43
51
|
};
|
|
44
52
|
|
|
45
|
-
} // namespace margelo::nitro::
|
|
53
|
+
} // namespace margelo::nitro::Markdown
|
|
46
54
|
|
|
47
55
|
namespace margelo::nitro {
|
|
48
56
|
|
|
49
57
|
// C++ ParserOptions <> JS ParserOptions (object)
|
|
50
58
|
template <>
|
|
51
|
-
struct JSIConverter<margelo::nitro::
|
|
52
|
-
static inline margelo::nitro::
|
|
59
|
+
struct JSIConverter<margelo::nitro::Markdown::ParserOptions> final {
|
|
60
|
+
static inline margelo::nitro::Markdown::ParserOptions fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
53
61
|
jsi::Object obj = arg.asObject(runtime);
|
|
54
|
-
return margelo::nitro::
|
|
55
|
-
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "gfm")),
|
|
56
|
-
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "math"))
|
|
62
|
+
return margelo::nitro::Markdown::ParserOptions(
|
|
63
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "gfm"))),
|
|
64
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "math")))
|
|
57
65
|
);
|
|
58
66
|
}
|
|
59
|
-
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::
|
|
67
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::Markdown::ParserOptions& arg) {
|
|
60
68
|
jsi::Object obj(runtime);
|
|
61
|
-
obj.setProperty(runtime, "gfm", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.gfm));
|
|
62
|
-
obj.setProperty(runtime, "math", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.math));
|
|
69
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "gfm"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.gfm));
|
|
70
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "math"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.math));
|
|
63
71
|
return obj;
|
|
64
72
|
}
|
|
65
73
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -70,8 +78,8 @@ namespace margelo::nitro {
|
|
|
70
78
|
if (!nitro::isPlainObject(runtime, obj)) {
|
|
71
79
|
return false;
|
|
72
80
|
}
|
|
73
|
-
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "gfm"))) return false;
|
|
74
|
-
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "math"))) return false;
|
|
81
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "gfm")))) return false;
|
|
82
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "math")))) return false;
|
|
75
83
|
return true;
|
|
76
84
|
}
|
|
77
85
|
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-markdown",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.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",
|
|
7
|
-
"types": "lib/typescript/index.d.ts",
|
|
7
|
+
"types": "lib/typescript/commonjs/index.d.ts",
|
|
8
8
|
"react-native": "src/index.ts",
|
|
9
9
|
"source": "src/index.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./lib/typescript/module/index.d.ts",
|
|
14
|
+
"default": "./lib/module/index.js"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./lib/typescript/commonjs/index.d.ts",
|
|
18
|
+
"default": "./lib/commonjs/index.js"
|
|
19
|
+
},
|
|
20
|
+
"react-native": "./src/index.ts"
|
|
21
|
+
},
|
|
22
|
+
"./headless": {
|
|
23
|
+
"import": {
|
|
24
|
+
"types": "./lib/typescript/module/headless.d.ts",
|
|
25
|
+
"default": "./lib/module/headless.js"
|
|
26
|
+
},
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./lib/typescript/commonjs/headless.d.ts",
|
|
29
|
+
"default": "./lib/commonjs/headless.js"
|
|
30
|
+
},
|
|
31
|
+
"react-native": "./src/headless.ts"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
10
34
|
"files": [
|
|
11
35
|
"src",
|
|
12
36
|
"lib",
|
|
@@ -34,8 +58,8 @@
|
|
|
34
58
|
"test": "jest",
|
|
35
59
|
"test:coverage": "jest --coverage",
|
|
36
60
|
"benchmark": "node ../../scripts/benchmark-comparison.js",
|
|
37
|
-
"prepack": "node -e \"require('fs').copyFileSync('../../README.md','./README.md')\"",
|
|
38
|
-
"postpack": "node -e \"const fs=require('fs');if(fs.existsSync('./README.md'))fs.unlinkSync('./README.md')\"",
|
|
61
|
+
"prepack": "node -e \"const fs=require('fs'); fs.copyFileSync('../../README.md','./README.md'); fs.copyFileSync('../../LICENSE','./LICENSE')\"",
|
|
62
|
+
"postpack": "node -e \"const fs=require('fs'); if(fs.existsSync('./README.md'))fs.unlinkSync('./README.md'); if(fs.existsSync('./LICENSE'))fs.unlinkSync('./LICENSE')\"",
|
|
39
63
|
"test:cpp": "node scripts/test-cpp.js"
|
|
40
64
|
},
|
|
41
65
|
"keywords": [
|
|
@@ -52,7 +76,7 @@
|
|
|
52
76
|
"type": "git",
|
|
53
77
|
"url": "git+https://github.com/JoaoPauloCMarra/react-native-nitro-markdown.git"
|
|
54
78
|
},
|
|
55
|
-
"author": "",
|
|
79
|
+
"author": "João Paulo C. Marra <joaopaulocmarra@gmail.com>",
|
|
56
80
|
"license": "MIT",
|
|
57
81
|
"bugs": {
|
|
58
82
|
"url": "https://github.com/JoaoPauloCMarra/react-native-nitro-markdown/issues"
|
|
@@ -62,12 +86,26 @@
|
|
|
62
86
|
"registry": "https://registry.npmjs.org/"
|
|
63
87
|
},
|
|
64
88
|
"devDependencies": {
|
|
65
|
-
"react
|
|
89
|
+
"@types/react": "^19.2.7",
|
|
90
|
+
"@types/react-native": "^0.73.0",
|
|
91
|
+
"react-native-builder-bob": "^0.40.17",
|
|
92
|
+
"react-native-nitro-modules": "*",
|
|
93
|
+
"typescript": "^5.9.3"
|
|
66
94
|
},
|
|
67
95
|
"peerDependencies": {
|
|
68
96
|
"react": "*",
|
|
69
97
|
"react-native": ">=0.75.0",
|
|
70
|
-
"react-native-nitro-modules": "
|
|
98
|
+
"react-native-nitro-modules": "*",
|
|
99
|
+
"react-native-mathjax-svg": ">=0.9.0",
|
|
100
|
+
"react-native-svg": ">=13.0.0"
|
|
101
|
+
},
|
|
102
|
+
"peerDependenciesMeta": {
|
|
103
|
+
"react-native-mathjax-svg": {
|
|
104
|
+
"optional": true
|
|
105
|
+
},
|
|
106
|
+
"react-native-svg": {
|
|
107
|
+
"optional": true
|
|
108
|
+
}
|
|
71
109
|
},
|
|
72
110
|
"codegenConfig": {
|
|
73
111
|
"name": "NitroMarkdownSpec",
|
|
@@ -12,19 +12,20 @@ Pod::Spec.new do |s|
|
|
|
12
12
|
|
|
13
13
|
s.platforms = { :ios => "13.0" }
|
|
14
14
|
s.source = { :git => "https://github.com/JoaoPauloCMarra/react-native-nitro-markdown.git", :tag => "#{s.version}" }
|
|
15
|
+
s.module_name = "NitroMarkdown"
|
|
15
16
|
|
|
16
|
-
# All source files including md4c and our C++ implementation
|
|
17
17
|
s.source_files = [
|
|
18
18
|
"ios/**/*.{h,m,mm,swift}",
|
|
19
19
|
"cpp/**/*.{h,hpp,c,cpp}"
|
|
20
20
|
]
|
|
21
21
|
|
|
22
|
-
# Ensure md4c.c is compiled as C, not C++
|
|
23
22
|
s.pod_target_xcconfig = {
|
|
24
23
|
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
|
|
25
24
|
"CLANG_CXX_LIBRARY" => "libc++",
|
|
26
25
|
"GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) MD4C_USE_UTF8=1",
|
|
27
26
|
"HEADER_SEARCH_PATHS" => [
|
|
27
|
+
"\"$(inherited)\"",
|
|
28
|
+
"\"$(PODS_ROOT)/Headers/Private/Yoga\"",
|
|
28
29
|
"\"$(PODS_TARGET_SRCROOT)/cpp/md4c\"",
|
|
29
30
|
"\"$(PODS_TARGET_SRCROOT)/cpp/core\"",
|
|
30
31
|
"\"$(PODS_TARGET_SRCROOT)/cpp/bindings\"",
|
|
@@ -33,10 +34,9 @@ Pod::Spec.new do |s|
|
|
|
33
34
|
].join(" ")
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
# React Native dependency
|
|
37
37
|
s.dependency "React-Core"
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
s.dependency "React-Fabric"
|
|
39
|
+
|
|
40
40
|
load 'nitrogen/generated/ios/NitroMarkdown+autolinking.rb'
|
|
41
41
|
add_nitrogen_files(s)
|
|
42
42
|
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createContext, useContext, type ReactNode, type ComponentType } from "react";
|
|
2
|
+
import { defaultMarkdownTheme, type MarkdownTheme } from "./theme";
|
|
3
|
+
import type { MarkdownNode } from "./headless";
|
|
4
|
+
|
|
5
|
+
export interface NodeRendererProps {
|
|
6
|
+
node: MarkdownNode;
|
|
7
|
+
depth: number;
|
|
8
|
+
inListItem: boolean;
|
|
9
|
+
parentIsText?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface CustomRendererProps {
|
|
13
|
+
node: MarkdownNode;
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
Renderer: ComponentType<NodeRendererProps>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type CustomRenderer = (
|
|
19
|
+
props: CustomRendererProps
|
|
20
|
+
) => ReactNode | undefined;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Object mapping node types to custom renderers.
|
|
24
|
+
*/
|
|
25
|
+
export type CustomRenderers = Partial<
|
|
26
|
+
Record<MarkdownNode["type"], CustomRenderer>
|
|
27
|
+
>;
|
|
28
|
+
|
|
29
|
+
// Context for custom renderers and theme
|
|
30
|
+
export interface MarkdownContextValue {
|
|
31
|
+
renderers: CustomRenderers;
|
|
32
|
+
theme: MarkdownTheme;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const MarkdownContext = createContext<MarkdownContextValue>({
|
|
36
|
+
renderers: {},
|
|
37
|
+
theme: defaultMarkdownTheme,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const useMarkdownContext = () => useContext(MarkdownContext);
|
|
41
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NitroModules } from "react-native-nitro-modules";
|
|
2
|
+
import type { MarkdownSession as MarkdownSessionSpec } from "./specs/MarkdownSession.nitro";
|
|
3
|
+
|
|
4
|
+
export type MarkdownSession = MarkdownSessionSpec;
|
|
5
|
+
|
|
6
|
+
export function createMarkdownSession(): MarkdownSession {
|
|
7
|
+
return NitroModules.createHybridObject<MarkdownSession>("MarkdownSession");
|
|
8
|
+
}
|