react-native-nitro-markdown 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -10
- package/android/CMakeLists.txt +1 -1
- package/android/src/main/java/com/margelo/nitro/com/nitromarkdown/HybridMarkdownSession.kt +9 -3
- package/cpp/bindings/HybridMarkdownParser.cpp +4 -2
- package/cpp/core/MD4CParser.cpp +20 -2
- package/cpp/core/MarkdownTypes.hpp +1 -1
- package/lib/commonjs/headless.js +2 -2
- package/lib/commonjs/markdown.js +16 -12
- package/lib/commonjs/markdown.js.map +1 -1
- package/lib/commonjs/renderers/blockquote.js +15 -13
- package/lib/commonjs/renderers/blockquote.js.map +1 -1
- package/lib/commonjs/renderers/code.js +57 -53
- package/lib/commonjs/renderers/code.js.map +1 -1
- package/lib/commonjs/renderers/heading.js +48 -46
- package/lib/commonjs/renderers/heading.js.map +1 -1
- package/lib/commonjs/renderers/horizontal-rule.js +10 -8
- package/lib/commonjs/renderers/horizontal-rule.js.map +1 -1
- package/lib/commonjs/renderers/image.js +12 -3
- package/lib/commonjs/renderers/image.js.map +1 -1
- package/lib/commonjs/renderers/list.js +75 -70
- package/lib/commonjs/renderers/list.js.map +1 -1
- package/lib/commonjs/renderers/math.js +4 -3
- package/lib/commonjs/renderers/math.js.map +1 -1
- package/lib/commonjs/renderers/paragraph.js +15 -13
- package/lib/commonjs/renderers/paragraph.js.map +1 -1
- package/lib/commonjs/renderers/style-cache.js +14 -0
- package/lib/commonjs/renderers/style-cache.js.map +1 -0
- package/lib/commonjs/renderers/table/index.js +7 -4
- package/lib/commonjs/renderers/table/index.js.map +1 -1
- package/lib/module/headless.js +2 -2
- package/lib/module/markdown.js +16 -12
- package/lib/module/markdown.js.map +1 -1
- package/lib/module/renderers/blockquote.js +15 -13
- package/lib/module/renderers/blockquote.js.map +1 -1
- package/lib/module/renderers/code.js +57 -53
- package/lib/module/renderers/code.js.map +1 -1
- package/lib/module/renderers/heading.js +48 -46
- package/lib/module/renderers/heading.js.map +1 -1
- package/lib/module/renderers/horizontal-rule.js +10 -8
- package/lib/module/renderers/horizontal-rule.js.map +1 -1
- package/lib/module/renderers/image.js +13 -4
- package/lib/module/renderers/image.js.map +1 -1
- package/lib/module/renderers/list.js +75 -70
- package/lib/module/renderers/list.js.map +1 -1
- package/lib/module/renderers/math.js +4 -3
- package/lib/module/renderers/math.js.map +1 -1
- package/lib/module/renderers/paragraph.js +15 -13
- package/lib/module/renderers/paragraph.js.map +1 -1
- package/lib/module/renderers/style-cache.js +10 -0
- package/lib/module/renderers/style-cache.js.map +1 -0
- package/lib/module/renderers/table/index.js +7 -4
- package/lib/module/renderers/table/index.js.map +1 -1
- package/lib/typescript/commonjs/Markdown.nitro.d.ts +1 -0
- package/lib/typescript/commonjs/Markdown.nitro.d.ts.map +1 -1
- package/lib/typescript/commonjs/headless.d.ts +2 -2
- package/lib/typescript/commonjs/markdown.d.ts +1 -1
- package/lib/typescript/commonjs/markdown.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/blockquote.d.ts +1 -1
- package/lib/typescript/commonjs/renderers/blockquote.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/code.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/heading.d.ts +1 -1
- package/lib/typescript/commonjs/renderers/heading.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/horizontal-rule.d.ts +1 -1
- package/lib/typescript/commonjs/renderers/horizontal-rule.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/image.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/list.d.ts +1 -1
- package/lib/typescript/commonjs/renderers/list.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/math.d.ts +1 -1
- package/lib/typescript/commonjs/renderers/math.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/paragraph.d.ts +1 -1
- package/lib/typescript/commonjs/renderers/paragraph.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/style-cache.d.ts +3 -0
- package/lib/typescript/commonjs/renderers/style-cache.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/table/index.d.ts.map +1 -1
- package/lib/typescript/module/Markdown.nitro.d.ts +1 -0
- package/lib/typescript/module/Markdown.nitro.d.ts.map +1 -1
- package/lib/typescript/module/headless.d.ts +2 -2
- package/lib/typescript/module/markdown.d.ts +1 -1
- package/lib/typescript/module/markdown.d.ts.map +1 -1
- package/lib/typescript/module/renderers/blockquote.d.ts +1 -1
- package/lib/typescript/module/renderers/blockquote.d.ts.map +1 -1
- package/lib/typescript/module/renderers/code.d.ts.map +1 -1
- package/lib/typescript/module/renderers/heading.d.ts +1 -1
- package/lib/typescript/module/renderers/heading.d.ts.map +1 -1
- package/lib/typescript/module/renderers/horizontal-rule.d.ts +1 -1
- package/lib/typescript/module/renderers/horizontal-rule.d.ts.map +1 -1
- package/lib/typescript/module/renderers/image.d.ts.map +1 -1
- package/lib/typescript/module/renderers/list.d.ts +1 -1
- package/lib/typescript/module/renderers/list.d.ts.map +1 -1
- package/lib/typescript/module/renderers/math.d.ts +1 -1
- package/lib/typescript/module/renderers/math.d.ts.map +1 -1
- package/lib/typescript/module/renderers/paragraph.d.ts +1 -1
- package/lib/typescript/module/renderers/paragraph.d.ts.map +1 -1
- package/lib/typescript/module/renderers/style-cache.d.ts +3 -0
- package/lib/typescript/module/renderers/style-cache.d.ts.map +1 -0
- package/lib/typescript/module/renderers/table/index.d.ts.map +1 -1
- package/nitro.json +12 -3
- package/nitrogen/generated/android/NitroMarkdownOnLoad.cpp +2 -2
- package/nitrogen/generated/android/c++/JFunc_void.hpp +2 -2
- package/nitrogen/generated/android/c++/JFunc_void_double_double.hpp +2 -2
- package/nitrogen/generated/android/c++/JHybridMarkdownSessionSpec.hpp +2 -2
- package/nitrogen/generated/ios/NitroMarkdown+autolinking.rb +2 -0
- package/nitrogen/generated/shared/c++/ParserOptions.hpp +6 -2
- package/package.json +5 -5
- package/react-native-nitro-markdown.podspec +3 -0
- package/src/Markdown.nitro.ts +1 -0
- package/src/headless.ts +2 -2
- package/src/markdown.tsx +30 -12
- package/src/renderers/blockquote.tsx +22 -17
- package/src/renderers/code.tsx +75 -63
- package/src/renderers/heading.tsx +60 -54
- package/src/renderers/horizontal-rule.tsx +17 -12
- package/src/renderers/image.tsx +15 -4
- package/src/renderers/list.tsx +93 -76
- package/src/renderers/math.tsx +8 -3
- package/src/renderers/paragraph.tsx +22 -17
- package/src/renderers/style-cache.ts +14 -0
- package/src/renderers/table/index.tsx +15 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../src/renderers/list.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../src/renderers/list.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAKhF,KAAK,SAAS,GAAG;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAGF,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAQ9B,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,aAAa,CAoBtC,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAqB9C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../../../src/renderers/math.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../../../src/renderers/math.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAiB,MAAM,OAAO,CAAC;AAC/C,OAAO,EAML,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AA0BtB,KAAK,eAAe,GAAG;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AA4DF,eAAO,MAAM,UAAU,EAAE,EAAE,CAAC,eAAe,CA2B1C,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,EAAE,CAAC,cAAc,CA0BxC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paragraph.d.ts","sourceRoot":"","sources":["../../../../src/renderers/paragraph.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"paragraph.d.ts","sourceRoot":"","sources":["../../../../src/renderers/paragraph.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAoB,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAKhF,KAAK,cAAc,GAAG;IACpB,QAAQ,EAAE,SAAS,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC9B,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,EAAE,CAAC,cAAc,CAmBxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style-cache.d.ts","sourceRoot":"","sources":["../../../../src/renderers/style-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,wBAAgB,eAAe,CAAC,CAAC,EAC/B,KAAK,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC,EAChC,KAAK,EAAE,aAAa,EACpB,YAAY,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,CAAC,GACxC,CAAC,CAOH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/renderers/table/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,EAAE,EACP,KAAK,aAAa,EACnB,MAAM,OAAO,CAAC;AACf,OAAO,EAKL,KAAK,SAAS,EAEf,MAAM,cAAc,CAAC;AAQtB,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/renderers/table/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,EAAE,EACP,KAAK,aAAa,EACnB,MAAM,OAAO,CAAC;AACf,OAAO,EAKL,KAAK,SAAS,EAEf,MAAM,cAAc,CAAC;AAQtB,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAI/B,KAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,OAAO,gBAAgB,EAAE,YAAY,CAAC;IAC5C,QAAQ,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAC3C,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAQF,eAAO,MAAM,aAAa,EAAE,EAAE,CAAC,kBAAkB,CAwShD,CAAC"}
|
package/nitro.json
CHANGED
|
@@ -9,11 +9,20 @@
|
|
|
9
9
|
},
|
|
10
10
|
"autolinking": {
|
|
11
11
|
"MarkdownParser": {
|
|
12
|
-
"
|
|
12
|
+
"all": {
|
|
13
|
+
"language": "c++",
|
|
14
|
+
"implementationClassName": "HybridMarkdownParser"
|
|
15
|
+
}
|
|
13
16
|
},
|
|
14
17
|
"MarkdownSession": {
|
|
15
|
-
"
|
|
16
|
-
|
|
18
|
+
"ios": {
|
|
19
|
+
"language": "swift",
|
|
20
|
+
"implementationClassName": "HybridMarkdownSession"
|
|
21
|
+
},
|
|
22
|
+
"android": {
|
|
23
|
+
"language": "kotlin",
|
|
24
|
+
"implementationClassName": "HybridMarkdownSession"
|
|
25
|
+
}
|
|
17
26
|
}
|
|
18
27
|
}
|
|
19
28
|
}
|
|
@@ -30,9 +30,9 @@ int initialize(JavaVM* vm) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
struct JHybridMarkdownSessionSpecImpl: public jni::JavaClass<JHybridMarkdownSessionSpecImpl, JHybridMarkdownSessionSpec::JavaPart> {
|
|
33
|
-
static auto
|
|
33
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/com/nitromarkdown/HybridMarkdownSession;";
|
|
34
34
|
static std::shared_ptr<JHybridMarkdownSessionSpec> create() {
|
|
35
|
-
static auto constructorFn = javaClassStatic()->getConstructor<JHybridMarkdownSessionSpecImpl::javaobject()>();
|
|
35
|
+
static const auto constructorFn = javaClassStatic()->getConstructor<JHybridMarkdownSessionSpecImpl::javaobject()>();
|
|
36
36
|
jni::local_ref<JHybridMarkdownSessionSpec::JavaPart> javaPart = javaClassStatic()->newObject(constructorFn);
|
|
37
37
|
return javaPart->getJHybridMarkdownSessionSpec();
|
|
38
38
|
}
|
|
@@ -23,7 +23,7 @@ namespace margelo::nitro::Markdown {
|
|
|
23
23
|
*/
|
|
24
24
|
struct JFunc_void: public jni::JavaClass<JFunc_void> {
|
|
25
25
|
public:
|
|
26
|
-
static auto
|
|
26
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/com/nitromarkdown/Func_void;";
|
|
27
27
|
|
|
28
28
|
public:
|
|
29
29
|
/**
|
|
@@ -59,7 +59,7 @@ namespace margelo::nitro::Markdown {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
public:
|
|
62
|
-
static auto
|
|
62
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/com/nitromarkdown/Func_void_cxx;";
|
|
63
63
|
static void registerNatives() {
|
|
64
64
|
registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_cxx::invoke_cxx)});
|
|
65
65
|
}
|
|
@@ -23,7 +23,7 @@ namespace margelo::nitro::Markdown {
|
|
|
23
23
|
*/
|
|
24
24
|
struct JFunc_void_double_double: public jni::JavaClass<JFunc_void_double_double> {
|
|
25
25
|
public:
|
|
26
|
-
static auto
|
|
26
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/com/nitromarkdown/Func_void_double_double;";
|
|
27
27
|
|
|
28
28
|
public:
|
|
29
29
|
/**
|
|
@@ -59,7 +59,7 @@ namespace margelo::nitro::Markdown {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
public:
|
|
62
|
-
static auto
|
|
62
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/com/nitromarkdown/Func_void_double_double_cxx;";
|
|
63
63
|
static void registerNatives() {
|
|
64
64
|
registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_double_double_cxx::invoke_cxx)});
|
|
65
65
|
}
|
|
@@ -21,11 +21,11 @@ namespace margelo::nitro::Markdown {
|
|
|
21
21
|
class JHybridMarkdownSessionSpec: public virtual HybridMarkdownSessionSpec, public virtual JHybridObject {
|
|
22
22
|
public:
|
|
23
23
|
struct JavaPart: public jni::JavaClass<JavaPart, JHybridObject::JavaPart> {
|
|
24
|
-
static auto
|
|
24
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/com/nitromarkdown/HybridMarkdownSessionSpec;";
|
|
25
25
|
std::shared_ptr<JHybridMarkdownSessionSpec> getJHybridMarkdownSessionSpec();
|
|
26
26
|
};
|
|
27
27
|
struct CxxPart: public jni::HybridClass<CxxPart, JHybridObject::CxxPart> {
|
|
28
|
-
static auto
|
|
28
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/com/nitromarkdown/HybridMarkdownSessionSpec$CxxPart;";
|
|
29
29
|
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
|
|
30
30
|
static void registerNatives();
|
|
31
31
|
using HybridBase::HybridBase;
|
|
@@ -56,5 +56,7 @@ def add_nitrogen_files(spec)
|
|
|
56
56
|
"SWIFT_OBJC_INTEROP_MODE" => "objcxx",
|
|
57
57
|
# Enables stricter modular headers
|
|
58
58
|
"DEFINES_MODULE" => "YES",
|
|
59
|
+
# Disable auto-generated ObjC header for Swift (Static linkage on Xcode 26.4 breaks here)
|
|
60
|
+
"SWIFT_INSTALL_OBJC_HEADER" => "NO",
|
|
59
61
|
})
|
|
60
62
|
end
|
|
@@ -41,10 +41,11 @@ namespace margelo::nitro::Markdown {
|
|
|
41
41
|
public:
|
|
42
42
|
std::optional<bool> gfm SWIFT_PRIVATE;
|
|
43
43
|
std::optional<bool> math SWIFT_PRIVATE;
|
|
44
|
+
std::optional<bool> html SWIFT_PRIVATE;
|
|
44
45
|
|
|
45
46
|
public:
|
|
46
47
|
ParserOptions() = default;
|
|
47
|
-
explicit ParserOptions(std::optional<bool> gfm, std::optional<bool> math): gfm(gfm), math(math) {}
|
|
48
|
+
explicit ParserOptions(std::optional<bool> gfm, std::optional<bool> math, std::optional<bool> html): gfm(gfm), math(math), html(html) {}
|
|
48
49
|
|
|
49
50
|
public:
|
|
50
51
|
friend bool operator==(const ParserOptions& lhs, const ParserOptions& rhs) = default;
|
|
@@ -61,13 +62,15 @@ namespace margelo::nitro {
|
|
|
61
62
|
jsi::Object obj = arg.asObject(runtime);
|
|
62
63
|
return margelo::nitro::Markdown::ParserOptions(
|
|
63
64
|
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")))
|
|
65
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "math"))),
|
|
66
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "html")))
|
|
65
67
|
);
|
|
66
68
|
}
|
|
67
69
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::Markdown::ParserOptions& arg) {
|
|
68
70
|
jsi::Object obj(runtime);
|
|
69
71
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "gfm"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.gfm));
|
|
70
72
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "math"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.math));
|
|
73
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "html"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.html));
|
|
71
74
|
return obj;
|
|
72
75
|
}
|
|
73
76
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -80,6 +83,7 @@ namespace margelo::nitro {
|
|
|
80
83
|
}
|
|
81
84
|
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "gfm")))) return false;
|
|
82
85
|
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "math")))) return false;
|
|
86
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "html")))) return false;
|
|
83
87
|
return true;
|
|
84
88
|
}
|
|
85
89
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-markdown",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
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",
|
|
@@ -91,18 +91,18 @@
|
|
|
91
91
|
},
|
|
92
92
|
"devDependencies": {
|
|
93
93
|
"@size-limit/preset-small-lib": "^11.0.0",
|
|
94
|
-
"@types/react": "~19.2.
|
|
94
|
+
"@types/react": "~19.2.14",
|
|
95
95
|
"@types/react-native": "^0.73.0",
|
|
96
96
|
"@types/react-test-renderer": "^19.1.0",
|
|
97
|
-
"react-native-builder-bob": "^0.
|
|
98
|
-
"react-test-renderer": "
|
|
97
|
+
"react-native-builder-bob": "^0.41.0",
|
|
98
|
+
"react-test-renderer": "19.2.0",
|
|
99
99
|
"size-limit": "^11.0.0",
|
|
100
100
|
"typescript": "^5.9.3"
|
|
101
101
|
},
|
|
102
102
|
"peerDependencies": {
|
|
103
103
|
"react": "*",
|
|
104
104
|
"react-native": ">=0.75.0",
|
|
105
|
-
"react-native-nitro-modules": ">=0.35.
|
|
105
|
+
"react-native-nitro-modules": ">=0.35.4",
|
|
106
106
|
"react-native-mathjax-svg": ">=0.9.0",
|
|
107
107
|
"react-native-svg": ">=13.0.0"
|
|
108
108
|
},
|
package/src/Markdown.nitro.ts
CHANGED
package/src/headless.ts
CHANGED
|
@@ -100,7 +100,7 @@ export function parseMarkdown(text: string): MarkdownNode;
|
|
|
100
100
|
/**
|
|
101
101
|
* Parse markdown text with custom options.
|
|
102
102
|
* @param text - The markdown text to parse
|
|
103
|
-
* @param options - Parser options (gfm, math)
|
|
103
|
+
* @param options - Parser options (gfm, math, html)
|
|
104
104
|
* @returns The root node of the parsed AST
|
|
105
105
|
*/
|
|
106
106
|
export function parseMarkdown(
|
|
@@ -134,7 +134,7 @@ export function parseMarkdown(
|
|
|
134
134
|
/**
|
|
135
135
|
* Parse markdown text with custom options.
|
|
136
136
|
* @param text - The markdown text to parse
|
|
137
|
-
* @param options - Parser options (gfm, math)
|
|
137
|
+
* @param options - Parser options (gfm, math, html)
|
|
138
138
|
* @returns The root node of the parsed AST
|
|
139
139
|
*/
|
|
140
140
|
export function parseMarkdownWithOptions(
|
package/src/markdown.tsx
CHANGED
|
@@ -104,6 +104,7 @@ const baseStylesCache = new WeakMap<MarkdownTheme, BaseStyles>();
|
|
|
104
104
|
const parseAstCache = new Map<string, MarkdownNode>();
|
|
105
105
|
const MAX_PARSE_CACHE_ENTRIES = 32;
|
|
106
106
|
const MAX_CACHEABLE_TEXT_LENGTH = 24_000;
|
|
107
|
+
const EMPTY_RENDERERS: CustomRenderers = {};
|
|
107
108
|
|
|
108
109
|
export type AstTransform = (ast: MarkdownNode) => MarkdownNode;
|
|
109
110
|
export type MarkdownVirtualizationOptions = Pick<
|
|
@@ -166,12 +167,14 @@ const cloneMarkdownNode = (node: MarkdownNode): MarkdownNode => {
|
|
|
166
167
|
};
|
|
167
168
|
|
|
168
169
|
const getParserOptionsKey = (options?: ParserOptions): string => {
|
|
169
|
-
if (!options) return "gfm:default|math:default";
|
|
170
|
+
if (!options) return "gfm:default|math:default|html:default";
|
|
170
171
|
|
|
171
172
|
const gfm = options.gfm === undefined ? "default" : options.gfm ? "1" : "0";
|
|
172
173
|
const math =
|
|
173
174
|
options.math === undefined ? "default" : options.math ? "1" : "0";
|
|
174
|
-
|
|
175
|
+
const html =
|
|
176
|
+
options.html === undefined ? "default" : options.html ? "1" : "0";
|
|
177
|
+
return `gfm:${gfm}|math:${math}|html:${html}`;
|
|
175
178
|
};
|
|
176
179
|
|
|
177
180
|
const normalizeParserOptions = (
|
|
@@ -181,14 +184,16 @@ const normalizeParserOptions = (
|
|
|
181
184
|
|
|
182
185
|
const gfm = options.gfm;
|
|
183
186
|
const math = options.math;
|
|
187
|
+
const html = options.html;
|
|
184
188
|
|
|
185
|
-
if (gfm === undefined && math === undefined) {
|
|
189
|
+
if (gfm === undefined && math === undefined && html === undefined) {
|
|
186
190
|
return undefined;
|
|
187
191
|
}
|
|
188
192
|
|
|
189
193
|
return {
|
|
190
194
|
gfm,
|
|
191
195
|
math,
|
|
196
|
+
html,
|
|
192
197
|
};
|
|
193
198
|
};
|
|
194
199
|
|
|
@@ -304,7 +309,7 @@ export type MarkdownProps = {
|
|
|
304
309
|
*/
|
|
305
310
|
children: string;
|
|
306
311
|
/**
|
|
307
|
-
* Parser options to enable GFM or
|
|
312
|
+
* Parser options to enable GFM, math, or raw HTML AST support.
|
|
308
313
|
*/
|
|
309
314
|
options?: ParserOptions;
|
|
310
315
|
/**
|
|
@@ -421,7 +426,7 @@ export const Markdown: FC<MarkdownProps> = ({
|
|
|
421
426
|
plugins,
|
|
422
427
|
sourceAst,
|
|
423
428
|
astTransform,
|
|
424
|
-
renderers =
|
|
429
|
+
renderers = EMPTY_RENDERERS,
|
|
425
430
|
theme: userTheme,
|
|
426
431
|
styles: nodeStyles,
|
|
427
432
|
stylingStrategy = "opinionated",
|
|
@@ -438,31 +443,30 @@ export const Markdown: FC<MarkdownProps> = ({
|
|
|
438
443
|
}) => {
|
|
439
444
|
const parserOptionGfm = options?.gfm;
|
|
440
445
|
const parserOptionMath = options?.math;
|
|
446
|
+
const parserOptionHtml = options?.html;
|
|
441
447
|
|
|
442
448
|
/* eslint-disable react-hooks/refs -- Refs updated/read intentionally to avoid re-parsing on callback identity changes */
|
|
443
449
|
const onErrorRef = useRef(onError);
|
|
444
450
|
onErrorRef.current = onError;
|
|
445
451
|
|
|
446
|
-
const pluginsRef = useRef(plugins);
|
|
447
|
-
pluginsRef.current = plugins;
|
|
448
|
-
|
|
449
452
|
const parseResult = useMemo(() => {
|
|
450
453
|
try {
|
|
451
454
|
const markdownToParse = applyBeforeParsePlugins(
|
|
452
455
|
children,
|
|
453
|
-
|
|
456
|
+
plugins,
|
|
454
457
|
onErrorRef.current,
|
|
455
458
|
);
|
|
456
459
|
const parserOptions = normalizeParserOptions({
|
|
457
460
|
gfm: parserOptionGfm,
|
|
458
461
|
math: parserOptionMath,
|
|
462
|
+
html: parserOptionHtml,
|
|
459
463
|
});
|
|
460
464
|
let parsedAst = sourceAst
|
|
461
465
|
? cloneMarkdownNode(sourceAst)
|
|
462
466
|
: getCachedParsedAst(markdownToParse, parserOptions);
|
|
463
467
|
parsedAst = applyAfterParsePlugins(
|
|
464
468
|
parsedAst,
|
|
465
|
-
|
|
469
|
+
plugins,
|
|
466
470
|
onErrorRef.current,
|
|
467
471
|
);
|
|
468
472
|
|
|
@@ -491,12 +495,26 @@ export const Markdown: FC<MarkdownProps> = ({
|
|
|
491
495
|
ast: null,
|
|
492
496
|
};
|
|
493
497
|
}
|
|
494
|
-
}, [
|
|
498
|
+
}, [
|
|
499
|
+
children,
|
|
500
|
+
parserOptionGfm,
|
|
501
|
+
parserOptionMath,
|
|
502
|
+
parserOptionHtml,
|
|
503
|
+
sourceAst,
|
|
504
|
+
astTransform,
|
|
505
|
+
plugins,
|
|
506
|
+
]);
|
|
495
507
|
/* eslint-enable react-hooks/refs */
|
|
496
508
|
|
|
497
509
|
useEffect(() => {
|
|
498
510
|
onParsingInProgress?.();
|
|
499
|
-
}, [
|
|
511
|
+
}, [
|
|
512
|
+
children,
|
|
513
|
+
parserOptionGfm,
|
|
514
|
+
parserOptionMath,
|
|
515
|
+
parserOptionHtml,
|
|
516
|
+
onParsingInProgress,
|
|
517
|
+
]);
|
|
500
518
|
|
|
501
519
|
useEffect(() => {
|
|
502
520
|
if (!parseResult.ast || !onParseComplete) return;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { FC, ReactNode } from "react";
|
|
2
2
|
import { View, StyleSheet, type ViewStyle } from "react-native";
|
|
3
|
+
import { getCachedStyles } from "./style-cache";
|
|
3
4
|
import { useMarkdownContext } from "../MarkdownContext";
|
|
5
|
+
import type { MarkdownTheme } from "../theme";
|
|
4
6
|
|
|
5
7
|
type BlockquoteProps = {
|
|
6
8
|
children: ReactNode;
|
|
@@ -9,22 +11,25 @@ type BlockquoteProps = {
|
|
|
9
11
|
|
|
10
12
|
export const Blockquote: FC<BlockquoteProps> = ({ children, style }) => {
|
|
11
13
|
const { theme } = useMarkdownContext();
|
|
12
|
-
const styles =
|
|
13
|
-
() =>
|
|
14
|
-
StyleSheet.create({
|
|
15
|
-
blockquote: {
|
|
16
|
-
borderLeftWidth: 4,
|
|
17
|
-
borderLeftColor: theme.colors.blockquote,
|
|
18
|
-
paddingLeft: theme.spacing.l,
|
|
19
|
-
marginVertical: theme.spacing.m,
|
|
20
|
-
backgroundColor: theme.colors.surfaceLight,
|
|
21
|
-
paddingVertical: theme.spacing.m,
|
|
22
|
-
paddingRight: theme.spacing.m,
|
|
23
|
-
borderRadius: theme.borderRadius.s,
|
|
24
|
-
},
|
|
25
|
-
}),
|
|
26
|
-
[theme],
|
|
27
|
-
);
|
|
14
|
+
const styles = getCachedStyles(stylesCache, theme, createStyles);
|
|
28
15
|
|
|
29
16
|
return <View style={[styles.blockquote, style]}>{children}</View>;
|
|
30
17
|
};
|
|
18
|
+
|
|
19
|
+
type BlockquoteStyles = ReturnType<typeof createStyles>;
|
|
20
|
+
|
|
21
|
+
const stylesCache = new WeakMap<MarkdownTheme, BlockquoteStyles>();
|
|
22
|
+
|
|
23
|
+
const createStyles = (theme: MarkdownTheme) =>
|
|
24
|
+
StyleSheet.create({
|
|
25
|
+
blockquote: {
|
|
26
|
+
borderLeftWidth: 4,
|
|
27
|
+
borderLeftColor: theme.colors.blockquote,
|
|
28
|
+
paddingLeft: theme.spacing.l,
|
|
29
|
+
marginVertical: theme.spacing.m,
|
|
30
|
+
backgroundColor: theme.colors.surfaceLight,
|
|
31
|
+
paddingVertical: theme.spacing.m,
|
|
32
|
+
paddingRight: theme.spacing.m,
|
|
33
|
+
borderRadius: theme.borderRadius.s,
|
|
34
|
+
},
|
|
35
|
+
});
|
package/src/renderers/code.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
type ViewStyle,
|
|
9
9
|
type TextStyle,
|
|
10
10
|
} from "react-native";
|
|
11
|
+
import { getCachedStyles } from "./style-cache";
|
|
11
12
|
import { getTextContent } from "../headless";
|
|
12
13
|
import { useMarkdownContext } from "../MarkdownContext";
|
|
13
14
|
import {
|
|
@@ -15,6 +16,7 @@ import {
|
|
|
15
16
|
type HighlightedToken,
|
|
16
17
|
} from "../utils/code-highlight";
|
|
17
18
|
import type { MarkdownNode } from "../headless";
|
|
19
|
+
import type { MarkdownTheme } from "../theme";
|
|
18
20
|
|
|
19
21
|
type CodeBlockProps = {
|
|
20
22
|
language?: string;
|
|
@@ -40,41 +42,14 @@ export const CodeBlock: FC<CodeBlockProps> = ({
|
|
|
40
42
|
: null;
|
|
41
43
|
|
|
42
44
|
const displayContent = content ?? (node ? getTextContent(node) : "");
|
|
43
|
-
|
|
44
|
-
const styles = useMemo(
|
|
45
|
+
const highlightedTokens = useMemo(
|
|
45
46
|
() =>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
backgroundColor: theme.colors.codeBackground,
|
|
49
|
-
borderRadius: theme.borderRadius.m,
|
|
50
|
-
padding: theme.spacing.l,
|
|
51
|
-
marginVertical: theme.spacing.m,
|
|
52
|
-
borderWidth: 1,
|
|
53
|
-
borderColor: theme.colors.border,
|
|
54
|
-
},
|
|
55
|
-
codeLanguage: {
|
|
56
|
-
color: theme.colors.codeLanguage,
|
|
57
|
-
fontSize: theme.fontSizes.xs,
|
|
58
|
-
fontWeight: "600",
|
|
59
|
-
marginBottom: theme.spacing.s,
|
|
60
|
-
textTransform: "uppercase",
|
|
61
|
-
letterSpacing: 0.5,
|
|
62
|
-
fontFamily: theme.fontFamilies.mono,
|
|
63
|
-
...(Platform.OS === "android" && { includeFontPadding: false }),
|
|
64
|
-
},
|
|
65
|
-
codeBlockText: {
|
|
66
|
-
fontFamily:
|
|
67
|
-
theme.fontFamilies.mono ??
|
|
68
|
-
Platform.select({ ios: "Courier", android: "monospace" }),
|
|
69
|
-
fontSize: theme.fontSizes.s,
|
|
70
|
-
color: theme.colors.text,
|
|
71
|
-
lineHeight: theme.fontSizes.s * 1.5,
|
|
72
|
-
...(Platform.OS === "android" && { includeFontPadding: false }),
|
|
73
|
-
},
|
|
74
|
-
}),
|
|
75
|
-
[theme],
|
|
47
|
+
highlighter && language ? highlighter(language, displayContent) : null,
|
|
48
|
+
[displayContent, highlighter, language],
|
|
76
49
|
);
|
|
77
50
|
|
|
51
|
+
const styles = getCachedStyles(codeBlockStylesCache, theme, createCodeStyles);
|
|
52
|
+
|
|
78
53
|
const showLanguage = theme.showCodeLanguage && language;
|
|
79
54
|
|
|
80
55
|
return (
|
|
@@ -87,21 +62,18 @@ export const CodeBlock: FC<CodeBlockProps> = ({
|
|
|
87
62
|
showsHorizontalScrollIndicator={false}
|
|
88
63
|
bounces={false}
|
|
89
64
|
>
|
|
90
|
-
{
|
|
65
|
+
{highlightedTokens ? (
|
|
91
66
|
<Text style={styles.codeBlockText} selectable>
|
|
92
|
-
{
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
);
|
|
103
|
-
},
|
|
104
|
-
)}
|
|
67
|
+
{highlightedTokens.map((token: HighlightedToken, i: number) => {
|
|
68
|
+
const tokenColor = ctx.theme.colors.codeTokenColors?.[token.type];
|
|
69
|
+
return tokenColor ? (
|
|
70
|
+
<Text key={i} style={{ color: tokenColor }}>
|
|
71
|
+
{token.text}
|
|
72
|
+
</Text>
|
|
73
|
+
) : (
|
|
74
|
+
<Text key={i}>{token.text}</Text>
|
|
75
|
+
);
|
|
76
|
+
})}
|
|
105
77
|
</Text>
|
|
106
78
|
) : (
|
|
107
79
|
<Text style={styles.codeBlockText} selectable>
|
|
@@ -131,23 +103,63 @@ export const InlineCode: FC<InlineCodeProps> = ({
|
|
|
131
103
|
const displayContent =
|
|
132
104
|
content ?? children ?? (node ? getTextContent(node) : "");
|
|
133
105
|
|
|
134
|
-
const styles =
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
fontFamily:
|
|
139
|
-
theme.fontFamilies.mono ??
|
|
140
|
-
Platform.select({ ios: "Courier", android: "monospace" }),
|
|
141
|
-
fontSize: theme.fontSizes.s,
|
|
142
|
-
color: theme.colors.code,
|
|
143
|
-
backgroundColor: theme.colors.codeBackground,
|
|
144
|
-
paddingHorizontal: theme.spacing.xs,
|
|
145
|
-
paddingVertical: 2,
|
|
146
|
-
borderRadius: theme.borderRadius.s,
|
|
147
|
-
...(Platform.OS === "android" && { includeFontPadding: false }),
|
|
148
|
-
},
|
|
149
|
-
}),
|
|
150
|
-
[theme],
|
|
106
|
+
const styles = getCachedStyles(
|
|
107
|
+
inlineCodeStylesCache,
|
|
108
|
+
theme,
|
|
109
|
+
createInlineStyles,
|
|
151
110
|
);
|
|
152
111
|
return <Text style={[styles.codeInline, style]}>{displayContent}</Text>;
|
|
153
112
|
};
|
|
113
|
+
|
|
114
|
+
type CodeBlockStyles = ReturnType<typeof createCodeStyles>;
|
|
115
|
+
type InlineCodeStyles = ReturnType<typeof createInlineStyles>;
|
|
116
|
+
|
|
117
|
+
const codeBlockStylesCache = new WeakMap<MarkdownTheme, CodeBlockStyles>();
|
|
118
|
+
const inlineCodeStylesCache = new WeakMap<MarkdownTheme, InlineCodeStyles>();
|
|
119
|
+
|
|
120
|
+
const getMonoFontFamily = (theme: MarkdownTheme) =>
|
|
121
|
+
theme.fontFamilies.mono ??
|
|
122
|
+
Platform.select({ ios: "Courier", android: "monospace" });
|
|
123
|
+
|
|
124
|
+
const createCodeStyles = (theme: MarkdownTheme) =>
|
|
125
|
+
StyleSheet.create({
|
|
126
|
+
codeBlock: {
|
|
127
|
+
backgroundColor: theme.colors.codeBackground,
|
|
128
|
+
borderRadius: theme.borderRadius.m,
|
|
129
|
+
padding: theme.spacing.l,
|
|
130
|
+
marginVertical: theme.spacing.m,
|
|
131
|
+
borderWidth: 1,
|
|
132
|
+
borderColor: theme.colors.border,
|
|
133
|
+
},
|
|
134
|
+
codeLanguage: {
|
|
135
|
+
color: theme.colors.codeLanguage,
|
|
136
|
+
fontSize: theme.fontSizes.xs,
|
|
137
|
+
fontWeight: "600",
|
|
138
|
+
marginBottom: theme.spacing.s,
|
|
139
|
+
textTransform: "uppercase",
|
|
140
|
+
letterSpacing: 0.5,
|
|
141
|
+
fontFamily: theme.fontFamilies.mono,
|
|
142
|
+
...(Platform.OS === "android" && { includeFontPadding: false }),
|
|
143
|
+
},
|
|
144
|
+
codeBlockText: {
|
|
145
|
+
fontFamily: getMonoFontFamily(theme),
|
|
146
|
+
fontSize: theme.fontSizes.s,
|
|
147
|
+
color: theme.colors.text,
|
|
148
|
+
lineHeight: theme.fontSizes.s * 1.5,
|
|
149
|
+
...(Platform.OS === "android" && { includeFontPadding: false }),
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const createInlineStyles = (theme: MarkdownTheme) =>
|
|
154
|
+
StyleSheet.create({
|
|
155
|
+
codeInline: {
|
|
156
|
+
fontFamily: getMonoFontFamily(theme),
|
|
157
|
+
fontSize: theme.fontSizes.s,
|
|
158
|
+
color: theme.colors.code,
|
|
159
|
+
backgroundColor: theme.colors.codeBackground,
|
|
160
|
+
paddingHorizontal: theme.spacing.xs,
|
|
161
|
+
paddingVertical: 2,
|
|
162
|
+
borderRadius: theme.borderRadius.s,
|
|
163
|
+
...(Platform.OS === "android" && { includeFontPadding: false }),
|
|
164
|
+
},
|
|
165
|
+
});
|