react-native-enriched-markdown 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +551 -0
- package/ReactNativeEnrichedMarkdown.podspec +27 -0
- package/android/build.gradle +101 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerDelegate.java +54 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerInterface.java +26 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/ComponentDescriptors.cpp +22 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/ComponentDescriptors.h +24 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.cpp +33 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.h +31 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.cpp +82 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.h +1388 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/ShadowNodes.cpp +17 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/ShadowNodes.h +32 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/States.cpp +16 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/States.h +20 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/baseline-prof.txt +65 -0
- package/android/src/main/cpp/jni-adapter.cpp +220 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownText.kt +270 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownTextLayoutManager.kt +15 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownTextManager.kt +173 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownTextPackage.kt +17 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/MeasurementStore.kt +385 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/accessibility/MarkdownAccessibilityHelper.kt +279 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/events/LinkLongPressEvent.kt +23 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/events/LinkPressEvent.kt +23 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/parser/MarkdownASTNode.kt +31 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/parser/Parser.kt +62 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockStyleContext.kt +166 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockquoteRenderer.kt +84 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/CodeBlockRenderer.kt +104 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/CodeRenderer.kt +36 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/DocumentRenderer.kt +16 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/EmphasisRenderer.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/HeadingRenderer.kt +70 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/ImageRenderer.kt +68 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/LineBreakRenderer.kt +16 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/LinkRenderer.kt +29 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/ListContextManager.kt +105 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/ListItemRenderer.kt +59 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/ListRenderer.kt +76 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/NodeRenderer.kt +103 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/ParagraphRenderer.kt +80 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/Renderer.kt +109 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/SpanStyleCache.kt +86 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/StrikethroughRenderer.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/StrongRenderer.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/TextRenderer.kt +30 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/ThematicBreakRenderer.kt +45 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/UnderlineRenderer.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/BaseListSpan.kt +136 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/BlockquoteSpan.kt +135 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/CodeBackgroundSpan.kt +180 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/CodeBlockSpan.kt +196 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/CodeSpan.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/EmphasisSpan.kt +34 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/HeadingSpan.kt +38 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/ImageSpan.kt +321 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/LineHeightSpan.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/LinkSpan.kt +51 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/MarginBottomSpan.kt +76 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/OrderedListSpan.kt +87 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/StrikethroughSpan.kt +12 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/StrongSpan.kt +37 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/TextSpan.kt +26 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/ThematicBreakSpan.kt +69 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/UnorderedListSpan.kt +69 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/BaseBlockStyle.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/BlockquoteStyle.kt +51 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/CodeBlockStyle.kt +54 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/CodeStyle.kt +21 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/EmphasisStyle.kt +17 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/HeadingStyle.kt +33 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/ImageStyle.kt +23 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/InlineImageStyle.kt +17 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/LinkStyle.kt +19 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/ListStyle.kt +57 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/ParagraphStyle.kt +33 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/StrikethroughStyle.kt +17 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/StrongStyle.kt +17 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/StyleConfig.kt +211 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/StyleParser.kt +92 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/TextAlignment.kt +32 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/ThematicBreakStyle.kt +23 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/UnderlineStyle.kt +17 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/AsyncDrawable.kt +91 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/HTMLGenerator.kt +827 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/LinkLongPressMovementMethod.kt +121 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/MarkdownExtractor.kt +375 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/SelectionActionMode.kt +139 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/Utils.kt +183 -0
- package/android/src/main/jni/CMakeLists.txt +70 -0
- package/android/src/main/jni/EnrichedMarkdownTextSpec.cpp +21 -0
- package/android/src/main/jni/EnrichedMarkdownTextSpec.h +25 -0
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/MarkdownTextComponentDescriptor.h +29 -0
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/MarkdownTextMeasurementManager.cpp +45 -0
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/MarkdownTextMeasurementManager.h +21 -0
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/MarkdownTextShadowNode.cpp +20 -0
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/MarkdownTextShadowNode.h +37 -0
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/conversions.h +22 -0
- package/cpp/md4c/md4c.c +6492 -0
- package/cpp/md4c/md4c.h +402 -0
- package/cpp/parser/MD4CParser.cpp +327 -0
- package/cpp/parser/MD4CParser.hpp +27 -0
- package/cpp/parser/MarkdownASTNode.hpp +51 -0
- package/ios/EnrichedMarkdownText.h +18 -0
- package/ios/EnrichedMarkdownText.mm +1401 -0
- package/ios/attachments/EnrichedMarkdownImageAttachment.h +23 -0
- package/ios/attachments/EnrichedMarkdownImageAttachment.m +185 -0
- package/ios/attachments/ThematicBreakAttachment.h +15 -0
- package/ios/attachments/ThematicBreakAttachment.m +33 -0
- package/ios/generated/EnrichedMarkdownTextSpec/ComponentDescriptors.cpp +22 -0
- package/ios/generated/EnrichedMarkdownTextSpec/ComponentDescriptors.h +24 -0
- package/ios/generated/EnrichedMarkdownTextSpec/EventEmitters.cpp +33 -0
- package/ios/generated/EnrichedMarkdownTextSpec/EventEmitters.h +31 -0
- package/ios/generated/EnrichedMarkdownTextSpec/Props.cpp +82 -0
- package/ios/generated/EnrichedMarkdownTextSpec/Props.h +1388 -0
- package/ios/generated/EnrichedMarkdownTextSpec/RCTComponentViewHelpers.h +20 -0
- package/ios/generated/EnrichedMarkdownTextSpec/ShadowNodes.cpp +17 -0
- package/ios/generated/EnrichedMarkdownTextSpec/ShadowNodes.h +32 -0
- package/ios/generated/EnrichedMarkdownTextSpec/States.cpp +16 -0
- package/ios/generated/EnrichedMarkdownTextSpec/States.h +20 -0
- package/ios/internals/EnrichedMarkdownTextComponentDescriptor.h +19 -0
- package/ios/internals/EnrichedMarkdownTextShadowNode.h +43 -0
- package/ios/internals/EnrichedMarkdownTextShadowNode.mm +85 -0
- package/ios/internals/EnrichedMarkdownTextState.h +24 -0
- package/ios/parser/MarkdownASTNode.h +35 -0
- package/ios/parser/MarkdownASTNode.m +32 -0
- package/ios/parser/MarkdownParser.h +17 -0
- package/ios/parser/MarkdownParser.mm +42 -0
- package/ios/parser/MarkdownParserBridge.mm +120 -0
- package/ios/renderer/AttributedRenderer.h +11 -0
- package/ios/renderer/AttributedRenderer.m +152 -0
- package/ios/renderer/BlockquoteRenderer.h +7 -0
- package/ios/renderer/BlockquoteRenderer.m +160 -0
- package/ios/renderer/CodeBlockRenderer.h +10 -0
- package/ios/renderer/CodeBlockRenderer.m +90 -0
- package/ios/renderer/CodeRenderer.h +10 -0
- package/ios/renderer/CodeRenderer.m +60 -0
- package/ios/renderer/EmphasisRenderer.h +6 -0
- package/ios/renderer/EmphasisRenderer.m +96 -0
- package/ios/renderer/HeadingRenderer.h +7 -0
- package/ios/renderer/HeadingRenderer.m +105 -0
- package/ios/renderer/ImageRenderer.h +12 -0
- package/ios/renderer/ImageRenderer.m +83 -0
- package/ios/renderer/LinkRenderer.h +7 -0
- package/ios/renderer/LinkRenderer.m +69 -0
- package/ios/renderer/ListItemRenderer.h +16 -0
- package/ios/renderer/ListItemRenderer.m +103 -0
- package/ios/renderer/ListRenderer.h +13 -0
- package/ios/renderer/ListRenderer.m +70 -0
- package/ios/renderer/NodeRenderer.h +8 -0
- package/ios/renderer/ParagraphRenderer.h +7 -0
- package/ios/renderer/ParagraphRenderer.m +80 -0
- package/ios/renderer/RenderContext.h +105 -0
- package/ios/renderer/RenderContext.m +312 -0
- package/ios/renderer/RendererFactory.h +12 -0
- package/ios/renderer/RendererFactory.m +116 -0
- package/ios/renderer/StrikethroughRenderer.h +6 -0
- package/ios/renderer/StrikethroughRenderer.m +40 -0
- package/ios/renderer/StrongRenderer.h +6 -0
- package/ios/renderer/StrongRenderer.m +83 -0
- package/ios/renderer/TextRenderer.h +6 -0
- package/ios/renderer/TextRenderer.m +16 -0
- package/ios/renderer/ThematicBreakRenderer.h +5 -0
- package/ios/renderer/ThematicBreakRenderer.m +53 -0
- package/ios/renderer/UnderlineRenderer.h +6 -0
- package/ios/renderer/UnderlineRenderer.m +39 -0
- package/ios/styles/StyleConfig.h +274 -0
- package/ios/styles/StyleConfig.mm +1806 -0
- package/ios/utils/AccessibilityInfo.h +35 -0
- package/ios/utils/AccessibilityInfo.m +24 -0
- package/ios/utils/BlockquoteBorder.h +20 -0
- package/ios/utils/BlockquoteBorder.m +92 -0
- package/ios/utils/CodeBackground.h +19 -0
- package/ios/utils/CodeBackground.m +191 -0
- package/ios/utils/CodeBlockBackground.h +17 -0
- package/ios/utils/CodeBlockBackground.m +82 -0
- package/ios/utils/EditMenuUtils.h +22 -0
- package/ios/utils/EditMenuUtils.m +118 -0
- package/ios/utils/FontUtils.h +25 -0
- package/ios/utils/FontUtils.m +27 -0
- package/ios/utils/HTMLGenerator.h +20 -0
- package/ios/utils/HTMLGenerator.m +793 -0
- package/ios/utils/LastElementUtils.h +53 -0
- package/ios/utils/ListMarkerDrawer.h +15 -0
- package/ios/utils/ListMarkerDrawer.m +127 -0
- package/ios/utils/MarkdownAccessibilityElementBuilder.h +45 -0
- package/ios/utils/MarkdownAccessibilityElementBuilder.m +323 -0
- package/ios/utils/MarkdownExtractor.h +17 -0
- package/ios/utils/MarkdownExtractor.m +308 -0
- package/ios/utils/ParagraphStyleUtils.h +21 -0
- package/ios/utils/ParagraphStyleUtils.m +111 -0
- package/ios/utils/PasteboardUtils.h +36 -0
- package/ios/utils/PasteboardUtils.m +134 -0
- package/ios/utils/RTFExportUtils.h +24 -0
- package/ios/utils/RTFExportUtils.m +297 -0
- package/ios/utils/RuntimeKeys.h +38 -0
- package/ios/utils/RuntimeKeys.m +11 -0
- package/ios/utils/TextViewLayoutManager.h +14 -0
- package/ios/utils/TextViewLayoutManager.mm +113 -0
- package/lib/module/EnrichedMarkdownText.js +65 -0
- package/lib/module/EnrichedMarkdownText.js.map +1 -0
- package/lib/module/EnrichedMarkdownTextNativeComponent.ts +210 -0
- package/lib/module/index.js +4 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/normalizeMarkdownStyle.js +384 -0
- package/lib/module/normalizeMarkdownStyle.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/EnrichedMarkdownText.d.ts +183 -0
- package/lib/typescript/src/EnrichedMarkdownText.d.ts.map +1 -0
- package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts +185 -0
- package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/normalizeMarkdownStyle.d.ts +6 -0
- package/lib/typescript/src/normalizeMarkdownStyle.d.ts.map +1 -0
- package/package.json +186 -1
- package/react-native.config.js +13 -0
- package/src/EnrichedMarkdownText.tsx +280 -0
- package/src/EnrichedMarkdownTextNativeComponent.ts +210 -0
- package/src/index.tsx +10 -0
- package/src/normalizeMarkdownStyle.ts +423 -0
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
import { Platform, processColor, type ColorValue } from 'react-native';
|
|
2
|
+
import type { MarkdownStyle } from './EnrichedMarkdownText';
|
|
3
|
+
import type { MarkdownStyleInternal } from './EnrichedMarkdownTextNativeComponent';
|
|
4
|
+
|
|
5
|
+
export const normalizeColor = (
|
|
6
|
+
color: string | undefined
|
|
7
|
+
): ColorValue | undefined => {
|
|
8
|
+
if (!color) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return processColor(color);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const defaultTextColor = processColor('#1F2937') as ColorValue;
|
|
16
|
+
const defaultHeadingColor = processColor('#111827') as ColorValue;
|
|
17
|
+
|
|
18
|
+
const getMonospaceFont = () =>
|
|
19
|
+
Platform.select({
|
|
20
|
+
ios: 'Menlo',
|
|
21
|
+
android: 'monospace',
|
|
22
|
+
default: 'monospace',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const getSystemFont = () =>
|
|
26
|
+
Platform.select({
|
|
27
|
+
ios: 'System', // SF Pro on iOS
|
|
28
|
+
android: 'sans-serif',
|
|
29
|
+
default: 'sans-serif',
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// fontWeight: '' allows custom PostScript fonts (e.g., 'Montserrat-Bold') to work on Android
|
|
33
|
+
// Setting a default weight like '700' would interfere with Android's font resolution
|
|
34
|
+
const paragraphDefaultStyles: MarkdownStyleInternal['paragraph'] = {
|
|
35
|
+
fontSize: 16,
|
|
36
|
+
fontFamily: getSystemFont(),
|
|
37
|
+
fontWeight: '',
|
|
38
|
+
color: defaultTextColor,
|
|
39
|
+
lineHeight: Platform.select({ ios: 24, android: 26, default: 26 }),
|
|
40
|
+
marginTop: 0,
|
|
41
|
+
marginBottom: 16,
|
|
42
|
+
textAlign: 'left',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const defaultH1Style: MarkdownStyleInternal['h1'] = {
|
|
46
|
+
fontSize: 30,
|
|
47
|
+
fontFamily: getSystemFont(),
|
|
48
|
+
fontWeight: '',
|
|
49
|
+
color: defaultHeadingColor,
|
|
50
|
+
lineHeight: Platform.select({ ios: 36, android: 38, default: 38 }),
|
|
51
|
+
marginTop: 0,
|
|
52
|
+
marginBottom: 8,
|
|
53
|
+
textAlign: 'left',
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const defaultH2Style: MarkdownStyleInternal['h2'] = {
|
|
57
|
+
fontSize: 24,
|
|
58
|
+
fontFamily: getSystemFont(),
|
|
59
|
+
fontWeight: '',
|
|
60
|
+
color: defaultHeadingColor,
|
|
61
|
+
lineHeight: Platform.select({ ios: 30, android: 32, default: 32 }),
|
|
62
|
+
marginTop: 0,
|
|
63
|
+
marginBottom: 8,
|
|
64
|
+
textAlign: 'left',
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const defaultH3Style: MarkdownStyleInternal['h3'] = {
|
|
68
|
+
fontSize: 20,
|
|
69
|
+
fontFamily: getSystemFont(),
|
|
70
|
+
fontWeight: '',
|
|
71
|
+
color: defaultHeadingColor,
|
|
72
|
+
lineHeight: Platform.select({ ios: 26, android: 28, default: 28 }),
|
|
73
|
+
marginTop: 0,
|
|
74
|
+
marginBottom: 8,
|
|
75
|
+
textAlign: 'left',
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const defaultH4Style: MarkdownStyleInternal['h4'] = {
|
|
79
|
+
fontSize: 18,
|
|
80
|
+
fontFamily: getSystemFont(),
|
|
81
|
+
fontWeight: '',
|
|
82
|
+
color: defaultHeadingColor,
|
|
83
|
+
lineHeight: Platform.select({ ios: 24, android: 26, default: 26 }),
|
|
84
|
+
marginTop: 0,
|
|
85
|
+
marginBottom: 8,
|
|
86
|
+
textAlign: 'left',
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const defaultH5Style: MarkdownStyleInternal['h5'] = {
|
|
90
|
+
fontSize: 16,
|
|
91
|
+
fontFamily: getSystemFont(),
|
|
92
|
+
fontWeight: '',
|
|
93
|
+
color: processColor('#374151') as ColorValue,
|
|
94
|
+
lineHeight: Platform.select({ ios: 22, android: 24, default: 24 }),
|
|
95
|
+
marginTop: 0,
|
|
96
|
+
marginBottom: 8,
|
|
97
|
+
textAlign: 'left',
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const defaultH6Style: MarkdownStyleInternal['h6'] = {
|
|
101
|
+
fontSize: 14,
|
|
102
|
+
fontFamily: getSystemFont(),
|
|
103
|
+
fontWeight: '',
|
|
104
|
+
color: processColor('#4B5563') as ColorValue,
|
|
105
|
+
lineHeight: Platform.select({ ios: 20, android: 22, default: 22 }),
|
|
106
|
+
marginTop: 0,
|
|
107
|
+
marginBottom: 8,
|
|
108
|
+
textAlign: 'left',
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const defaultLinkColor = processColor('#2563EB') as ColorValue;
|
|
112
|
+
|
|
113
|
+
const defaultLinkStyle: MarkdownStyleInternal['link'] = {
|
|
114
|
+
color: defaultLinkColor,
|
|
115
|
+
underline: true,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const defaultCodeColor = processColor('#E01E5A') as ColorValue;
|
|
119
|
+
const defaultCodeBackgroundColor = processColor('#FDF2F4') as ColorValue;
|
|
120
|
+
const defaultCodeBorderColor = processColor('#F8D7DA') as ColorValue;
|
|
121
|
+
|
|
122
|
+
const defaultCodeStyle: MarkdownStyleInternal['code'] = {
|
|
123
|
+
color: defaultCodeColor,
|
|
124
|
+
backgroundColor: defaultCodeBackgroundColor,
|
|
125
|
+
borderColor: defaultCodeBorderColor,
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const defaultImageStyle: MarkdownStyleInternal['image'] = {
|
|
129
|
+
height: 200,
|
|
130
|
+
borderRadius: 8,
|
|
131
|
+
marginTop: 0,
|
|
132
|
+
marginBottom: 16,
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const defaultInlineImageStyle: MarkdownStyleInternal['inlineImage'] = {
|
|
136
|
+
size: 20,
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// Blockquote - subtle but distinct
|
|
140
|
+
const defaultBlockquoteBorderColor = processColor('#D1D5DB') as ColorValue;
|
|
141
|
+
const defaultBlockquoteBackgroundColor = processColor('#F9FAFB') as ColorValue;
|
|
142
|
+
|
|
143
|
+
const defaultBlockquoteStyle: MarkdownStyleInternal['blockquote'] = {
|
|
144
|
+
fontSize: 16,
|
|
145
|
+
fontFamily: getSystemFont(),
|
|
146
|
+
fontWeight: '',
|
|
147
|
+
color: processColor('#4B5563') as ColorValue,
|
|
148
|
+
lineHeight: Platform.select({ ios: 24, android: 26, default: 26 }),
|
|
149
|
+
marginTop: 0,
|
|
150
|
+
marginBottom: 16,
|
|
151
|
+
borderColor: defaultBlockquoteBorderColor,
|
|
152
|
+
borderWidth: 3,
|
|
153
|
+
gapWidth: 16,
|
|
154
|
+
backgroundColor: defaultBlockquoteBackgroundColor,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const defaultListBulletColor = processColor('#6B7280') as ColorValue;
|
|
158
|
+
const defaultListMarkerColor = processColor('#6B7280') as ColorValue;
|
|
159
|
+
|
|
160
|
+
const defaultListStyle: MarkdownStyleInternal['list'] = {
|
|
161
|
+
fontSize: 16,
|
|
162
|
+
fontFamily: getSystemFont(),
|
|
163
|
+
fontWeight: '',
|
|
164
|
+
color: defaultTextColor,
|
|
165
|
+
lineHeight: Platform.select({
|
|
166
|
+
ios: 22,
|
|
167
|
+
android: 26,
|
|
168
|
+
default: 26,
|
|
169
|
+
}),
|
|
170
|
+
marginTop: 0,
|
|
171
|
+
marginBottom: 16,
|
|
172
|
+
bulletColor: defaultListBulletColor,
|
|
173
|
+
bulletSize: 6,
|
|
174
|
+
markerColor: defaultListMarkerColor,
|
|
175
|
+
markerFontWeight: '500',
|
|
176
|
+
gapWidth: 12,
|
|
177
|
+
marginLeft: 24,
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const defaultCodeBlockBackgroundColor = processColor('#1F2937') as ColorValue;
|
|
181
|
+
const defaultCodeBlockBorderColor = processColor('#374151') as ColorValue;
|
|
182
|
+
const defaultCodeBlockTextColor = processColor('#F3F4F6') as ColorValue;
|
|
183
|
+
|
|
184
|
+
const defaultCodeBlockStyle: MarkdownStyleInternal['codeBlock'] = {
|
|
185
|
+
fontSize: 14,
|
|
186
|
+
fontFamily: getMonospaceFont(),
|
|
187
|
+
fontWeight: '',
|
|
188
|
+
color: defaultCodeBlockTextColor,
|
|
189
|
+
lineHeight: Platform.select({ ios: 20, android: 22, default: 22 }),
|
|
190
|
+
marginTop: 0,
|
|
191
|
+
marginBottom: 16,
|
|
192
|
+
backgroundColor: defaultCodeBlockBackgroundColor,
|
|
193
|
+
borderColor: defaultCodeBlockBorderColor,
|
|
194
|
+
borderRadius: 8,
|
|
195
|
+
borderWidth: 1,
|
|
196
|
+
padding: 16,
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const defaultStrikethroughColor = processColor('#9CA3AF') as ColorValue;
|
|
200
|
+
const defaultUnderlineColor = defaultTextColor;
|
|
201
|
+
|
|
202
|
+
const defaultThematicBreakColor = processColor('#E5E7EB') as ColorValue;
|
|
203
|
+
|
|
204
|
+
const defaultThematicBreakStyle: MarkdownStyleInternal['thematicBreak'] = {
|
|
205
|
+
color: defaultThematicBreakColor,
|
|
206
|
+
height: 1,
|
|
207
|
+
marginTop: 24,
|
|
208
|
+
marginBottom: 24,
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
export const normalizeMarkdownStyle = (
|
|
212
|
+
style: MarkdownStyle
|
|
213
|
+
): MarkdownStyleInternal => {
|
|
214
|
+
const paragraph: MarkdownStyleInternal['paragraph'] = {
|
|
215
|
+
fontSize: style.paragraph?.fontSize ?? paragraphDefaultStyles.fontSize,
|
|
216
|
+
fontFamily:
|
|
217
|
+
style.paragraph?.fontFamily ?? paragraphDefaultStyles.fontFamily,
|
|
218
|
+
fontWeight:
|
|
219
|
+
style.paragraph?.fontWeight ?? paragraphDefaultStyles.fontWeight,
|
|
220
|
+
color:
|
|
221
|
+
normalizeColor(style.paragraph?.color) ?? paragraphDefaultStyles.color,
|
|
222
|
+
marginTop: style.paragraph?.marginTop ?? paragraphDefaultStyles.marginTop,
|
|
223
|
+
marginBottom:
|
|
224
|
+
style.paragraph?.marginBottom ?? paragraphDefaultStyles.marginBottom,
|
|
225
|
+
lineHeight:
|
|
226
|
+
style.paragraph?.lineHeight ?? paragraphDefaultStyles.lineHeight,
|
|
227
|
+
textAlign: style.paragraph?.textAlign ?? paragraphDefaultStyles.textAlign,
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const h1: MarkdownStyleInternal['h1'] = {
|
|
231
|
+
fontSize: style.h1?.fontSize ?? defaultH1Style.fontSize,
|
|
232
|
+
fontFamily: style.h1?.fontFamily ?? defaultH1Style.fontFamily,
|
|
233
|
+
fontWeight: style.h1?.fontWeight ?? defaultH1Style.fontWeight,
|
|
234
|
+
color: normalizeColor(style.h1?.color) ?? defaultH1Style.color,
|
|
235
|
+
marginTop: style.h1?.marginTop ?? defaultH1Style.marginTop,
|
|
236
|
+
marginBottom: style.h1?.marginBottom ?? defaultH1Style.marginBottom,
|
|
237
|
+
lineHeight: style.h1?.lineHeight ?? defaultH1Style.lineHeight,
|
|
238
|
+
textAlign: style.h1?.textAlign ?? defaultH1Style.textAlign,
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const h2: MarkdownStyleInternal['h2'] = {
|
|
242
|
+
fontSize: style.h2?.fontSize ?? defaultH2Style.fontSize,
|
|
243
|
+
fontFamily: style.h2?.fontFamily ?? defaultH2Style.fontFamily,
|
|
244
|
+
fontWeight: style.h2?.fontWeight ?? defaultH2Style.fontWeight,
|
|
245
|
+
color: normalizeColor(style.h2?.color) ?? defaultH2Style.color,
|
|
246
|
+
marginTop: style.h2?.marginTop ?? defaultH2Style.marginTop,
|
|
247
|
+
marginBottom: style.h2?.marginBottom ?? defaultH2Style.marginBottom,
|
|
248
|
+
lineHeight: style.h2?.lineHeight ?? defaultH2Style.lineHeight,
|
|
249
|
+
textAlign: style.h2?.textAlign ?? defaultH2Style.textAlign,
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const h3: MarkdownStyleInternal['h3'] = {
|
|
253
|
+
fontSize: style.h3?.fontSize ?? defaultH3Style.fontSize,
|
|
254
|
+
fontFamily: style.h3?.fontFamily ?? defaultH3Style.fontFamily,
|
|
255
|
+
fontWeight: style.h3?.fontWeight ?? defaultH3Style.fontWeight,
|
|
256
|
+
color: normalizeColor(style.h3?.color) ?? defaultH3Style.color,
|
|
257
|
+
marginTop: style.h3?.marginTop ?? defaultH3Style.marginTop,
|
|
258
|
+
marginBottom: style.h3?.marginBottom ?? defaultH3Style.marginBottom,
|
|
259
|
+
lineHeight: style.h3?.lineHeight ?? defaultH3Style.lineHeight,
|
|
260
|
+
textAlign: style.h3?.textAlign ?? defaultH3Style.textAlign,
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const h4: MarkdownStyleInternal['h4'] = {
|
|
264
|
+
fontSize: style.h4?.fontSize ?? defaultH4Style.fontSize,
|
|
265
|
+
fontFamily: style.h4?.fontFamily ?? defaultH4Style.fontFamily,
|
|
266
|
+
fontWeight: style.h4?.fontWeight ?? defaultH4Style.fontWeight,
|
|
267
|
+
color: normalizeColor(style.h4?.color) ?? defaultH4Style.color,
|
|
268
|
+
marginTop: style.h4?.marginTop ?? defaultH4Style.marginTop,
|
|
269
|
+
marginBottom: style.h4?.marginBottom ?? defaultH4Style.marginBottom,
|
|
270
|
+
lineHeight: style.h4?.lineHeight ?? defaultH4Style.lineHeight,
|
|
271
|
+
textAlign: style.h4?.textAlign ?? defaultH4Style.textAlign,
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const h5: MarkdownStyleInternal['h5'] = {
|
|
275
|
+
fontSize: style.h5?.fontSize ?? defaultH5Style.fontSize,
|
|
276
|
+
fontFamily: style.h5?.fontFamily ?? defaultH5Style.fontFamily,
|
|
277
|
+
fontWeight: style.h5?.fontWeight ?? defaultH5Style.fontWeight,
|
|
278
|
+
color: normalizeColor(style.h5?.color) ?? defaultH5Style.color,
|
|
279
|
+
marginTop: style.h5?.marginTop ?? defaultH5Style.marginTop,
|
|
280
|
+
marginBottom: style.h5?.marginBottom ?? defaultH5Style.marginBottom,
|
|
281
|
+
lineHeight: style.h5?.lineHeight ?? defaultH5Style.lineHeight,
|
|
282
|
+
textAlign: style.h5?.textAlign ?? defaultH5Style.textAlign,
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
const h6: MarkdownStyleInternal['h6'] = {
|
|
286
|
+
fontSize: style.h6?.fontSize ?? defaultH6Style.fontSize,
|
|
287
|
+
fontFamily: style.h6?.fontFamily ?? defaultH6Style.fontFamily,
|
|
288
|
+
fontWeight: style.h6?.fontWeight ?? defaultH6Style.fontWeight,
|
|
289
|
+
color: normalizeColor(style.h6?.color) ?? defaultH6Style.color,
|
|
290
|
+
marginTop: style.h6?.marginTop ?? defaultH6Style.marginTop,
|
|
291
|
+
marginBottom: style.h6?.marginBottom ?? defaultH6Style.marginBottom,
|
|
292
|
+
lineHeight: style.h6?.lineHeight ?? defaultH6Style.lineHeight,
|
|
293
|
+
textAlign: style.h6?.textAlign ?? defaultH6Style.textAlign,
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const blockquote: MarkdownStyleInternal['blockquote'] = {
|
|
297
|
+
fontSize: style.blockquote?.fontSize ?? defaultBlockquoteStyle.fontSize,
|
|
298
|
+
fontFamily:
|
|
299
|
+
style.blockquote?.fontFamily ?? defaultBlockquoteStyle.fontFamily,
|
|
300
|
+
fontWeight:
|
|
301
|
+
style.blockquote?.fontWeight ?? defaultBlockquoteStyle.fontWeight,
|
|
302
|
+
color:
|
|
303
|
+
normalizeColor(style.blockquote?.color) ?? defaultBlockquoteStyle.color,
|
|
304
|
+
marginTop: style.blockquote?.marginTop ?? defaultBlockquoteStyle.marginTop,
|
|
305
|
+
marginBottom:
|
|
306
|
+
style.blockquote?.marginBottom ?? defaultBlockquoteStyle.marginBottom,
|
|
307
|
+
lineHeight:
|
|
308
|
+
style.blockquote?.lineHeight ?? defaultBlockquoteStyle.lineHeight,
|
|
309
|
+
borderColor:
|
|
310
|
+
normalizeColor(style.blockquote?.borderColor) ??
|
|
311
|
+
defaultBlockquoteStyle.borderColor,
|
|
312
|
+
borderWidth:
|
|
313
|
+
style.blockquote?.borderWidth ?? defaultBlockquoteStyle.borderWidth,
|
|
314
|
+
gapWidth: style.blockquote?.gapWidth ?? defaultBlockquoteStyle.gapWidth,
|
|
315
|
+
backgroundColor:
|
|
316
|
+
(normalizeColor(style.blockquote?.backgroundColor) as ColorValue) ??
|
|
317
|
+
defaultBlockquoteStyle.backgroundColor,
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const list: MarkdownStyleInternal['list'] = {
|
|
321
|
+
fontSize: style.list?.fontSize ?? defaultListStyle.fontSize,
|
|
322
|
+
fontFamily: style.list?.fontFamily ?? defaultListStyle.fontFamily,
|
|
323
|
+
fontWeight: style.list?.fontWeight ?? defaultListStyle.fontWeight,
|
|
324
|
+
color: normalizeColor(style.list?.color) ?? defaultListStyle.color,
|
|
325
|
+
marginTop: style.list?.marginTop ?? defaultListStyle.marginTop,
|
|
326
|
+
marginBottom: style.list?.marginBottom ?? defaultListStyle.marginBottom,
|
|
327
|
+
lineHeight: style.list?.lineHeight ?? defaultListStyle.lineHeight,
|
|
328
|
+
bulletColor:
|
|
329
|
+
normalizeColor(style.list?.bulletColor) ?? defaultListStyle.bulletColor,
|
|
330
|
+
bulletSize: style.list?.bulletSize ?? defaultListStyle.bulletSize,
|
|
331
|
+
markerColor:
|
|
332
|
+
normalizeColor(style.list?.markerColor) ?? defaultListStyle.markerColor,
|
|
333
|
+
markerFontWeight:
|
|
334
|
+
style.list?.markerFontWeight ?? defaultListStyle.markerFontWeight,
|
|
335
|
+
gapWidth: style.list?.gapWidth ?? defaultListStyle.gapWidth,
|
|
336
|
+
marginLeft: style.list?.marginLeft ?? defaultListStyle.marginLeft,
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
const codeBlock: MarkdownStyleInternal['codeBlock'] = {
|
|
340
|
+
fontSize: style.codeBlock?.fontSize ?? defaultCodeBlockStyle.fontSize,
|
|
341
|
+
fontFamily: style.codeBlock?.fontFamily ?? defaultCodeBlockStyle.fontFamily,
|
|
342
|
+
fontWeight: style.codeBlock?.fontWeight ?? defaultCodeBlockStyle.fontWeight,
|
|
343
|
+
color:
|
|
344
|
+
normalizeColor(style.codeBlock?.color) ?? defaultCodeBlockStyle.color,
|
|
345
|
+
marginTop: style.codeBlock?.marginTop ?? defaultCodeBlockStyle.marginTop,
|
|
346
|
+
marginBottom:
|
|
347
|
+
style.codeBlock?.marginBottom ?? defaultCodeBlockStyle.marginBottom,
|
|
348
|
+
lineHeight: style.codeBlock?.lineHeight ?? defaultCodeBlockStyle.lineHeight,
|
|
349
|
+
backgroundColor:
|
|
350
|
+
normalizeColor(style.codeBlock?.backgroundColor) ??
|
|
351
|
+
defaultCodeBlockStyle.backgroundColor,
|
|
352
|
+
borderColor:
|
|
353
|
+
normalizeColor(style.codeBlock?.borderColor) ??
|
|
354
|
+
defaultCodeBlockStyle.borderColor,
|
|
355
|
+
borderRadius:
|
|
356
|
+
style.codeBlock?.borderRadius ?? defaultCodeBlockStyle.borderRadius,
|
|
357
|
+
borderWidth:
|
|
358
|
+
style.codeBlock?.borderWidth ?? defaultCodeBlockStyle.borderWidth,
|
|
359
|
+
padding: style.codeBlock?.padding ?? defaultCodeBlockStyle.padding,
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
return {
|
|
363
|
+
paragraph,
|
|
364
|
+
h1,
|
|
365
|
+
h2,
|
|
366
|
+
h3,
|
|
367
|
+
h4,
|
|
368
|
+
h5,
|
|
369
|
+
h6,
|
|
370
|
+
blockquote,
|
|
371
|
+
list,
|
|
372
|
+
codeBlock,
|
|
373
|
+
link: {
|
|
374
|
+
...defaultLinkStyle,
|
|
375
|
+
...style.link,
|
|
376
|
+
color: normalizeColor(style.link?.color) ?? defaultLinkStyle.color,
|
|
377
|
+
},
|
|
378
|
+
strong: {
|
|
379
|
+
color: normalizeColor(style.strong?.color),
|
|
380
|
+
},
|
|
381
|
+
em: {
|
|
382
|
+
color: normalizeColor(style.em?.color),
|
|
383
|
+
},
|
|
384
|
+
strikethrough: {
|
|
385
|
+
color:
|
|
386
|
+
normalizeColor(style.strikethrough?.color) ?? defaultStrikethroughColor,
|
|
387
|
+
},
|
|
388
|
+
underline: {
|
|
389
|
+
color: normalizeColor(style.underline?.color) ?? defaultUnderlineColor,
|
|
390
|
+
},
|
|
391
|
+
code: {
|
|
392
|
+
...defaultCodeStyle,
|
|
393
|
+
color: normalizeColor(style.code?.color) ?? defaultCodeStyle.color,
|
|
394
|
+
backgroundColor:
|
|
395
|
+
normalizeColor(style.code?.backgroundColor) ??
|
|
396
|
+
defaultCodeStyle.backgroundColor,
|
|
397
|
+
borderColor:
|
|
398
|
+
normalizeColor(style.code?.borderColor) ?? defaultCodeStyle.borderColor,
|
|
399
|
+
},
|
|
400
|
+
image: {
|
|
401
|
+
...defaultImageStyle,
|
|
402
|
+
height: style.image?.height ?? defaultImageStyle.height,
|
|
403
|
+
borderRadius: style.image?.borderRadius ?? defaultImageStyle.borderRadius,
|
|
404
|
+
marginTop: style.image?.marginTop ?? defaultImageStyle.marginTop,
|
|
405
|
+
marginBottom: style.image?.marginBottom ?? defaultImageStyle.marginBottom,
|
|
406
|
+
},
|
|
407
|
+
inlineImage: {
|
|
408
|
+
...defaultInlineImageStyle,
|
|
409
|
+
size: style.inlineImage?.size ?? defaultInlineImageStyle.size,
|
|
410
|
+
},
|
|
411
|
+
thematicBreak: {
|
|
412
|
+
color:
|
|
413
|
+
normalizeColor(style.thematicBreak?.color) ??
|
|
414
|
+
defaultThematicBreakStyle.color,
|
|
415
|
+
height: style.thematicBreak?.height ?? defaultThematicBreakStyle.height,
|
|
416
|
+
marginTop:
|
|
417
|
+
style.thematicBreak?.marginTop ?? defaultThematicBreakStyle.marginTop,
|
|
418
|
+
marginBottom:
|
|
419
|
+
style.thematicBreak?.marginBottom ??
|
|
420
|
+
defaultThematicBreakStyle.marginBottom,
|
|
421
|
+
},
|
|
422
|
+
};
|
|
423
|
+
};
|