react-native-enriched-markdown 0.1.0 → 0.1.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 +20 -0
- package/README.md +479 -0
- package/ReactNativeEnrichedMarkdown.podspec +27 -0
- package/android/build.gradle +101 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerDelegate.java +39 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerInterface.java +21 -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 +24 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.h +25 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.cpp +57 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.h +1164 -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 +203 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownText.kt +153 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownTextLayoutManager.kt +30 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownTextManager.kt +119 -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 +165 -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 +29 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/parser/Parser.kt +48 -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 +89 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/CodeBlockRenderer.kt +105 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/CodeRenderer.kt +35 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/DocumentRenderer.kt +15 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/EmphasisRenderer.kt +26 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/HeadingRenderer.kt +54 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/ImageRenderer.kt +52 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/LineBreakRenderer.kt +15 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/LinkRenderer.kt +28 -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 +58 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/ListRenderer.kt +69 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/NodeRenderer.kt +99 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/ParagraphRenderer.kt +66 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/Renderer.kt +95 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/SpanStyleCache.kt +85 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/StrongRenderer.kt +26 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/TextRenderer.kt +29 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/ThematicBreakRenderer.kt +44 -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 +320 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/LineHeightSpan.kt +36 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/LinkSpan.kt +37 -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/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 +10 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/BlockquoteStyle.kt +48 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/CodeBlockStyle.kt +51 -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 +29 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/ImageStyle.kt +21 -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 +54 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/ParagraphStyle.kt +29 -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 +180 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/StyleParser.kt +75 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/ThematicBreakStyle.kt +23 -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 +809 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/MarkdownExtractor.kt +365 -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 +181 -0
- package/android/src/main/jni/CMakeLists.txt +82 -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 +33 -0
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/MarkdownTextShadowNode.h +49 -0
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/MarkdownTextState.cpp +9 -0
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/MarkdownTextState.h +25 -0
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/conversions.h +19 -0
- package/cpp/md4c/md4c.c +6492 -0
- package/cpp/md4c/md4c.h +402 -0
- package/cpp/parser/MD4CParser.cpp +314 -0
- package/cpp/parser/MD4CParser.hpp +23 -0
- package/cpp/parser/MarkdownASTNode.hpp +49 -0
- package/ios/EnrichedMarkdownText.h +18 -0
- package/ios/EnrichedMarkdownText.mm +1074 -0
- package/ios/attachments/ImageAttachment.h +23 -0
- package/ios/attachments/ImageAttachment.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 +24 -0
- package/ios/generated/EnrichedMarkdownTextSpec/EventEmitters.h +25 -0
- package/ios/generated/EnrichedMarkdownTextSpec/Props.cpp +57 -0
- package/ios/generated/EnrichedMarkdownTextSpec/Props.h +1164 -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 +33 -0
- package/ios/parser/MarkdownASTNode.m +32 -0
- package/ios/parser/MarkdownParser.h +8 -0
- package/ios/parser/MarkdownParser.mm +13 -0
- package/ios/parser/MarkdownParserBridge.mm +110 -0
- package/ios/renderer/AttributedRenderer.h +9 -0
- package/ios/renderer/AttributedRenderer.m +119 -0
- package/ios/renderer/BlockquoteRenderer.h +7 -0
- package/ios/renderer/BlockquoteRenderer.m +159 -0
- package/ios/renderer/CodeBlockRenderer.h +10 -0
- package/ios/renderer/CodeBlockRenderer.m +89 -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 +98 -0
- package/ios/renderer/ImageRenderer.h +12 -0
- package/ios/renderer/ImageRenderer.m +62 -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 +91 -0
- package/ios/renderer/ListRenderer.h +13 -0
- package/ios/renderer/ListRenderer.m +67 -0
- package/ios/renderer/NodeRenderer.h +8 -0
- package/ios/renderer/ParagraphRenderer.h +7 -0
- package/ios/renderer/ParagraphRenderer.m +69 -0
- package/ios/renderer/RenderContext.h +88 -0
- package/ios/renderer/RenderContext.m +248 -0
- package/ios/renderer/RendererFactory.h +12 -0
- package/ios/renderer/RendererFactory.m +110 -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/styles/StyleConfig.h +228 -0
- package/ios/styles/StyleConfig.mm +1467 -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 +87 -0
- package/ios/utils/EditMenuUtils.h +22 -0
- package/ios/utils/EditMenuUtils.m +118 -0
- package/ios/utils/FontUtils.h +20 -0
- package/ios/utils/FontUtils.m +13 -0
- package/ios/utils/HTMLGenerator.h +20 -0
- package/ios/utils/HTMLGenerator.m +779 -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/MarkdownExtractor.h +17 -0
- package/ios/utils/MarkdownExtractor.m +295 -0
- package/ios/utils/ParagraphStyleUtils.h +13 -0
- package/ios/utils/ParagraphStyleUtils.m +56 -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 +34 -0
- package/lib/module/EnrichedMarkdownText.js.map +1 -0
- package/lib/module/EnrichedMarkdownTextNativeComponent.ts +130 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/normalizeMarkdownStyle.js +340 -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 +101 -0
- package/lib/typescript/src/EnrichedMarkdownText.d.ts.map +1 -0
- package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts +111 -0
- package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +5 -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 +152 -0
- package/src/EnrichedMarkdownTextNativeComponent.ts +130 -0
- package/src/index.tsx +7 -0
- package/src/normalizeMarkdownStyle.ts +377 -0
|
@@ -0,0 +1,377 @@
|
|
|
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
|
+
marginBottom: 16,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const defaultH1Style: MarkdownStyleInternal['h1'] = {
|
|
44
|
+
fontSize: 30,
|
|
45
|
+
fontFamily: getSystemFont(),
|
|
46
|
+
fontWeight: '',
|
|
47
|
+
color: defaultHeadingColor,
|
|
48
|
+
lineHeight: Platform.select({ ios: 36, android: 38, default: 38 }),
|
|
49
|
+
marginBottom: 8,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const defaultH2Style: MarkdownStyleInternal['h2'] = {
|
|
53
|
+
fontSize: 24,
|
|
54
|
+
fontFamily: getSystemFont(),
|
|
55
|
+
fontWeight: '',
|
|
56
|
+
color: defaultHeadingColor,
|
|
57
|
+
lineHeight: Platform.select({ ios: 30, android: 32, default: 32 }),
|
|
58
|
+
marginBottom: 8,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const defaultH3Style: MarkdownStyleInternal['h3'] = {
|
|
62
|
+
fontSize: 20,
|
|
63
|
+
fontFamily: getSystemFont(),
|
|
64
|
+
fontWeight: '',
|
|
65
|
+
color: defaultHeadingColor,
|
|
66
|
+
lineHeight: Platform.select({ ios: 26, android: 28, default: 28 }),
|
|
67
|
+
marginBottom: 8,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const defaultH4Style: MarkdownStyleInternal['h4'] = {
|
|
71
|
+
fontSize: 18,
|
|
72
|
+
fontFamily: getSystemFont(),
|
|
73
|
+
fontWeight: '',
|
|
74
|
+
color: defaultHeadingColor,
|
|
75
|
+
lineHeight: Platform.select({ ios: 24, android: 26, default: 26 }),
|
|
76
|
+
marginBottom: 8,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const defaultH5Style: MarkdownStyleInternal['h5'] = {
|
|
80
|
+
fontSize: 16,
|
|
81
|
+
fontFamily: getSystemFont(),
|
|
82
|
+
fontWeight: '',
|
|
83
|
+
color: processColor('#374151') as ColorValue,
|
|
84
|
+
lineHeight: Platform.select({ ios: 22, android: 24, default: 24 }),
|
|
85
|
+
marginBottom: 8,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const defaultH6Style: MarkdownStyleInternal['h6'] = {
|
|
89
|
+
fontSize: 14,
|
|
90
|
+
fontFamily: getSystemFont(),
|
|
91
|
+
fontWeight: '',
|
|
92
|
+
color: processColor('#4B5563') as ColorValue,
|
|
93
|
+
lineHeight: Platform.select({ ios: 20, android: 22, default: 22 }),
|
|
94
|
+
marginBottom: 8,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const defaultLinkColor = processColor('#2563EB') as ColorValue;
|
|
98
|
+
|
|
99
|
+
const defaultLinkStyle: MarkdownStyleInternal['link'] = {
|
|
100
|
+
color: defaultLinkColor,
|
|
101
|
+
underline: true,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const defaultCodeColor = processColor('#E01E5A') as ColorValue;
|
|
105
|
+
const defaultCodeBackgroundColor = processColor('#FDF2F4') as ColorValue;
|
|
106
|
+
const defaultCodeBorderColor = processColor('#F8D7DA') as ColorValue;
|
|
107
|
+
|
|
108
|
+
const defaultCodeStyle: MarkdownStyleInternal['code'] = {
|
|
109
|
+
color: defaultCodeColor,
|
|
110
|
+
backgroundColor: defaultCodeBackgroundColor,
|
|
111
|
+
borderColor: defaultCodeBorderColor,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const defaultImageStyle: MarkdownStyleInternal['image'] = {
|
|
115
|
+
height: 200,
|
|
116
|
+
borderRadius: 8,
|
|
117
|
+
marginBottom: 16,
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const defaultInlineImageStyle: MarkdownStyleInternal['inlineImage'] = {
|
|
121
|
+
size: 20,
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// Blockquote - subtle but distinct
|
|
125
|
+
const defaultBlockquoteBorderColor = processColor('#D1D5DB') as ColorValue;
|
|
126
|
+
const defaultBlockquoteBackgroundColor = processColor('#F9FAFB') as ColorValue;
|
|
127
|
+
|
|
128
|
+
const defaultBlockquoteStyle: MarkdownStyleInternal['blockquote'] = {
|
|
129
|
+
fontSize: 16,
|
|
130
|
+
fontFamily: getSystemFont(),
|
|
131
|
+
fontWeight: '',
|
|
132
|
+
color: processColor('#4B5563') as ColorValue,
|
|
133
|
+
lineHeight: Platform.select({ ios: 24, android: 26, default: 26 }),
|
|
134
|
+
marginBottom: 16,
|
|
135
|
+
borderColor: defaultBlockquoteBorderColor,
|
|
136
|
+
borderWidth: 3,
|
|
137
|
+
gapWidth: 16,
|
|
138
|
+
backgroundColor: defaultBlockquoteBackgroundColor,
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const defaultListBulletColor = processColor('#6B7280') as ColorValue;
|
|
142
|
+
const defaultListMarkerColor = processColor('#6B7280') as ColorValue;
|
|
143
|
+
|
|
144
|
+
const defaultListStyle: MarkdownStyleInternal['list'] = {
|
|
145
|
+
fontSize: 16,
|
|
146
|
+
fontFamily: getSystemFont(),
|
|
147
|
+
fontWeight: '',
|
|
148
|
+
color: defaultTextColor,
|
|
149
|
+
lineHeight: Platform.select({
|
|
150
|
+
ios: 22,
|
|
151
|
+
android: 26,
|
|
152
|
+
default: 26,
|
|
153
|
+
}),
|
|
154
|
+
marginBottom: 16,
|
|
155
|
+
bulletColor: defaultListBulletColor,
|
|
156
|
+
bulletSize: 6,
|
|
157
|
+
markerColor: defaultListMarkerColor,
|
|
158
|
+
markerFontWeight: '500',
|
|
159
|
+
gapWidth: 12,
|
|
160
|
+
marginLeft: 24,
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const defaultCodeBlockBackgroundColor = processColor('#1F2937') as ColorValue;
|
|
164
|
+
const defaultCodeBlockBorderColor = processColor('#374151') as ColorValue;
|
|
165
|
+
const defaultCodeBlockTextColor = processColor('#F3F4F6') as ColorValue;
|
|
166
|
+
|
|
167
|
+
const defaultCodeBlockStyle: MarkdownStyleInternal['codeBlock'] = {
|
|
168
|
+
fontSize: 14,
|
|
169
|
+
fontFamily: getMonospaceFont(),
|
|
170
|
+
fontWeight: '',
|
|
171
|
+
color: defaultCodeBlockTextColor,
|
|
172
|
+
lineHeight: Platform.select({ ios: 20, android: 22, default: 22 }),
|
|
173
|
+
marginBottom: 16,
|
|
174
|
+
backgroundColor: defaultCodeBlockBackgroundColor,
|
|
175
|
+
borderColor: defaultCodeBlockBorderColor,
|
|
176
|
+
borderRadius: 8,
|
|
177
|
+
borderWidth: 1,
|
|
178
|
+
padding: 16,
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const defaultThematicBreakColor = processColor('#E5E7EB') as ColorValue;
|
|
182
|
+
|
|
183
|
+
const defaultThematicBreakStyle: MarkdownStyleInternal['thematicBreak'] = {
|
|
184
|
+
color: defaultThematicBreakColor,
|
|
185
|
+
height: 1,
|
|
186
|
+
marginTop: 24,
|
|
187
|
+
marginBottom: 24,
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export const normalizeMarkdownStyle = (
|
|
191
|
+
style: MarkdownStyle
|
|
192
|
+
): MarkdownStyleInternal => {
|
|
193
|
+
const paragraph: MarkdownStyleInternal['paragraph'] = {
|
|
194
|
+
fontSize: style.paragraph?.fontSize ?? paragraphDefaultStyles.fontSize,
|
|
195
|
+
fontFamily:
|
|
196
|
+
style.paragraph?.fontFamily ?? paragraphDefaultStyles.fontFamily,
|
|
197
|
+
fontWeight:
|
|
198
|
+
style.paragraph?.fontWeight ?? paragraphDefaultStyles.fontWeight,
|
|
199
|
+
color:
|
|
200
|
+
normalizeColor(style.paragraph?.color) ?? paragraphDefaultStyles.color,
|
|
201
|
+
marginBottom:
|
|
202
|
+
style.paragraph?.marginBottom ?? paragraphDefaultStyles.marginBottom,
|
|
203
|
+
lineHeight:
|
|
204
|
+
style.paragraph?.lineHeight ?? paragraphDefaultStyles.lineHeight,
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const h1: MarkdownStyleInternal['h1'] = {
|
|
208
|
+
fontSize: style.h1?.fontSize ?? defaultH1Style.fontSize,
|
|
209
|
+
fontFamily: style.h1?.fontFamily ?? defaultH1Style.fontFamily,
|
|
210
|
+
fontWeight: style.h1?.fontWeight ?? defaultH1Style.fontWeight,
|
|
211
|
+
color: normalizeColor(style.h1?.color) ?? defaultH1Style.color,
|
|
212
|
+
marginBottom: style.h1?.marginBottom ?? defaultH1Style.marginBottom,
|
|
213
|
+
lineHeight: style.h1?.lineHeight ?? defaultH1Style.lineHeight,
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const h2: MarkdownStyleInternal['h2'] = {
|
|
217
|
+
fontSize: style.h2?.fontSize ?? defaultH2Style.fontSize,
|
|
218
|
+
fontFamily: style.h2?.fontFamily ?? defaultH2Style.fontFamily,
|
|
219
|
+
fontWeight: style.h2?.fontWeight ?? defaultH2Style.fontWeight,
|
|
220
|
+
color: normalizeColor(style.h2?.color) ?? defaultH2Style.color,
|
|
221
|
+
marginBottom: style.h2?.marginBottom ?? defaultH2Style.marginBottom,
|
|
222
|
+
lineHeight: style.h2?.lineHeight ?? defaultH2Style.lineHeight,
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const h3: MarkdownStyleInternal['h3'] = {
|
|
226
|
+
fontSize: style.h3?.fontSize ?? defaultH3Style.fontSize,
|
|
227
|
+
fontFamily: style.h3?.fontFamily ?? defaultH3Style.fontFamily,
|
|
228
|
+
fontWeight: style.h3?.fontWeight ?? defaultH3Style.fontWeight,
|
|
229
|
+
color: normalizeColor(style.h3?.color) ?? defaultH3Style.color,
|
|
230
|
+
marginBottom: style.h3?.marginBottom ?? defaultH3Style.marginBottom,
|
|
231
|
+
lineHeight: style.h3?.lineHeight ?? defaultH3Style.lineHeight,
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const h4: MarkdownStyleInternal['h4'] = {
|
|
235
|
+
fontSize: style.h4?.fontSize ?? defaultH4Style.fontSize,
|
|
236
|
+
fontFamily: style.h4?.fontFamily ?? defaultH4Style.fontFamily,
|
|
237
|
+
fontWeight: style.h4?.fontWeight ?? defaultH4Style.fontWeight,
|
|
238
|
+
color: normalizeColor(style.h4?.color) ?? defaultH4Style.color,
|
|
239
|
+
marginBottom: style.h4?.marginBottom ?? defaultH4Style.marginBottom,
|
|
240
|
+
lineHeight: style.h4?.lineHeight ?? defaultH4Style.lineHeight,
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const h5: MarkdownStyleInternal['h5'] = {
|
|
244
|
+
fontSize: style.h5?.fontSize ?? defaultH5Style.fontSize,
|
|
245
|
+
fontFamily: style.h5?.fontFamily ?? defaultH5Style.fontFamily,
|
|
246
|
+
fontWeight: style.h5?.fontWeight ?? defaultH5Style.fontWeight,
|
|
247
|
+
color: normalizeColor(style.h5?.color) ?? defaultH5Style.color,
|
|
248
|
+
marginBottom: style.h5?.marginBottom ?? defaultH5Style.marginBottom,
|
|
249
|
+
lineHeight: style.h5?.lineHeight ?? defaultH5Style.lineHeight,
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const h6: MarkdownStyleInternal['h6'] = {
|
|
253
|
+
fontSize: style.h6?.fontSize ?? defaultH6Style.fontSize,
|
|
254
|
+
fontFamily: style.h6?.fontFamily ?? defaultH6Style.fontFamily,
|
|
255
|
+
fontWeight: style.h6?.fontWeight ?? defaultH6Style.fontWeight,
|
|
256
|
+
color: normalizeColor(style.h6?.color) ?? defaultH6Style.color,
|
|
257
|
+
marginBottom: style.h6?.marginBottom ?? defaultH6Style.marginBottom,
|
|
258
|
+
lineHeight: style.h6?.lineHeight ?? defaultH6Style.lineHeight,
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
const blockquote: MarkdownStyleInternal['blockquote'] = {
|
|
262
|
+
fontSize: style.blockquote?.fontSize ?? defaultBlockquoteStyle.fontSize,
|
|
263
|
+
fontFamily:
|
|
264
|
+
style.blockquote?.fontFamily ?? defaultBlockquoteStyle.fontFamily,
|
|
265
|
+
fontWeight:
|
|
266
|
+
style.blockquote?.fontWeight ?? defaultBlockquoteStyle.fontWeight,
|
|
267
|
+
color:
|
|
268
|
+
normalizeColor(style.blockquote?.color) ?? defaultBlockquoteStyle.color,
|
|
269
|
+
marginBottom:
|
|
270
|
+
style.blockquote?.marginBottom ?? defaultBlockquoteStyle.marginBottom,
|
|
271
|
+
lineHeight:
|
|
272
|
+
style.blockquote?.lineHeight ?? defaultBlockquoteStyle.lineHeight,
|
|
273
|
+
borderColor:
|
|
274
|
+
normalizeColor(style.blockquote?.borderColor) ??
|
|
275
|
+
defaultBlockquoteStyle.borderColor,
|
|
276
|
+
borderWidth:
|
|
277
|
+
style.blockquote?.borderWidth ?? defaultBlockquoteStyle.borderWidth,
|
|
278
|
+
gapWidth: style.blockquote?.gapWidth ?? defaultBlockquoteStyle.gapWidth,
|
|
279
|
+
backgroundColor:
|
|
280
|
+
(normalizeColor(style.blockquote?.backgroundColor) as ColorValue) ??
|
|
281
|
+
defaultBlockquoteStyle.backgroundColor,
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
const list: MarkdownStyleInternal['list'] = {
|
|
285
|
+
fontSize: style.list?.fontSize ?? defaultListStyle.fontSize,
|
|
286
|
+
fontFamily: style.list?.fontFamily ?? defaultListStyle.fontFamily,
|
|
287
|
+
fontWeight: style.list?.fontWeight ?? defaultListStyle.fontWeight,
|
|
288
|
+
color: normalizeColor(style.list?.color) ?? defaultListStyle.color,
|
|
289
|
+
marginBottom: style.list?.marginBottom ?? defaultListStyle.marginBottom,
|
|
290
|
+
lineHeight: style.list?.lineHeight ?? defaultListStyle.lineHeight,
|
|
291
|
+
bulletColor:
|
|
292
|
+
normalizeColor(style.list?.bulletColor) ?? defaultListStyle.bulletColor,
|
|
293
|
+
bulletSize: style.list?.bulletSize ?? defaultListStyle.bulletSize,
|
|
294
|
+
markerColor:
|
|
295
|
+
normalizeColor(style.list?.markerColor) ?? defaultListStyle.markerColor,
|
|
296
|
+
markerFontWeight:
|
|
297
|
+
style.list?.markerFontWeight ?? defaultListStyle.markerFontWeight,
|
|
298
|
+
gapWidth: style.list?.gapWidth ?? defaultListStyle.gapWidth,
|
|
299
|
+
marginLeft: style.list?.marginLeft ?? defaultListStyle.marginLeft,
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
const codeBlock: MarkdownStyleInternal['codeBlock'] = {
|
|
303
|
+
fontSize: style.codeBlock?.fontSize ?? defaultCodeBlockStyle.fontSize,
|
|
304
|
+
fontFamily: style.codeBlock?.fontFamily ?? defaultCodeBlockStyle.fontFamily,
|
|
305
|
+
fontWeight: style.codeBlock?.fontWeight ?? defaultCodeBlockStyle.fontWeight,
|
|
306
|
+
color:
|
|
307
|
+
normalizeColor(style.codeBlock?.color) ?? defaultCodeBlockStyle.color,
|
|
308
|
+
marginBottom:
|
|
309
|
+
style.codeBlock?.marginBottom ?? defaultCodeBlockStyle.marginBottom,
|
|
310
|
+
lineHeight: style.codeBlock?.lineHeight ?? defaultCodeBlockStyle.lineHeight,
|
|
311
|
+
backgroundColor:
|
|
312
|
+
normalizeColor(style.codeBlock?.backgroundColor) ??
|
|
313
|
+
defaultCodeBlockStyle.backgroundColor,
|
|
314
|
+
borderColor:
|
|
315
|
+
normalizeColor(style.codeBlock?.borderColor) ??
|
|
316
|
+
defaultCodeBlockStyle.borderColor,
|
|
317
|
+
borderRadius:
|
|
318
|
+
style.codeBlock?.borderRadius ?? defaultCodeBlockStyle.borderRadius,
|
|
319
|
+
borderWidth:
|
|
320
|
+
style.codeBlock?.borderWidth ?? defaultCodeBlockStyle.borderWidth,
|
|
321
|
+
padding: style.codeBlock?.padding ?? defaultCodeBlockStyle.padding,
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
return {
|
|
325
|
+
paragraph,
|
|
326
|
+
h1,
|
|
327
|
+
h2,
|
|
328
|
+
h3,
|
|
329
|
+
h4,
|
|
330
|
+
h5,
|
|
331
|
+
h6,
|
|
332
|
+
blockquote,
|
|
333
|
+
list,
|
|
334
|
+
codeBlock,
|
|
335
|
+
link: {
|
|
336
|
+
...defaultLinkStyle,
|
|
337
|
+
...style.link,
|
|
338
|
+
color: normalizeColor(style.link?.color) ?? defaultLinkStyle.color,
|
|
339
|
+
},
|
|
340
|
+
strong: {
|
|
341
|
+
color: normalizeColor(style.strong?.color),
|
|
342
|
+
},
|
|
343
|
+
em: {
|
|
344
|
+
color: normalizeColor(style.em?.color),
|
|
345
|
+
},
|
|
346
|
+
code: {
|
|
347
|
+
...defaultCodeStyle,
|
|
348
|
+
color: normalizeColor(style.code?.color) ?? defaultCodeStyle.color,
|
|
349
|
+
backgroundColor:
|
|
350
|
+
normalizeColor(style.code?.backgroundColor) ??
|
|
351
|
+
defaultCodeStyle.backgroundColor,
|
|
352
|
+
borderColor:
|
|
353
|
+
normalizeColor(style.code?.borderColor) ?? defaultCodeStyle.borderColor,
|
|
354
|
+
},
|
|
355
|
+
image: {
|
|
356
|
+
...defaultImageStyle,
|
|
357
|
+
height: style.image?.height ?? defaultImageStyle.height,
|
|
358
|
+
borderRadius: style.image?.borderRadius ?? defaultImageStyle.borderRadius,
|
|
359
|
+
marginBottom: style.image?.marginBottom ?? defaultImageStyle.marginBottom,
|
|
360
|
+
},
|
|
361
|
+
inlineImage: {
|
|
362
|
+
...defaultInlineImageStyle,
|
|
363
|
+
size: style.inlineImage?.size ?? defaultInlineImageStyle.size,
|
|
364
|
+
},
|
|
365
|
+
thematicBreak: {
|
|
366
|
+
color:
|
|
367
|
+
normalizeColor(style.thematicBreak?.color) ??
|
|
368
|
+
defaultThematicBreakStyle.color,
|
|
369
|
+
height: style.thematicBreak?.height ?? defaultThematicBreakStyle.height,
|
|
370
|
+
marginTop:
|
|
371
|
+
style.thematicBreak?.marginTop ?? defaultThematicBreakStyle.marginTop,
|
|
372
|
+
marginBottom:
|
|
373
|
+
style.thematicBreak?.marginBottom ??
|
|
374
|
+
defaultThematicBreakStyle.marginBottom,
|
|
375
|
+
},
|
|
376
|
+
};
|
|
377
|
+
};
|