react-native-enriched-markdown-scaffold 1.0.2-scaffold.9 → 1.2.0-scaffold.2
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/ReactNativeEnrichedMarkdown.podspec +31 -10
- package/android/build.gradle +49 -12
- package/android/consumer-rules.pro +3 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerDelegate.java +18 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerInterface.java +6 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextInputManagerDelegate.java +3 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextInputManagerInterface.java +1 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerDelegate.java +18 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerInterface.java +6 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.cpp +62 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.h +44 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.cpp +67 -2
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.h +929 -178
- package/android/src/main/baseline-prof.txt +21 -22
- package/android/src/main/cpp/jni-adapter.cpp +17 -5
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdown.kt +729 -768
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownInternalText.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownManager.kt +72 -3
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownText.kt +222 -8
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownTextManager.kt +65 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/MeasurementStore.kt +191 -26
- package/android/src/main/java/com/swmansion/enriched/markdown/accessibility/AccessibleMarkdownTextView.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/accessibility/MarkdownAccessibilityHelper.kt +54 -6
- package/android/src/main/java/com/swmansion/enriched/markdown/events/CodeBlockPressEvent.kt +24 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/events/ImagePressEvent.kt +25 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/events/LatexErrorEvent.kt +29 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/EnrichedMarkdownTextInputManager.kt +21 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/EnrichedMarkdownTextInputView.kt +101 -9
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/EditPipeline.kt +48 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/InputConnectionWrapper.kt +7 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/MarkdownShortcutMatcher.kt +64 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/formatting/InputRemend.kt +44 -6
- package/android/src/main/java/com/swmansion/enriched/markdown/input/layout/InputEventEmitter.kt +9 -8
- package/android/src/main/java/com/swmansion/enriched/markdown/math/LatexErrorReporter.kt +9 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/parser/MarkdownASTNode.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/parser/Parser.kt +5 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlankLineRenderer.kt +38 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockStyleContext.kt +2 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockquoteRenderer.kt +3 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockquoteTextRenderer.kt +55 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/CodeBlockRenderer.kt +8 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/HighlightRenderer.kt +10 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/NodeRenderer.kt +31 -3
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/ParagraphRenderer.kt +17 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/Renderer.kt +40 -21
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/AdmonitionIcons.kt +62 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{views → segments}/BlockSegmentView.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/BlockquoteContainerView.kt +401 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{views → segments}/CodeBlockContainerView.kt +55 -16
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/ContainerNodeView.kt +164 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{utils/common → segments}/MarkdownSegment.kt +21 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/RenderedSegment.kt +137 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentHeightMeasurer.kt +139 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{utils/common → segments}/SegmentReconciler.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/{utils/common → segments}/SegmentSignature.kt +3 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentViewCreators.kt +262 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentViewFactory.kt +29 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{views → segments}/TableContainerView.kt +100 -36
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/CodeBackgroundSpan.kt +18 -17
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/CodeBlockSpan.kt +3 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/HighlightSpan.kt +60 -6
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/ImageSpan.kt +15 -5
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/InlineBackgroundGeometry.kt +42 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/InlineChipPainter.kt +4 -27
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/LineHeightSpan.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/LinkSpan.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/spoiler/SpoilerDrawUtils.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/BlockquoteStyle.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/LinkVariantEntry.kt +2 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/StyleConfig.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/VideoStyle.kt +31 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/BorderStyleUtils.kt +86 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/EllipsizeUtils.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/EnrichedMarkdownAncestorUtils.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/FeatureFlags.kt +1 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/MarkdownViewManagerUtils.kt +36 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/ReadableMapExtensions.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/serialization/MarkdownASTSerializer.kt +227 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/input/PasteTextUtils.kt +34 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/conversion/HTMLGenerator.kt +50 -28
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/conversion/MarkdownExtractor.kt +16 -21
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/extensions/SpannableExtensions.kt +4 -3
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/span/BlockSpacing.kt +3 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/span/SpanFlags.kt +13 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/CodeBlockPressHost.kt +15 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/ImagePressHost.kt +19 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/LinkEvents.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/LinkLongPressMovementMethod.kt +87 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/TextViewSetup.kt +79 -0
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/conversions.h +2 -0
- package/android/src/math/java/com/swmansion/enriched/markdown/renderer/MathInlineRenderer.kt +9 -3
- package/android/src/math/java/com/swmansion/enriched/markdown/{views → segments}/MathContainerView.kt +86 -29
- package/android/src/math/java/com/swmansion/enriched/markdown/spans/MathInlineSpan.kt +33 -7
- package/android/src/video/java/com/swmansion/enriched/markdown/segments/VideoContainerView.kt +115 -0
- package/cpp/md4c/md4c.c +343 -236
- package/cpp/md4c/md4c.h +28 -11
- package/cpp/parser/MD4CParser.cpp +266 -4
- package/cpp/parser/MD4CParser.hpp +6 -2
- package/cpp/parser/MarkdownASTNode.hpp +4 -1
- package/cpp/wasm/ASTSerializer.cpp +6 -0
- package/cpp/wasm/md4c_wasm.cpp +5 -1
- package/docs/API_REFERENCE.md +199 -12
- package/docs/BREAKING_CHANGES.md +75 -0
- package/docs/CODE_HIGHLIGHT.md +4 -0
- package/docs/COPY_OPTIONS.md +52 -9
- package/docs/ELEMENTS_STRUCTURE.md +48 -1
- package/docs/INPUT.md +60 -3
- package/docs/LATEX_MATH.md +30 -0
- package/docs/MACOS.md +1 -1
- package/docs/MENTIONS.md +2 -2
- package/docs/STYLES.md +27 -0
- package/docs/TEXT.md +8 -0
- package/docs/WEB.md +44 -10
- package/ios/EnrichedMarkdown.mm +285 -43
- package/ios/EnrichedMarkdownText.mm +185 -23
- package/ios/attachments/ENRMImageAttachment.h +17 -2
- package/ios/attachments/ENRMImageAttachment.m +26 -28
- package/ios/attachments/ENRMMathInlineAttachment+macOS.m +10 -2
- package/ios/attachments/ENRMMathInlineAttachment.h +3 -1
- package/ios/attachments/ENRMMathInlineAttachment.m +17 -1
- package/ios/attachments/ENRMMathInlineAttachmentShared.h +3 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/EventEmitters.cpp +62 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/EventEmitters.h +44 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.cpp +67 -2
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.h +929 -178
- package/ios/input/ENRMInputFormatter.mm +68 -12
- package/ios/input/ENRMInputFormatterStyle.mm +9 -2
- package/ios/input/ENRMInputParser.mm +18 -0
- package/ios/input/ENRMInputRemend.mm +40 -3
- package/ios/input/ENRMMarkdownShortcutMatcher.h +39 -0
- package/ios/input/ENRMMarkdownShortcutMatcher.mm +66 -0
- package/ios/input/EnrichedMarkdownTextInput.mm +129 -1
- package/ios/internals/ENRMViewFreeMeasurement.h +45 -6
- package/ios/internals/MeasurementCache.h +20 -4
- package/ios/internals/ShadowMeasurementUtils.h +2 -0
- package/ios/math/ENRMLatexErrorCoordinator.h +27 -0
- package/ios/math/ENRMLatexErrorCoordinator.mm +75 -0
- package/ios/math/ENRMLatexErrorReporting.h +13 -0
- package/ios/math/ENRMRaTeXBridge.swift +46 -3
- package/ios/parser/ENRMMarkdownParser.h +3 -0
- package/ios/parser/ENRMMarkdownParser.mm +11 -2
- package/ios/parser/MarkdownASTNode.h +8 -1
- package/ios/parser/MarkdownASTNode.m +20 -0
- package/ios/parser/MarkdownParserBridge.mm +13 -2
- package/ios/renderer/AttributedRenderer.h +13 -1
- package/ios/renderer/AttributedRenderer.m +24 -13
- package/ios/renderer/BaselineShiftTextAttributes.h +4 -0
- package/ios/renderer/BaselineShiftTextAttributes.m +4 -0
- package/ios/renderer/BlankLineRenderer.h +4 -0
- package/ios/renderer/BlankLineRenderer.m +51 -0
- package/ios/renderer/BlockquoteRenderer.m +1 -0
- package/ios/renderer/CodeBlockRenderer.m +8 -0
- package/ios/renderer/CodeRenderer.m +5 -2
- package/ios/renderer/ENRMBlockquoteTextRenderer.h +25 -0
- package/ios/renderer/ENRMBlockquoteTextRenderer.m +48 -0
- package/ios/renderer/ENRMImageRenderer.m +1 -1
- package/ios/renderer/ENRMMathInlineRenderer.m +9 -1
- package/ios/renderer/HeadingRenderer.m +1 -0
- package/ios/renderer/HighlightRenderer.m +6 -0
- package/ios/renderer/LinkRenderer.m +1 -1
- package/ios/renderer/ListItemRenderer.m +51 -2
- package/ios/renderer/ParagraphRenderer.m +10 -3
- package/ios/renderer/RenderContext.h +16 -0
- package/ios/renderer/RenderContext.m +16 -0
- package/ios/renderer/RendererFactory.m +6 -0
- package/ios/renderer/SubscriptRenderer.m +1 -0
- package/ios/renderer/SuperscriptRenderer.m +1 -0
- package/ios/segments/ENRMAdmonitionIcons.h +31 -0
- package/ios/segments/ENRMAdmonitionIcons.m +93 -0
- package/ios/segments/ENRMBlockquoteContainerView.h +90 -0
- package/ios/segments/ENRMBlockquoteContainerView.mm +551 -0
- package/ios/{views → segments}/ENRMCodeBlockContainerView.h +9 -4
- package/ios/{views → segments}/ENRMCodeBlockContainerView.m +147 -36
- package/ios/segments/ENRMContainerNodeView.h +52 -0
- package/ios/segments/ENRMContainerNodeView.mm +201 -0
- package/ios/segments/ENRMDynamicBlockProps.h +32 -0
- package/ios/segments/ENRMDynamicBlockProps.m +15 -0
- package/ios/{views → segments}/ENRMMathContainerView.h +13 -5
- package/ios/{views → segments}/ENRMMathContainerView.m +60 -9
- package/ios/segments/ENRMSVGPath.h +21 -0
- package/ios/segments/ENRMSVGPath.m +409 -0
- package/ios/segments/ENRMSegmentHeightMeasurer.h +33 -0
- package/ios/segments/ENRMSegmentHeightMeasurer.mm +94 -0
- package/ios/segments/ENRMVideoContainerView.h +40 -0
- package/ios/segments/ENRMVideoContainerView.m +421 -0
- package/ios/{utils → segments}/RenderedMarkdownSegment.h +19 -2
- package/ios/{utils → segments}/RenderedMarkdownSegment.m +42 -1
- package/ios/segments/SegmentRenderer.h +26 -0
- package/ios/{utils → segments}/SegmentRenderer.m +46 -9
- package/ios/{views → segments}/TableContainerView.h +5 -4
- package/ios/{views → segments}/TableContainerView.m +96 -12
- package/ios/styles/StyleConfig.h +17 -0
- package/ios/styles/StyleConfig.mm +90 -0
- package/ios/utils/ENRMCodeBlockContent.mm +13 -0
- package/ios/utils/ENRMFeatureFlags.h +6 -0
- package/ios/utils/ENRMTextRenderer.h +8 -0
- package/ios/utils/ENRMTextRenderer.m +26 -10
- package/ios/utils/ENRMUIKit.h +1 -0
- package/ios/utils/FontUtils.h +2 -1
- package/ios/utils/FontUtils.m +22 -6
- package/ios/utils/LinkTapUtils.h +17 -2
- package/ios/utils/LinkTapUtils.m +44 -2
- package/ios/utils/ListMarkerDrawer.m +25 -1
- package/ios/utils/MarkdownASTSerializer.h +7 -0
- package/ios/utils/MarkdownASTSerializer.m +243 -0
- package/ios/utils/MarkdownAccessibilityElementBuilder.m +9 -67
- package/ios/utils/MarkdownExtractor.m +6 -3
- package/ios/utils/ParagraphStyleUtils.h +25 -1
- package/ios/utils/ParagraphStyleUtils.m +51 -7
- package/ios/utils/StylePropsUtils.h +60 -1
- package/ios/utils/TextViewLayoutManager.mm +57 -0
- package/lib/module/EnrichedMarkdownNativeComponent.ts +110 -4
- package/lib/module/EnrichedMarkdownTextInput.js +60 -2
- package/lib/module/EnrichedMarkdownTextInput.js.map +1 -1
- package/lib/module/EnrichedMarkdownTextInputNativeComponent.ts +12 -0
- package/lib/module/EnrichedMarkdownTextNativeComponent.ts +115 -4
- package/lib/module/admonitionDefaults.js +34 -0
- package/lib/module/admonitionDefaults.js.map +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/jest/index.js +84 -4
- package/lib/module/jest/index.js.map +1 -1
- package/lib/module/native/EnrichedMarkdownText.js +58 -5
- package/lib/module/native/EnrichedMarkdownText.js.map +1 -1
- package/lib/module/normalizeMarkdownShortcuts.js +31 -0
- package/lib/module/normalizeMarkdownShortcuts.js.map +1 -0
- package/lib/module/normalizeMarkdownStyle.js +15 -1
- package/lib/module/normalizeMarkdownStyle.js.map +1 -1
- package/lib/module/normalizeMarkdownStyle.web.js +15 -1
- package/lib/module/normalizeMarkdownStyle.web.js.map +1 -1
- package/lib/module/styleUtils.js +15 -3
- package/lib/module/styleUtils.js.map +1 -1
- package/lib/module/utils/textInputState.js +4 -3
- package/lib/module/utils/textInputState.js.map +1 -1
- package/lib/module/utils/usePressability.js +28 -0
- package/lib/module/utils/usePressability.js.map +1 -0
- package/lib/module/web/EnrichedMarkdownText.js +19 -6
- package/lib/module/web/EnrichedMarkdownText.js.map +1 -1
- package/lib/module/web/globalStyles.js +7 -1
- package/lib/module/web/globalStyles.js.map +1 -1
- package/lib/module/web/nativeProps.js +70 -0
- package/lib/module/web/nativeProps.js.map +1 -0
- package/lib/module/web/parseMarkdown.js +5 -3
- package/lib/module/web/parseMarkdown.js.map +1 -1
- package/lib/module/web/renderers/BlockRenderers.js +164 -8
- package/lib/module/web/renderers/BlockRenderers.js.map +1 -1
- package/lib/module/web/renderers/admonitionIcons.js +34 -0
- package/lib/module/web/renderers/admonitionIcons.js.map +1 -0
- package/lib/module/web/styles.js +30 -8
- package/lib/module/web/styles.js.map +1 -1
- package/lib/module/web/wasm/md4c.js +0 -0
- package/lib/module/web/wasm/md4c.js.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts +103 -3
- package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownTextInput.d.ts +27 -3
- package/lib/typescript/src/EnrichedMarkdownTextInput.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownTextInputNativeComponent.d.ts +11 -0
- package/lib/typescript/src/EnrichedMarkdownTextInputNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts +108 -3
- package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/admonitionDefaults.d.ts +10 -0
- package/lib/typescript/src/admonitionDefaults.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/index.web.d.ts +1 -1
- package/lib/typescript/src/index.web.d.ts.map +1 -1
- package/lib/typescript/src/jest/index.d.ts +2 -2
- package/lib/typescript/src/jest/index.d.ts.map +1 -1
- package/lib/typescript/src/native/EnrichedMarkdownText.d.ts +3 -3
- package/lib/typescript/src/native/EnrichedMarkdownText.d.ts.map +1 -1
- package/lib/typescript/src/normalizeMarkdownShortcuts.d.ts +7 -0
- package/lib/typescript/src/normalizeMarkdownShortcuts.d.ts.map +1 -0
- package/lib/typescript/src/normalizeMarkdownStyle.d.ts.map +1 -1
- package/lib/typescript/src/normalizeMarkdownStyle.web.d.ts.map +1 -1
- package/lib/typescript/src/styleUtils.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownStyle.d.ts +59 -1
- package/lib/typescript/src/types/MarkdownStyle.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownStyleInternal.d.ts +21 -0
- package/lib/typescript/src/types/MarkdownStyleInternal.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownTextProps.d.ts +93 -8
- package/lib/typescript/src/types/MarkdownTextProps.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownTextProps.web.d.ts +25 -1
- package/lib/typescript/src/types/MarkdownTextProps.web.d.ts.map +1 -1
- package/lib/typescript/src/types/events.d.ts +33 -5
- package/lib/typescript/src/types/events.d.ts.map +1 -1
- package/lib/typescript/src/utils/textInputState.d.ts +5 -3
- package/lib/typescript/src/utils/textInputState.d.ts.map +1 -1
- package/lib/typescript/src/utils/usePressability.d.ts +24 -0
- package/lib/typescript/src/utils/usePressability.d.ts.map +1 -0
- package/lib/typescript/src/web/EnrichedMarkdownText.d.ts +1 -1
- package/lib/typescript/src/web/EnrichedMarkdownText.d.ts.map +1 -1
- package/lib/typescript/src/web/globalStyles.d.ts +1 -0
- package/lib/typescript/src/web/globalStyles.d.ts.map +1 -1
- package/lib/typescript/src/web/nativeProps.d.ts +34 -0
- package/lib/typescript/src/web/nativeProps.d.ts.map +1 -0
- package/lib/typescript/src/web/parseMarkdown.d.ts +1 -1
- package/lib/typescript/src/web/parseMarkdown.d.ts.map +1 -1
- package/lib/typescript/src/web/renderers/BlockRenderers.d.ts.map +1 -1
- package/lib/typescript/src/web/renderers/admonitionIcons.d.ts +5 -0
- package/lib/typescript/src/web/renderers/admonitionIcons.d.ts.map +1 -0
- package/lib/typescript/src/web/styles.d.ts +1 -0
- package/lib/typescript/src/web/styles.d.ts.map +1 -1
- package/lib/typescript/src/web/types.d.ts +8 -2
- package/lib/typescript/src/web/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/postinstall.mjs +7 -0
- package/src/EnrichedMarkdownNativeComponent.ts +110 -4
- package/src/EnrichedMarkdownTextInput.tsx +101 -4
- package/src/EnrichedMarkdownTextInputNativeComponent.ts +12 -0
- package/src/EnrichedMarkdownTextNativeComponent.ts +115 -4
- package/src/admonitionDefaults.ts +58 -0
- package/src/index.tsx +5 -0
- package/src/index.web.tsx +3 -0
- package/src/jest/index.tsx +138 -5
- package/src/native/EnrichedMarkdownText.tsx +55 -3
- package/src/normalizeMarkdownShortcuts.ts +38 -0
- package/src/normalizeMarkdownStyle.ts +17 -0
- package/src/normalizeMarkdownStyle.web.ts +17 -0
- package/src/styleUtils.ts +17 -6
- package/src/types/MarkdownStyle.ts +62 -1
- package/src/types/MarkdownStyleInternal.ts +24 -0
- package/src/types/MarkdownTextProps.ts +95 -7
- package/src/types/MarkdownTextProps.web.ts +26 -0
- package/src/types/events.ts +36 -5
- package/src/utils/textInputState.ts +5 -3
- package/src/utils/usePressability.ts +34 -0
- package/src/web/EnrichedMarkdownText.tsx +36 -3
- package/src/web/globalStyles.ts +10 -0
- package/src/web/nativeProps.ts +78 -0
- package/src/web/parseMarkdown.ts +10 -2
- package/src/web/renderers/BlockRenderers.tsx +175 -6
- package/src/web/renderers/admonitionIcons.ts +37 -0
- package/src/web/styles.ts +28 -3
- package/src/web/types.ts +12 -1
- package/src/web/wasm/md4c.js +0 -0
- package/vendor-ratex.mjs +86 -17
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/DocumentRenderer.kt +0 -16
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/RenderedSegment.kt +0 -88
- package/ios/utils/SegmentRenderer.h +0 -24
- /package/ios/{views → segments}/ENRMTableGridView.h +0 -0
- /package/ios/{views → segments}/ENRMTableGridView.m +0 -0
- /package/ios/{views → segments}/ENRMTableIOSGridView.h +0 -0
- /package/ios/{views → segments}/ENRMTableIOSGridView.m +0 -0
- /package/ios/{utils → segments}/SegmentReconciler.h +0 -0
- /package/ios/{utils → segments}/SegmentReconciler.m +0 -0
- /package/ios/{utils → segments}/SegmentViewRegistry.h +0 -0
- /package/ios/{utils → segments}/SegmentViewRegistry.m +0 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ViewProps } from 'react-native';
|
|
2
|
+
import type { EnrichedMarkdownTextProps as NativeMarkdownTextProps } from '../types/MarkdownTextProps';
|
|
3
|
+
import type { EnrichedMarkdownTextProps as WebMarkdownTextProps } from '../types/MarkdownTextProps.web';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Props that form the native (iOS/Android) EnrichedMarkdownText API but have no
|
|
7
|
+
* effect on web.
|
|
8
|
+
*
|
|
9
|
+
* In a typical React Native + react-native-web project the component is
|
|
10
|
+
* type-checked against the native `MarkdownTextProps.ts` interface (bundlers
|
|
11
|
+
* swap in `.web.tsx` at runtime, but `tsc` resolves the base `.ts` unless the
|
|
12
|
+
* project sets `moduleSuffixes`). So JSX like `flavor="github"` or
|
|
13
|
+
* `streamingAnimation` compiles fine and would otherwise be spread onto the
|
|
14
|
+
* root DOM element, triggering React "unknown prop" warnings. They are dropped
|
|
15
|
+
* here before reaching the DOM.
|
|
16
|
+
*
|
|
17
|
+
* The set below is not hand-maintained: `NativeOnlyPropName` is derived as the
|
|
18
|
+
* native prop names minus the ones web implements, so adding a native-only prop
|
|
19
|
+
* to `MarkdownTextProps.ts` fails the build here until it is listed and thus
|
|
20
|
+
* filtered. Generic React Native ViewProps (nativeID, accessibility*, hitSlop,
|
|
21
|
+
* etc.) are excluded from that union and stay out of scope; they are documented
|
|
22
|
+
* as not stripped in docs/WEB.md.
|
|
23
|
+
*
|
|
24
|
+
* The `react-native` and native-props imports are type-only, so nothing from
|
|
25
|
+
* either reaches the web bundle.
|
|
26
|
+
*/
|
|
27
|
+
type NativeOnlyPropName = Exclude<
|
|
28
|
+
keyof NativeMarkdownTextProps,
|
|
29
|
+
keyof WebMarkdownTextProps | keyof ViewProps
|
|
30
|
+
>;
|
|
31
|
+
|
|
32
|
+
export const NATIVE_ONLY_PROP_NAMES: Record<NativeOnlyPropName, true> = {
|
|
33
|
+
onCopyPress: true,
|
|
34
|
+
onLatexError: true,
|
|
35
|
+
enableBlockContextMenu: true,
|
|
36
|
+
enableLinkPreview: true,
|
|
37
|
+
selectionHandleColor: true,
|
|
38
|
+
allowFontScaling: true,
|
|
39
|
+
maxFontSizeMultiplier: true,
|
|
40
|
+
flavor: true,
|
|
41
|
+
streamingAnimation: true,
|
|
42
|
+
streamingConfig: true,
|
|
43
|
+
spoilerOverlay: true,
|
|
44
|
+
contextMenuItems: true,
|
|
45
|
+
imageRequestHeaders: true,
|
|
46
|
+
selectionMenuConfig: true,
|
|
47
|
+
accessibilityLabels: true,
|
|
48
|
+
textBreakStrategy: true,
|
|
49
|
+
lineBreakStrategyIOS: true,
|
|
50
|
+
writingDirection: true,
|
|
51
|
+
numberOfLines: true,
|
|
52
|
+
ellipsizeMode: true,
|
|
53
|
+
// Fork props (native only). `ref` is the native imperative handle
|
|
54
|
+
// (`clearSelection` + `measure*`); a DOM node cannot satisfy it, so it is not
|
|
55
|
+
// forwarded to the root element on web.
|
|
56
|
+
onSelectionChange: true,
|
|
57
|
+
linkLongPressSelects: true,
|
|
58
|
+
contextMenuHidden: true,
|
|
59
|
+
ref: true,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const NATIVE_ONLY_PROPS = new Set<string>(Object.keys(NATIVE_ONLY_PROP_NAMES));
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Removes native-only props so they are never forwarded to a DOM element.
|
|
66
|
+
* Returns a shallow copy; the input is left untouched.
|
|
67
|
+
*/
|
|
68
|
+
export function filterNativeOnlyProps<T extends object>(
|
|
69
|
+
props: T
|
|
70
|
+
): Omit<T, NativeOnlyPropName> {
|
|
71
|
+
const result: Record<string, unknown> = {};
|
|
72
|
+
for (const [key, value] of Object.entries(props)) {
|
|
73
|
+
if (!NATIVE_ONLY_PROPS.has(key)) {
|
|
74
|
+
result[key] = value;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return result as Omit<T, NativeOnlyPropName>;
|
|
78
|
+
}
|
package/src/web/parseMarkdown.ts
CHANGED
|
@@ -8,7 +8,9 @@ type ParseFn = (
|
|
|
8
8
|
superscript: number,
|
|
9
9
|
subscript: number,
|
|
10
10
|
highlight: number,
|
|
11
|
-
hardSoftBreaks: number
|
|
11
|
+
hardSoftBreaks: number,
|
|
12
|
+
preserveBlankLines: number,
|
|
13
|
+
admonitions: number
|
|
12
14
|
) => string;
|
|
13
15
|
|
|
14
16
|
// Caching the Promise (not the resolved value) means concurrent callers share
|
|
@@ -30,6 +32,8 @@ function initializeParser(): Promise<ParseFn> {
|
|
|
30
32
|
'number',
|
|
31
33
|
'number',
|
|
32
34
|
'number',
|
|
35
|
+
'number',
|
|
36
|
+
'number',
|
|
33
37
|
])
|
|
34
38
|
)
|
|
35
39
|
.catch((error) => {
|
|
@@ -58,6 +62,8 @@ export async function parseMarkdown(
|
|
|
58
62
|
subscript = false,
|
|
59
63
|
highlight = false,
|
|
60
64
|
hardSoftBreaks = false,
|
|
65
|
+
preserveBlankLines = false,
|
|
66
|
+
admonitions = true,
|
|
61
67
|
}: Md4cFlags = {}
|
|
62
68
|
): Promise<ASTNode> {
|
|
63
69
|
const parse = await initializeParser();
|
|
@@ -70,7 +76,9 @@ export async function parseMarkdown(
|
|
|
70
76
|
superscript ? 1 : 0,
|
|
71
77
|
subscript ? 1 : 0,
|
|
72
78
|
highlight ? 1 : 0,
|
|
73
|
-
hardSoftBreaks ? 1 : 0
|
|
79
|
+
hardSoftBreaks ? 1 : 0,
|
|
80
|
+
preserveBlankLines ? 1 : 0,
|
|
81
|
+
admonitions ? 1 : 0
|
|
74
82
|
)
|
|
75
83
|
);
|
|
76
84
|
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
import type { CSSProperties, KeyboardEvent } from 'react';
|
|
1
2
|
import { extractNodeText, filenameFromUrl } from '../utils';
|
|
2
3
|
import type { RendererProps, RendererMap } from '../types';
|
|
3
4
|
import { toHeadingLevel } from '../styles';
|
|
4
5
|
import { KaTeXRenderer } from './KaTeXRenderer';
|
|
6
|
+
import {
|
|
7
|
+
ADMONITION_ICON_PATHS,
|
|
8
|
+
ADMONITION_ICON_VIEWBOX,
|
|
9
|
+
ADMONITION_TITLES,
|
|
10
|
+
} from './admonitionIcons';
|
|
11
|
+
import type { AdmonitionType } from '../../admonitionDefaults';
|
|
12
|
+
import { ENRM_ADMONITION_CLASS } from '../globalStyles';
|
|
5
13
|
|
|
6
14
|
function ParagraphRenderer({
|
|
7
15
|
node,
|
|
@@ -13,7 +21,7 @@ function ParagraphRenderer({
|
|
|
13
21
|
node.children?.length === 1 && node.children[0]?.type === 'Image';
|
|
14
22
|
if (isImageOnly) return <>{renderChildren(node)}</>;
|
|
15
23
|
|
|
16
|
-
if (parentType === 'Blockquote') {
|
|
24
|
+
if (parentType === 'Blockquote' || parentType === 'Admonition') {
|
|
17
25
|
return <p style={styles.paragraphInBlockquote}>{renderChildren(node)}</p>;
|
|
18
26
|
}
|
|
19
27
|
|
|
@@ -35,12 +43,100 @@ function BlockquoteRenderer({ node, styles, renderChildren }: RendererProps) {
|
|
|
35
43
|
);
|
|
36
44
|
}
|
|
37
45
|
|
|
38
|
-
function
|
|
46
|
+
function AdmonitionRenderer({
|
|
47
|
+
node,
|
|
48
|
+
style,
|
|
49
|
+
styles,
|
|
50
|
+
renderChildren,
|
|
51
|
+
}: RendererProps) {
|
|
52
|
+
const type = (node.attributes?.admonitionType ?? 'note') as AdmonitionType;
|
|
53
|
+
const blockquote = style.blockquote;
|
|
54
|
+
const colors = blockquote.admonitions[type] ?? blockquote.admonitions.note;
|
|
55
|
+
const tint = colors.color;
|
|
56
|
+
const iconSize = Math.ceil(blockquote.fontSize);
|
|
57
|
+
// Reuse the blockquote box geometry; override the accent bar + fill per type.
|
|
58
|
+
const boxStyle: CSSProperties = {
|
|
59
|
+
...styles.blockquote,
|
|
60
|
+
borderInlineStart: `${blockquote.borderWidth}px solid ${tint}`,
|
|
61
|
+
backgroundColor: colors.backgroundColor,
|
|
62
|
+
};
|
|
63
|
+
const headerStyle: CSSProperties = {
|
|
64
|
+
display: 'flex',
|
|
65
|
+
alignItems: 'center',
|
|
66
|
+
gap: Math.round(iconSize * 0.4),
|
|
67
|
+
marginBottom: Math.round(blockquote.fontSize * 0.4),
|
|
68
|
+
color: tint,
|
|
69
|
+
fontWeight: 'bold',
|
|
70
|
+
fontSize: blockquote.fontSize,
|
|
71
|
+
lineHeight: 1.2,
|
|
72
|
+
};
|
|
73
|
+
return (
|
|
74
|
+
<div className={ENRM_ADMONITION_CLASS} style={boxStyle}>
|
|
75
|
+
<div style={headerStyle}>
|
|
76
|
+
<svg
|
|
77
|
+
width={iconSize}
|
|
78
|
+
height={iconSize}
|
|
79
|
+
viewBox={`0 0 ${ADMONITION_ICON_VIEWBOX} ${ADMONITION_ICON_VIEWBOX}`}
|
|
80
|
+
fill={tint}
|
|
81
|
+
aria-hidden="true"
|
|
82
|
+
>
|
|
83
|
+
<path d={ADMONITION_ICON_PATHS[type]} />
|
|
84
|
+
</svg>
|
|
85
|
+
<span>{ADMONITION_TITLES[type]}</span>
|
|
86
|
+
</div>
|
|
87
|
+
{renderChildren(node)}
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function CodeBlockRenderer({
|
|
93
|
+
node,
|
|
94
|
+
styles,
|
|
95
|
+
renderChildren,
|
|
96
|
+
callbacks,
|
|
97
|
+
}: RendererProps) {
|
|
39
98
|
const language = node.attributes?.language;
|
|
40
99
|
const label = language ? `Code block: ${language}` : 'Code block';
|
|
41
100
|
|
|
101
|
+
if (callbacks.onCodeBlockPress == null) {
|
|
102
|
+
return (
|
|
103
|
+
<pre style={styles.codeBlock} aria-label={label}>
|
|
104
|
+
<code style={styles.codeBlockFont}>{renderChildren(node)}</code>
|
|
105
|
+
</pre>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const press = () =>
|
|
110
|
+
callbacks.onCodeBlockPress?.({
|
|
111
|
+
code: extractNodeText(node).replace(/\n+$/, ''),
|
|
112
|
+
language: language ?? '',
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Don't fire while code text is selected - selection stays separate from the tap.
|
|
116
|
+
const handleClick = () => {
|
|
117
|
+
const selection =
|
|
118
|
+
typeof window !== 'undefined' ? window.getSelection() : null;
|
|
119
|
+
if (selection && !selection.isCollapsed) return;
|
|
120
|
+
press();
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const handleKeyDown = (event: KeyboardEvent<HTMLPreElement>) => {
|
|
124
|
+
if (event.repeat) return;
|
|
125
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
126
|
+
event.preventDefault();
|
|
127
|
+
press();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
42
131
|
return (
|
|
43
|
-
<pre
|
|
132
|
+
<pre
|
|
133
|
+
style={{ ...styles.codeBlock, cursor: 'pointer' }}
|
|
134
|
+
aria-label={label}
|
|
135
|
+
role="button"
|
|
136
|
+
tabIndex={0}
|
|
137
|
+
onClick={handleClick}
|
|
138
|
+
onKeyDown={handleKeyDown}
|
|
139
|
+
>
|
|
44
140
|
<code style={styles.codeBlockFont}>{renderChildren(node)}</code>
|
|
45
141
|
</pre>
|
|
46
142
|
);
|
|
@@ -50,16 +146,64 @@ function ThematicBreakRenderer({ styles }: RendererProps) {
|
|
|
50
146
|
return <hr style={styles.thematicBreak} />;
|
|
51
147
|
}
|
|
52
148
|
|
|
53
|
-
|
|
149
|
+
// Each blank line in the source becomes one empty line. Rendered as a spacer
|
|
150
|
+
// sized to the paragraph line height (rather than a run of <br>, whose height
|
|
151
|
+
// would follow the container line height) so the vertical rhythm matches the
|
|
152
|
+
// surrounding paragraphs. Any extra block spacing is left to the caller.
|
|
153
|
+
function BlankLineRenderer({ node, style }: RendererProps) {
|
|
154
|
+
const count = Number.parseInt(node.attributes?.count ?? '0', 10);
|
|
155
|
+
const lines = Number.isFinite(count) ? Math.max(0, count) : 0;
|
|
156
|
+
if (lines === 0) return null;
|
|
157
|
+
return (
|
|
158
|
+
<div
|
|
159
|
+
aria-hidden="true"
|
|
160
|
+
style={{ height: lines * style.paragraph.lineHeight }}
|
|
161
|
+
/>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function ImageRenderer({ node, styles, parentType, callbacks }: RendererProps) {
|
|
54
166
|
const url = node.attributes?.url;
|
|
55
167
|
if (!url) return null;
|
|
56
168
|
|
|
57
169
|
const title = node.attributes?.title;
|
|
58
|
-
const
|
|
170
|
+
const markdownAlt = extractNodeText(node).trim();
|
|
171
|
+
const alt = markdownAlt || title || filenameFromUrl(url) || 'Image';
|
|
59
172
|
const imgStyle = node.attributes?.isInline
|
|
60
173
|
? styles.inlineImage
|
|
61
174
|
: styles.image;
|
|
62
|
-
|
|
175
|
+
|
|
176
|
+
const interactive =
|
|
177
|
+
callbacks.onImagePress != null &&
|
|
178
|
+
parentType !== 'Link' &&
|
|
179
|
+
parentType !== 'TableCell' &&
|
|
180
|
+
parentType !== 'TableHeaderCell';
|
|
181
|
+
if (!interactive) {
|
|
182
|
+
return <img src={url} alt={alt} title={title} style={imgStyle} />;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const press = () => callbacks.onImagePress?.({ url, altText: markdownAlt });
|
|
186
|
+
const handleKeyDown = (event: KeyboardEvent<HTMLImageElement>) => {
|
|
187
|
+
if (event.repeat) return;
|
|
188
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
189
|
+
event.preventDefault();
|
|
190
|
+
press();
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
return (
|
|
195
|
+
<img
|
|
196
|
+
src={url}
|
|
197
|
+
alt={alt}
|
|
198
|
+
title={title}
|
|
199
|
+
style={imgStyle}
|
|
200
|
+
role="button"
|
|
201
|
+
tabIndex={0}
|
|
202
|
+
aria-label={alt}
|
|
203
|
+
onClick={press}
|
|
204
|
+
onKeyDown={handleKeyDown}
|
|
205
|
+
/>
|
|
206
|
+
);
|
|
63
207
|
}
|
|
64
208
|
|
|
65
209
|
function LatexMathDisplayRenderer({
|
|
@@ -79,12 +223,37 @@ function LatexMathDisplayRenderer({
|
|
|
79
223
|
);
|
|
80
224
|
}
|
|
81
225
|
|
|
226
|
+
function VideoRenderer({ node, styles }: RendererProps) {
|
|
227
|
+
const url = node.attributes?.url;
|
|
228
|
+
if (!url) return null;
|
|
229
|
+
|
|
230
|
+
const title = node.attributes?.title;
|
|
231
|
+
const alt = extractNodeText(node).trim();
|
|
232
|
+
const label = alt || title || 'Video';
|
|
233
|
+
|
|
234
|
+
return (
|
|
235
|
+
<video
|
|
236
|
+
controls
|
|
237
|
+
playsInline
|
|
238
|
+
preload="metadata"
|
|
239
|
+
style={styles.video}
|
|
240
|
+
title={title}
|
|
241
|
+
aria-label={label}
|
|
242
|
+
>
|
|
243
|
+
<source src={url} />
|
|
244
|
+
</video>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
82
248
|
export const blockRenderers: RendererMap = {
|
|
83
249
|
Paragraph: ParagraphRenderer,
|
|
84
250
|
Heading: HeadingRenderer,
|
|
85
251
|
Blockquote: BlockquoteRenderer,
|
|
252
|
+
Admonition: AdmonitionRenderer,
|
|
86
253
|
CodeBlock: CodeBlockRenderer,
|
|
87
254
|
ThematicBreak: ThematicBreakRenderer,
|
|
255
|
+
BlankLine: BlankLineRenderer,
|
|
88
256
|
Image: ImageRenderer,
|
|
89
257
|
LatexMathDisplay: LatexMathDisplayRenderer,
|
|
258
|
+
Video: VideoRenderer,
|
|
90
259
|
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AdmonitionType } from '../../admonitionDefaults';
|
|
2
|
+
|
|
3
|
+
// GitHub alert icons, taken verbatim from @primer/octicons (16x16 viewBox):
|
|
4
|
+
// note=info, tip=light-bulb, important=report, warning=alert, caution=stop.
|
|
5
|
+
//
|
|
6
|
+
// These `d` path strings are the single source of truth for the admonition
|
|
7
|
+
// header icon and MUST stay byte-identical across the three renderers so the
|
|
8
|
+
// glyph looks the same everywhere:
|
|
9
|
+
// - iOS: ios/segments/ENRMAdmonitionIcons.m
|
|
10
|
+
// - Android: android/.../segments/AdmonitionIcons.kt
|
|
11
|
+
// - Web: this file
|
|
12
|
+
// Parity is enforced by __tests__/admonition-icons-parity.test.ts (jest, run in
|
|
13
|
+
// CI), which reads all three files and fails on any drift. That guard only works
|
|
14
|
+
// while all three copies live under packages/react-native-enriched-markdown/**;
|
|
15
|
+
// moving a copy out of this package requires re-homing the guard (or adding a
|
|
16
|
+
// native-side check) so the copies can't silently diverge.
|
|
17
|
+
export const ADMONITION_ICON_VIEWBOX = 16;
|
|
18
|
+
|
|
19
|
+
export const ADMONITION_ICON_PATHS: Record<AdmonitionType, string> = {
|
|
20
|
+
note: 'M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z',
|
|
21
|
+
tip: 'M8 1.5c-2.363 0-4 1.69-4 3.75 0 .984.424 1.625.984 2.304l.214.253c.223.264.47.556.673.848.284.411.537.896.621 1.49a.75.75 0 0 1-1.484.211c-.04-.282-.163-.547-.37-.847a8.456 8.456 0 0 0-.542-.68c-.084-.1-.173-.205-.268-.32C3.201 7.75 2.5 6.766 2.5 5.25 2.5 2.31 4.863 0 8 0s5.5 2.31 5.5 5.25c0 1.516-.701 2.5-1.328 3.259-.095.115-.184.22-.268.319-.207.245-.383.453-.541.681-.208.3-.33.565-.37.847a.751.751 0 0 1-1.485-.212c.084-.593.337-1.078.621-1.489.203-.292.45-.584.673-.848.075-.088.147-.173.213-.253.561-.679.985-1.32.985-2.304 0-2.06-1.637-3.75-4-3.75ZM5.75 12h4.5a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1 0-1.5ZM6 15.25a.75.75 0 0 1 .75-.75h2.5a.75.75 0 0 1 0 1.5h-2.5a.75.75 0 0 1-.75-.75Z',
|
|
22
|
+
important:
|
|
23
|
+
'M0 1.75C0 .784.784 0 1.75 0h12.5C15.216 0 16 .784 16 1.75v9.5A1.75 1.75 0 0 1 14.25 13H8.06l-2.573 2.573A1.458 1.458 0 0 1 3 14.543V13H1.75A1.75 1.75 0 0 1 0 11.25Zm1.75-.25a.25.25 0 0 0-.25.25v9.5c0 .138.112.25.25.25h2a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h6.5a.25.25 0 0 0 .25-.25v-9.5a.25.25 0 0 0-.25-.25Zm7 2.25v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 9a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z',
|
|
24
|
+
warning:
|
|
25
|
+
'M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z',
|
|
26
|
+
caution:
|
|
27
|
+
'M4.47.22A.749.749 0 0 1 5 0h6c.199 0 .389.079.53.22l4.25 4.25c.141.14.22.331.22.53v6a.749.749 0 0 1-.22.53l-4.25 4.25A.749.749 0 0 1 11 16H5a.749.749 0 0 1-.53-.22L.22 11.53A.749.749 0 0 1 0 11V5c0-.199.079-.389.22-.53Zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5ZM8 4a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 4Zm0 8a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// GitHub renders the type name capitalized in the header (Note, Tip, ...).
|
|
31
|
+
export const ADMONITION_TITLES: Record<AdmonitionType, string> = {
|
|
32
|
+
note: 'Note',
|
|
33
|
+
tip: 'Tip',
|
|
34
|
+
important: 'Important',
|
|
35
|
+
warning: 'Warning',
|
|
36
|
+
caution: 'Caution',
|
|
37
|
+
};
|
package/src/web/styles.ts
CHANGED
|
@@ -59,6 +59,7 @@ export function zeroTrailingMargins(
|
|
|
59
59
|
codeBlock: { ...style.codeBlock, marginBottom: 0 },
|
|
60
60
|
thematicBreak: { ...style.thematicBreak, marginBottom: 0 },
|
|
61
61
|
image: { ...style.image, marginBottom: 0 },
|
|
62
|
+
video: { ...style.video, marginBottom: 0 },
|
|
62
63
|
math: { ...style.math, marginBottom: 0 },
|
|
63
64
|
table: { ...style.table, marginBottom: 0 },
|
|
64
65
|
};
|
|
@@ -103,7 +104,12 @@ function paragraphStyle(style: MarkdownStyleInternal): CSSProperties {
|
|
|
103
104
|
function paragraphInBlockquoteStyle(
|
|
104
105
|
style: MarkdownStyleInternal
|
|
105
106
|
): CSSProperties {
|
|
106
|
-
|
|
107
|
+
// Keep the paragraph's block margins so spacing between blocks inside a quote
|
|
108
|
+
// matches the top-level document (e.g. the gap before a heading). The last
|
|
109
|
+
// child's trailing margin is zeroed by a global blockquote :last-child rule
|
|
110
|
+
// (see globalStyles), mirroring native's trailing-margin trim - the quote is a
|
|
111
|
+
// flex-item BFC, so that margin would otherwise not collapse out of the box.
|
|
112
|
+
return baseBlock(style.paragraph);
|
|
107
113
|
}
|
|
108
114
|
|
|
109
115
|
function headingStyle(
|
|
@@ -125,7 +131,7 @@ function blockquoteStyle(style: MarkdownStyleInternal): CSSProperties {
|
|
|
125
131
|
marginBottom: blockquote.marginBottom,
|
|
126
132
|
marginInlineStart: 0, // reset UA default (40px in LTR, auto in RTL)
|
|
127
133
|
marginInlineEnd: 0,
|
|
128
|
-
paddingInlineStart: blockquote.gapWidth,
|
|
134
|
+
paddingInlineStart: blockquote.gapWidth + blockquote.padding,
|
|
129
135
|
paddingInlineEnd: blockquote.padding,
|
|
130
136
|
paddingTop: blockquote.padding,
|
|
131
137
|
paddingBottom: blockquote.padding,
|
|
@@ -235,6 +241,23 @@ function imageStyle(style: MarkdownStyleInternal): CSSProperties {
|
|
|
235
241
|
return { ...base, width: '100%', height: image.height, objectFit };
|
|
236
242
|
}
|
|
237
243
|
|
|
244
|
+
function videoStyle(style: MarkdownStyleInternal): CSSProperties {
|
|
245
|
+
const video = style.video;
|
|
246
|
+
const base: CSSProperties = {
|
|
247
|
+
width: '100%',
|
|
248
|
+
maxWidth: '100%',
|
|
249
|
+
display: 'block',
|
|
250
|
+
borderRadius: video.borderRadius,
|
|
251
|
+
backgroundColor: video.backgroundColor,
|
|
252
|
+
marginTop: video.marginTop,
|
|
253
|
+
marginBottom: video.marginBottom,
|
|
254
|
+
};
|
|
255
|
+
if (video.aspectRatio > 0) {
|
|
256
|
+
base.aspectRatio = video.aspectRatio;
|
|
257
|
+
}
|
|
258
|
+
return base;
|
|
259
|
+
}
|
|
260
|
+
|
|
238
261
|
function inlineImageStyle(style: MarkdownStyleInternal): CSSProperties {
|
|
239
262
|
const size = style.inlineImage.size;
|
|
240
263
|
return {
|
|
@@ -331,7 +354,7 @@ export function linkStyleForUrl(
|
|
|
331
354
|
resolved.paddingHorizontal > 0 || resolved.paddingVertical > 0;
|
|
332
355
|
return {
|
|
333
356
|
color: resolved.color,
|
|
334
|
-
fontFamily: normalizeFontFamily(
|
|
357
|
+
fontFamily: normalizeFontFamily(resolved.fontFamily),
|
|
335
358
|
textDecoration: resolved.underline ? 'underline' : 'none',
|
|
336
359
|
...(backgroundColor && backgroundColor !== 'transparent'
|
|
337
360
|
? { backgroundColor }
|
|
@@ -593,6 +616,7 @@ export interface Styles {
|
|
|
593
616
|
tableCell: Record<ColumnAlign, CSSProperties>;
|
|
594
617
|
taskCheckbox: CSSProperties;
|
|
595
618
|
taskCheckboxDisabled: CSSProperties;
|
|
619
|
+
video: CSSProperties;
|
|
596
620
|
}
|
|
597
621
|
|
|
598
622
|
type ColumnAlign = 'left' | 'center' | 'right' | 'default';
|
|
@@ -655,6 +679,7 @@ export function buildStyles(style: MarkdownStyleInternal): Styles {
|
|
|
655
679
|
},
|
|
656
680
|
taskCheckbox: taskCheckboxStyle(style),
|
|
657
681
|
taskCheckboxDisabled: taskCheckboxDisabledStyle(style),
|
|
682
|
+
video: videoStyle(style),
|
|
658
683
|
};
|
|
659
684
|
|
|
660
685
|
stylesStore.set(style, result);
|
package/src/web/types.ts
CHANGED
|
@@ -4,7 +4,9 @@ import type { Styles } from './styles';
|
|
|
4
4
|
import type {
|
|
5
5
|
LinkPressEvent,
|
|
6
6
|
LinkLongPressEvent,
|
|
7
|
+
ImagePressEvent,
|
|
7
8
|
TaskListItemPressEvent,
|
|
9
|
+
CodeBlockPressEvent,
|
|
8
10
|
} from '../types/events';
|
|
9
11
|
import type { LinkDecorationInfo } from '../types/MarkdownTextProps.web';
|
|
10
12
|
import type { KaTeXInstance } from './katex';
|
|
@@ -39,7 +41,10 @@ export type NodeType =
|
|
|
39
41
|
| 'TableHeaderCell'
|
|
40
42
|
| 'TableCell'
|
|
41
43
|
| 'LatexMathInline'
|
|
42
|
-
| 'LatexMathDisplay'
|
|
44
|
+
| 'LatexMathDisplay'
|
|
45
|
+
| 'BlankLine'
|
|
46
|
+
| 'Admonition'
|
|
47
|
+
| 'Video';
|
|
43
48
|
|
|
44
49
|
export interface NodeAttributes {
|
|
45
50
|
level?: string;
|
|
@@ -58,7 +63,11 @@ export interface NodeAttributes {
|
|
|
58
63
|
colCount?: string;
|
|
59
64
|
headRowCount?: string;
|
|
60
65
|
bodyRowCount?: string;
|
|
66
|
+
/** "note"/"tip"/"important"/"warning"/"caution" for a MD_BLOCK_ADMONITION. */
|
|
67
|
+
admonitionType?: string;
|
|
61
68
|
align?: 'left' | 'center' | 'right' | 'default';
|
|
69
|
+
/** Present on BlankLine nodes — count of blank lines in the source run. */
|
|
70
|
+
count?: string;
|
|
62
71
|
}
|
|
63
72
|
|
|
64
73
|
export interface ASTNode {
|
|
@@ -74,8 +83,10 @@ export interface ASTNode {
|
|
|
74
83
|
export interface RendererCallbacks {
|
|
75
84
|
onLinkPress?: (event: LinkPressEvent) => void;
|
|
76
85
|
onLinkLongPress?: (event: LinkLongPressEvent) => void;
|
|
86
|
+
onImagePress?: (event: ImagePressEvent) => void;
|
|
77
87
|
onTaskListItemPress?: (event: TaskListItemPressEvent) => void;
|
|
78
88
|
renderLinkDecoration?: (info: LinkDecorationInfo) => ReactNode | null;
|
|
89
|
+
onCodeBlockPress?: (event: CodeBlockPressEvent) => void;
|
|
79
90
|
}
|
|
80
91
|
|
|
81
92
|
export interface RenderCapabilities {
|
package/src/web/wasm/md4c.js
CHANGED
|
Binary file
|
package/vendor-ratex.mjs
CHANGED
|
@@ -52,8 +52,44 @@ function copyFile(src, dest) {
|
|
|
52
52
|
fs.copyFileSync(src, dest);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
56
|
+
|
|
57
|
+
// Downloads a url to a Buffer, resilient to the two failure modes that turn a
|
|
58
|
+
// routine install into #745: transient GitHub/CDN blips, and being behind a proxy.
|
|
59
|
+
// Node's global fetch is undici, which ignores http_proxy/https_proxy unless
|
|
60
|
+
// NODE_USE_ENV_PROXY is set, so on a proxied machine the source tarball can time out
|
|
61
|
+
// even though curl and the package manager both work. Retry fetch a few times, then
|
|
62
|
+
// fall back to curl, which honors the proxy env and retries itself. The caller still
|
|
63
|
+
// verifies the sha256, so a truncated or tampered body is caught either way.
|
|
64
|
+
async function download(url, label) {
|
|
65
|
+
const attempts = 3;
|
|
66
|
+
for (let i = 1; i <= attempts; i++) {
|
|
67
|
+
try {
|
|
68
|
+
const res = await fetch(url);
|
|
69
|
+
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
|
|
70
|
+
return Buffer.from(await res.arrayBuffer());
|
|
71
|
+
} catch (err) {
|
|
72
|
+
log(`${label} fetch attempt ${i}/${attempts} failed: ${err.message}`);
|
|
73
|
+
if (i < attempts) await sleep(500 * i);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
log(`${label} falling back to curl (honors http_proxy/https_proxy) for ${url}`);
|
|
77
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'ratex-dl-'));
|
|
78
|
+
try {
|
|
79
|
+
const dest = path.join(tmp, 'asset');
|
|
80
|
+
const res = spawnSync('curl', ['-fsSL', '--retry', '3', '-o', dest, url], { stdio: ['ignore', 'ignore', 'inherit'] });
|
|
81
|
+
if (res.error && res.error.code === 'ENOENT') {
|
|
82
|
+
fail(`${label} download failed for ${url}: fetch failed and curl is not installed`);
|
|
83
|
+
}
|
|
84
|
+
if (res.status !== 0) fail(`${label} download failed for ${url} (curl exit ${res.status})`);
|
|
85
|
+
return fs.readFileSync(dest);
|
|
86
|
+
} finally {
|
|
87
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
55
91
|
// Reads a manifest asset from a local path when the url points at an existing file
|
|
56
|
-
// (offline), otherwise
|
|
92
|
+
// (offline), otherwise downloads it. The sha256 is verified either way; a mismatch is
|
|
57
93
|
// fatal and prints the computed digest to paste back into ratex-version.json on a re-pin.
|
|
58
94
|
async function fetchAndVerify(url, sha256, label) {
|
|
59
95
|
if (!sha256) fail(`${label}.sha256 missing in ratex-version.json; cannot verify ${url}`);
|
|
@@ -63,13 +99,7 @@ async function fetchAndVerify(url, sha256, label) {
|
|
|
63
99
|
buf = fs.readFileSync(url);
|
|
64
100
|
} else {
|
|
65
101
|
log(`fetching ${label} from ${url}`);
|
|
66
|
-
|
|
67
|
-
const res = await fetch(url);
|
|
68
|
-
if (!res.ok) fail(`${label} download failed: ${res.status} ${res.statusText} for ${url}`);
|
|
69
|
-
buf = Buffer.from(await res.arrayBuffer());
|
|
70
|
-
} catch (err) {
|
|
71
|
-
fail(`${label} download failed for ${url}: ${err.message}`);
|
|
72
|
-
}
|
|
102
|
+
buf = await download(url, label);
|
|
73
103
|
}
|
|
74
104
|
const digest = crypto.createHash('sha256').update(buf).digest('hex');
|
|
75
105
|
if (digest !== sha256) {
|
|
@@ -107,8 +137,6 @@ async function main() {
|
|
|
107
137
|
if (args.manifest) manifestPath = path.resolve(args.manifest);
|
|
108
138
|
if (args.output) outDir = path.resolve(args.output);
|
|
109
139
|
|
|
110
|
-
const xcframeworkDir = path.join(outDir, 'RaTeX.xcframework');
|
|
111
|
-
const fontsOut = path.join(outDir, 'Fonts');
|
|
112
140
|
const stampFile = path.join(outDir, '.stamp');
|
|
113
141
|
|
|
114
142
|
const m = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
@@ -120,19 +148,39 @@ async function main() {
|
|
|
120
148
|
return;
|
|
121
149
|
}
|
|
122
150
|
|
|
123
|
-
|
|
124
|
-
|
|
151
|
+
// Assemble the whole tree in a sibling staging dir and swap it into place only
|
|
152
|
+
// after every asset (XCFramework, the four Swift sources, the fonts, the stamp)
|
|
153
|
+
// has landed. A failure partway -- most commonly the source tarball fetch after
|
|
154
|
+
// the XCFramework already extracted -- must never leave a half-written tree: the
|
|
155
|
+
// podspec would read the lone XCFramework as "math ready" and compile the RaTeX
|
|
156
|
+
// bridge against Swift sources that are not there (#745). Staging plus a final
|
|
157
|
+
// swap makes a failed vendor indistinguishable from an absent one, which the
|
|
158
|
+
// podspec's default-on path degrades cleanly. The staging dir is a sibling of
|
|
159
|
+
// outDir so it shares its filesystem and the closing rename never crosses
|
|
160
|
+
// devices (EXDEV), and a --force that fails leaves the previous good tree intact.
|
|
161
|
+
const staging = outDir + '.staging';
|
|
162
|
+
// fail() exits the process directly rather than throwing, so cleanup cannot live
|
|
163
|
+
// in a catch alone; an exit hook removes the staging dir on every failure path.
|
|
164
|
+
// After a successful swap the dir no longer exists, so this becomes a no-op.
|
|
165
|
+
process.on('exit', () => {
|
|
166
|
+
try { fs.rmSync(staging, { recursive: true, force: true }); } catch { /* best effort */ }
|
|
167
|
+
});
|
|
168
|
+
fs.rmSync(staging, { recursive: true, force: true });
|
|
169
|
+
fs.mkdirSync(staging, { recursive: true });
|
|
170
|
+
|
|
171
|
+
const xcframeworkDir = path.join(staging, 'RaTeX.xcframework');
|
|
172
|
+
const fontsOut = path.join(staging, 'Fonts');
|
|
125
173
|
|
|
126
174
|
// 1. Prebuilt static XCFramework (device + simulator[arm64,x86_64] + macOS slices).
|
|
127
175
|
const xcBuf = await fetchAndVerify(m.xcframework.url, m.xcframework.sha256, 'xcframework');
|
|
128
176
|
{
|
|
129
177
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'ratex-xcf-'));
|
|
130
178
|
try {
|
|
131
|
-
extractTo(xcBuf, '.zip', ['-d',
|
|
179
|
+
extractTo(xcBuf, '.zip', ['-d', staging], tmp);
|
|
132
180
|
} finally {
|
|
133
181
|
fs.rmSync(tmp, { recursive: true, force: true });
|
|
134
182
|
}
|
|
135
|
-
if (!fs.existsSync(xcframeworkDir)) fail(`extracted zip has no RaTeX.xcframework in ${
|
|
183
|
+
if (!fs.existsSync(xcframeworkDir)) fail(`extracted zip has no RaTeX.xcframework in ${staging}`);
|
|
136
184
|
}
|
|
137
185
|
|
|
138
186
|
// 2. Core Swift sources + KaTeX fonts + LICENSE from the pinned source tag.
|
|
@@ -147,7 +195,7 @@ async function main() {
|
|
|
147
195
|
for (const rel of m.source.swiftSources) {
|
|
148
196
|
const from = path.join(root, rel);
|
|
149
197
|
if (!fs.existsSync(from)) fail(`source tarball missing ${rel}`);
|
|
150
|
-
copyFile(from, path.join(
|
|
198
|
+
copyFile(from, path.join(staging, path.basename(rel)));
|
|
151
199
|
}
|
|
152
200
|
|
|
153
201
|
const fontsSrc = path.join(root, m.source.fontsDir);
|
|
@@ -159,13 +207,34 @@ async function main() {
|
|
|
159
207
|
if (n === 0) fail(`no .ttf fonts found under ${m.source.fontsDir}`);
|
|
160
208
|
|
|
161
209
|
const licenseFrom = path.join(root, m.source.license);
|
|
162
|
-
if (fs.existsSync(licenseFrom)) copyFile(licenseFrom, path.join(
|
|
210
|
+
if (fs.existsSync(licenseFrom)) copyFile(licenseFrom, path.join(staging, 'LICENSE'));
|
|
163
211
|
} finally {
|
|
164
212
|
fs.rmSync(tmp, { recursive: true, force: true });
|
|
165
213
|
}
|
|
166
214
|
}
|
|
167
215
|
|
|
168
|
-
fs.writeFileSync(
|
|
216
|
+
fs.writeFileSync(path.join(staging, '.stamp'), key + '\n');
|
|
217
|
+
|
|
218
|
+
// Publish by swapping directories, never deleting the previous tree before the new
|
|
219
|
+
// one is in place. rm-then-rename has a window where a failed rename leaves the
|
|
220
|
+
// vendor dir empty and wipes a previously-good tree. Instead: move any existing tree
|
|
221
|
+
// aside (a rename, atomic on one filesystem), then move the staged tree in; if that
|
|
222
|
+
// second move fails, restore the one set aside so a failed install can never empty
|
|
223
|
+
// the vendor dir. Only once the new tree is live is the old one removed -- a failure
|
|
224
|
+
// there is harmless, leaving a .backup the next run clears. A previously-good tree
|
|
225
|
+
// therefore survives any single failure in this sequence.
|
|
226
|
+
const backup = outDir + '.backup';
|
|
227
|
+
fs.rmSync(backup, { recursive: true, force: true });
|
|
228
|
+
const hadPrevious = fs.existsSync(outDir);
|
|
229
|
+
if (hadPrevious) fs.renameSync(outDir, backup);
|
|
230
|
+
try {
|
|
231
|
+
fs.renameSync(staging, outDir);
|
|
232
|
+
} catch (err) {
|
|
233
|
+
if (hadPrevious) fs.renameSync(backup, outDir);
|
|
234
|
+
throw err;
|
|
235
|
+
}
|
|
236
|
+
fs.rmSync(backup, { recursive: true, force: true });
|
|
237
|
+
|
|
169
238
|
log(`RaTeX ${m.tag} -> ${outDir}`);
|
|
170
239
|
log('done.');
|
|
171
240
|
}
|