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,40 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#import "ENRMFeatureFlags.h"
|
|
3
|
+
|
|
4
|
+
#if ENRICHED_MARKDOWN_VIDEO
|
|
5
|
+
|
|
6
|
+
#import "ENRMDynamicBlockProps.h"
|
|
7
|
+
#import "ENRMUIKit.h"
|
|
8
|
+
#import "StyleConfig.h"
|
|
9
|
+
|
|
10
|
+
@class MarkdownASTNode;
|
|
11
|
+
|
|
12
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
13
|
+
|
|
14
|
+
@interface ENRMVideoContainerView : RCTUIView
|
|
15
|
+
#if !TARGET_OS_OSX
|
|
16
|
+
<UIContextMenuInteractionDelegate>
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
- (instancetype)initWithConfig:(StyleConfig *)config;
|
|
20
|
+
|
|
21
|
+
- (void)applyVideoNode:(MarkdownASTNode *)node;
|
|
22
|
+
|
|
23
|
+
- (void)reapplyStyle;
|
|
24
|
+
|
|
25
|
+
- (CGFloat)measureHeight:(CGFloat)maxWidth;
|
|
26
|
+
|
|
27
|
+
+ (CGFloat)measureHeightForVideoNode:(MarkdownASTNode *)node config:(StyleConfig *)config maxWidth:(CGFloat)maxWidth;
|
|
28
|
+
|
|
29
|
+
@property (nonatomic, strong) StyleConfig *config;
|
|
30
|
+
|
|
31
|
+
// Shared, runtime-mutable block props (context-menu gate + copy labels) read live
|
|
32
|
+
// at menu-open. Set to the root's shared instance at creation. See
|
|
33
|
+
// ENRMDynamicBlockProps.
|
|
34
|
+
@property (nonatomic, strong) ENRMDynamicBlockProps *dynamicProps;
|
|
35
|
+
|
|
36
|
+
@end
|
|
37
|
+
|
|
38
|
+
NS_ASSUME_NONNULL_END
|
|
39
|
+
|
|
40
|
+
#endif
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
#import "ENRMFeatureFlags.h"
|
|
2
|
+
|
|
3
|
+
#if ENRICHED_MARKDOWN_VIDEO
|
|
4
|
+
|
|
5
|
+
#import "ENRMVideoContainerView.h"
|
|
6
|
+
#import "MarkdownASTNode.h"
|
|
7
|
+
#import "PasteboardUtils.h"
|
|
8
|
+
#import <AVKit/AVKit.h>
|
|
9
|
+
#if TARGET_OS_OSX
|
|
10
|
+
#import "ENRMMenuAction.h"
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
static const CGFloat kDefaultVideoAspectRatio = 16.0 / 9.0;
|
|
14
|
+
|
|
15
|
+
static inline CGFloat ENRMVideoAspectRatio(StyleConfig *config)
|
|
16
|
+
{
|
|
17
|
+
CGFloat aspectRatio = [config videoAspectRatio];
|
|
18
|
+
return aspectRatio > 0 ? aspectRatio : kDefaultVideoAspectRatio;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
#if !TARGET_OS_OSX
|
|
22
|
+
|
|
23
|
+
// A thin wrapper VC that hosts AVPlayerViewController as a child with correct
|
|
24
|
+
// containment. RNSScreen (react-native-screens) overrides
|
|
25
|
+
// shouldAutomaticallyForwardAppearanceMethods, so using our own intermediate VC
|
|
26
|
+
// lets us trigger appearance transitions explicitly and guarantees the player
|
|
27
|
+
// controls render.
|
|
28
|
+
@interface ENRMVideoHostController : UIViewController
|
|
29
|
+
@property (nonatomic, strong, readonly) AVPlayerViewController *playerViewController;
|
|
30
|
+
- (void)applyCornerRadius:(CGFloat)radius backgroundColor:(UIColor *)color;
|
|
31
|
+
@end
|
|
32
|
+
|
|
33
|
+
@implementation ENRMVideoHostController
|
|
34
|
+
|
|
35
|
+
- (void)viewDidLoad
|
|
36
|
+
{
|
|
37
|
+
[super viewDidLoad];
|
|
38
|
+
self.view.backgroundColor = [UIColor clearColor];
|
|
39
|
+
|
|
40
|
+
_playerViewController = [[AVPlayerViewController alloc] init];
|
|
41
|
+
_playerViewController.showsPlaybackControls = YES;
|
|
42
|
+
_playerViewController.entersFullScreenWhenPlaybackBegins = NO;
|
|
43
|
+
_playerViewController.exitsFullScreenWhenPlaybackEnds = YES;
|
|
44
|
+
_playerViewController.view.layer.masksToBounds = YES;
|
|
45
|
+
|
|
46
|
+
[self addChildViewController:_playerViewController];
|
|
47
|
+
[self.view addSubview:_playerViewController.view];
|
|
48
|
+
[_playerViewController didMoveToParentViewController:self];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
- (void)applyCornerRadius:(CGFloat)radius backgroundColor:(UIColor *)color
|
|
52
|
+
{
|
|
53
|
+
_playerViewController.view.layer.cornerRadius = radius;
|
|
54
|
+
_playerViewController.view.backgroundColor = color ?: [UIColor blackColor];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
- (void)viewDidLayoutSubviews
|
|
58
|
+
{
|
|
59
|
+
[super viewDidLayoutSubviews];
|
|
60
|
+
_playerViewController.view.frame = self.view.bounds;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@end
|
|
64
|
+
|
|
65
|
+
#endif // !TARGET_OS_OSX
|
|
66
|
+
|
|
67
|
+
// ===== iOS implementation =====
|
|
68
|
+
|
|
69
|
+
#if !TARGET_OS_OSX
|
|
70
|
+
|
|
71
|
+
static RCTUIView *ENRMCreatePlayIconOverlay(void)
|
|
72
|
+
{
|
|
73
|
+
CGFloat size = 52;
|
|
74
|
+
RCTUIView *circle = [[RCTUIView alloc] initWithFrame:CGRectMake(0, 0, size, size)];
|
|
75
|
+
circle.userInteractionEnabled = NO;
|
|
76
|
+
circle.layer.backgroundColor = [RCTUIColor colorWithWhite:0 alpha:0.5].CGColor;
|
|
77
|
+
circle.layer.cornerRadius = size / 2.0;
|
|
78
|
+
|
|
79
|
+
CGFloat inset = size * 0.3;
|
|
80
|
+
CGFloat triLeft = inset + size * 0.04;
|
|
81
|
+
CGFloat triTop = inset - size * 0.04;
|
|
82
|
+
CGFloat triRight = size - inset + size * 0.04;
|
|
83
|
+
CGFloat triMid = size / 2.0;
|
|
84
|
+
|
|
85
|
+
UIBezierPath *triangle = [UIBezierPath bezierPath];
|
|
86
|
+
[triangle moveToPoint:CGPointMake(triLeft, triTop)];
|
|
87
|
+
BezierPathAddLine(triangle, CGPointMake(triRight, triMid));
|
|
88
|
+
BezierPathAddLine(triangle, CGPointMake(triLeft, size - triTop));
|
|
89
|
+
[triangle closePath];
|
|
90
|
+
|
|
91
|
+
CAShapeLayer *triLayer = [CAShapeLayer layer];
|
|
92
|
+
triLayer.path = triangle.CGPath;
|
|
93
|
+
triLayer.fillColor = [RCTUIColor whiteColor].CGColor;
|
|
94
|
+
[circle.layer addSublayer:triLayer];
|
|
95
|
+
|
|
96
|
+
return circle;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@implementation ENRMVideoContainerView {
|
|
100
|
+
ENRMVideoHostController *_hostController;
|
|
101
|
+
RCTUIView *_playIconOverlay;
|
|
102
|
+
NSString *_currentURL;
|
|
103
|
+
BOOL _hostInstalled;
|
|
104
|
+
BOOL _hasBeenTapped;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
- (instancetype)initWithConfig:(StyleConfig *)config
|
|
108
|
+
{
|
|
109
|
+
if (self = [super init]) {
|
|
110
|
+
_config = config;
|
|
111
|
+
_dynamicProps = [[ENRMDynamicBlockProps alloc] init];
|
|
112
|
+
self.userInteractionEnabled = YES;
|
|
113
|
+
|
|
114
|
+
_hostController = [[ENRMVideoHostController alloc] init];
|
|
115
|
+
[_hostController loadViewIfNeeded];
|
|
116
|
+
[_hostController applyCornerRadius:[config videoBorderRadius] backgroundColor:[config videoBackgroundColor]];
|
|
117
|
+
[self addSubview:_hostController.view];
|
|
118
|
+
|
|
119
|
+
_playIconOverlay = ENRMCreatePlayIconOverlay();
|
|
120
|
+
_playIconOverlay.userInteractionEnabled = NO;
|
|
121
|
+
[self addSubview:_playIconOverlay];
|
|
122
|
+
|
|
123
|
+
UIContextMenuInteraction *contextMenu = [[UIContextMenuInteraction alloc] initWithDelegate:self];
|
|
124
|
+
[_hostController.view addInteraction:contextMenu];
|
|
125
|
+
}
|
|
126
|
+
return self;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#pragma mark - Touch Forwarding
|
|
130
|
+
|
|
131
|
+
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
|
|
132
|
+
{
|
|
133
|
+
if (!self.userInteractionEnabled || self.hidden || self.alpha < 0.01) {
|
|
134
|
+
return nil;
|
|
135
|
+
}
|
|
136
|
+
if ([self pointInside:point withEvent:event]) {
|
|
137
|
+
if (!_hasBeenTapped) {
|
|
138
|
+
_hasBeenTapped = YES;
|
|
139
|
+
_playIconOverlay.hidden = YES;
|
|
140
|
+
}
|
|
141
|
+
return [_hostController.view hitTest:[self convertPoint:point toView:_hostController.view] withEvent:event];
|
|
142
|
+
}
|
|
143
|
+
return nil;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
#pragma mark - View Controller Containment
|
|
147
|
+
|
|
148
|
+
- (void)didMoveToWindow
|
|
149
|
+
{
|
|
150
|
+
[super didMoveToWindow];
|
|
151
|
+
if (self.window && !_hostInstalled) {
|
|
152
|
+
UIViewController *parentVC = [self enrm_closestViewController];
|
|
153
|
+
if (parentVC) {
|
|
154
|
+
[parentVC addChildViewController:_hostController];
|
|
155
|
+
[_hostController beginAppearanceTransition:YES animated:NO];
|
|
156
|
+
[_hostController didMoveToParentViewController:parentVC];
|
|
157
|
+
[_hostController endAppearanceTransition];
|
|
158
|
+
_hostInstalled = YES;
|
|
159
|
+
}
|
|
160
|
+
} else if (!self.window && _hostInstalled) {
|
|
161
|
+
[_hostController beginAppearanceTransition:NO animated:NO];
|
|
162
|
+
[_hostController endAppearanceTransition];
|
|
163
|
+
[_hostController willMoveToParentViewController:nil];
|
|
164
|
+
[_hostController removeFromParentViewController];
|
|
165
|
+
_hostInstalled = NO;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
- (UIViewController *)enrm_closestViewController
|
|
170
|
+
{
|
|
171
|
+
UIResponder *responder = self.nextResponder;
|
|
172
|
+
while (responder) {
|
|
173
|
+
if ([responder isKindOfClass:[UIViewController class]]) {
|
|
174
|
+
return (UIViewController *)responder;
|
|
175
|
+
}
|
|
176
|
+
responder = responder.nextResponder;
|
|
177
|
+
}
|
|
178
|
+
return nil;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
#pragma mark - Style Updates
|
|
182
|
+
|
|
183
|
+
- (void)reapplyStyle
|
|
184
|
+
{
|
|
185
|
+
[_hostController applyCornerRadius:[_config videoBorderRadius] backgroundColor:[_config videoBackgroundColor]];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
#pragma mark - Video Loading
|
|
189
|
+
|
|
190
|
+
- (void)applyVideoNode:(MarkdownASTNode *)node
|
|
191
|
+
{
|
|
192
|
+
NSString *url = [node.attributes objectForKey:@"url"];
|
|
193
|
+
if (!url || [url isEqualToString:_currentURL]) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
_currentURL = [url copy];
|
|
197
|
+
_hasBeenTapped = NO;
|
|
198
|
+
_playIconOverlay.hidden = NO;
|
|
199
|
+
|
|
200
|
+
AVPlayerViewController *playerVC = _hostController.playerViewController;
|
|
201
|
+
[playerVC.player pause];
|
|
202
|
+
|
|
203
|
+
NSURL *videoURL = [NSURL URLWithString:url];
|
|
204
|
+
if (!videoURL) {
|
|
205
|
+
playerVC.player = nil;
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
playerVC.player = [AVPlayer playerWithURL:videoURL];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
#pragma mark - Layout & Measurement
|
|
213
|
+
|
|
214
|
+
- (void)layoutSubviews
|
|
215
|
+
{
|
|
216
|
+
[super layoutSubviews];
|
|
217
|
+
_hostController.view.frame = self.bounds;
|
|
218
|
+
_playIconOverlay.center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
- (CGFloat)measureHeight:(CGFloat)maxWidth
|
|
222
|
+
{
|
|
223
|
+
return maxWidth / ENRMVideoAspectRatio(_config);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
+ (CGFloat)measureHeightForVideoNode:(__unused MarkdownASTNode *)node
|
|
227
|
+
config:(StyleConfig *)config
|
|
228
|
+
maxWidth:(CGFloat)maxWidth
|
|
229
|
+
{
|
|
230
|
+
return maxWidth / ENRMVideoAspectRatio(config);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
#pragma mark - Context Menu
|
|
234
|
+
|
|
235
|
+
- (void)copyURLToPasteboard
|
|
236
|
+
{
|
|
237
|
+
if (_currentURL.length > 0) {
|
|
238
|
+
copyStringToPasteboard(_currentURL);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
- (void)copyMarkdownToPasteboard
|
|
243
|
+
{
|
|
244
|
+
if (_currentURL.length > 0) {
|
|
245
|
+
NSString *markdown;
|
|
246
|
+
if ([_currentURL containsString:@"\""]) {
|
|
247
|
+
markdown = [NSString stringWithFormat:@"<video src='%@' />", _currentURL];
|
|
248
|
+
} else {
|
|
249
|
+
markdown = [NSString stringWithFormat:@"<video src=\"%@\" />", _currentURL];
|
|
250
|
+
}
|
|
251
|
+
copyStringToPasteboard(markdown);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
- (UIContextMenuConfiguration *)contextMenuInteraction:(UIContextMenuInteraction *)interaction
|
|
256
|
+
configurationForMenuAtLocation:(CGPoint)location
|
|
257
|
+
{
|
|
258
|
+
if (!self.dynamicProps.enableBlockContextMenu || _currentURL.length == 0) {
|
|
259
|
+
return nil;
|
|
260
|
+
}
|
|
261
|
+
return [UIContextMenuConfiguration
|
|
262
|
+
configurationWithIdentifier:nil
|
|
263
|
+
previewProvider:nil
|
|
264
|
+
actionProvider:^UIMenu *(NSArray<UIMenuElement *> *suggestedActions) {
|
|
265
|
+
UIAction *copyURL =
|
|
266
|
+
[UIAction actionWithTitle:self.dynamicProps.menuCopyLabel
|
|
267
|
+
image:[RCTUIImage systemImageNamed:@"doc.on.doc"]
|
|
268
|
+
identifier:nil
|
|
269
|
+
handler:^(__kindof UIAction *action) { [self copyURLToPasteboard]; }];
|
|
270
|
+
|
|
271
|
+
UIAction *copyMarkdown =
|
|
272
|
+
[UIAction actionWithTitle:self.dynamicProps.menuCopyAsMarkdownLabel
|
|
273
|
+
image:[RCTUIImage systemImageNamed:@"doc.text"]
|
|
274
|
+
identifier:nil
|
|
275
|
+
handler:^(__kindof UIAction *action) { [self copyMarkdownToPasteboard]; }];
|
|
276
|
+
|
|
277
|
+
return [UIMenu menuWithTitle:@"" children:@[ copyURL, copyMarkdown ]];
|
|
278
|
+
}];
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
#pragma mark - Cleanup
|
|
282
|
+
|
|
283
|
+
- (void)dealloc
|
|
284
|
+
{
|
|
285
|
+
[_hostController.playerViewController.player pause];
|
|
286
|
+
_hostController.playerViewController.player = nil;
|
|
287
|
+
[_hostController beginAppearanceTransition:NO animated:NO];
|
|
288
|
+
[_hostController endAppearanceTransition];
|
|
289
|
+
[_hostController willMoveToParentViewController:nil];
|
|
290
|
+
[_hostController removeFromParentViewController];
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
@end
|
|
294
|
+
|
|
295
|
+
#else // TARGET_OS_OSX
|
|
296
|
+
|
|
297
|
+
// ===== macOS implementation =====
|
|
298
|
+
|
|
299
|
+
@implementation ENRMVideoContainerView {
|
|
300
|
+
AVPlayerView *_playerView;
|
|
301
|
+
NSString *_currentURL;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
- (instancetype)initWithConfig:(StyleConfig *)config
|
|
305
|
+
{
|
|
306
|
+
if (self = [super init]) {
|
|
307
|
+
_config = config;
|
|
308
|
+
_dynamicProps = [[ENRMDynamicBlockProps alloc] init];
|
|
309
|
+
self.wantsLayer = YES;
|
|
310
|
+
|
|
311
|
+
_playerView = [[AVPlayerView alloc] init];
|
|
312
|
+
_playerView.controlsStyle = AVPlayerViewControlsStyleInline;
|
|
313
|
+
_playerView.wantsLayer = YES;
|
|
314
|
+
_playerView.layer.masksToBounds = YES;
|
|
315
|
+
_playerView.layer.cornerRadius = [config videoBorderRadius];
|
|
316
|
+
_playerView.layer.backgroundColor = ([config videoBackgroundColor] ?: [NSColor blackColor]).CGColor;
|
|
317
|
+
[self addSubview:_playerView];
|
|
318
|
+
}
|
|
319
|
+
return self;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
- (BOOL)isFlipped
|
|
323
|
+
{
|
|
324
|
+
return YES;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
#pragma mark - Style Updates
|
|
328
|
+
|
|
329
|
+
- (void)reapplyStyle
|
|
330
|
+
{
|
|
331
|
+
_playerView.layer.cornerRadius = [_config videoBorderRadius];
|
|
332
|
+
_playerView.layer.backgroundColor = ([_config videoBackgroundColor] ?: [NSColor blackColor]).CGColor;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
#pragma mark - Video Loading
|
|
336
|
+
|
|
337
|
+
- (void)applyVideoNode:(MarkdownASTNode *)node
|
|
338
|
+
{
|
|
339
|
+
NSString *url = [node.attributes objectForKey:@"url"];
|
|
340
|
+
if (!url || [url isEqualToString:_currentURL]) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
_currentURL = [url copy];
|
|
344
|
+
|
|
345
|
+
[_playerView.player pause];
|
|
346
|
+
|
|
347
|
+
NSURL *videoURL = [NSURL URLWithString:url];
|
|
348
|
+
if (!videoURL) {
|
|
349
|
+
_playerView.player = nil;
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
_playerView.player = [AVPlayer playerWithURL:videoURL];
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
#pragma mark - Layout & Measurement
|
|
357
|
+
|
|
358
|
+
- (void)layout
|
|
359
|
+
{
|
|
360
|
+
[super layout];
|
|
361
|
+
_playerView.frame = self.bounds;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
- (CGFloat)measureHeight:(CGFloat)maxWidth
|
|
365
|
+
{
|
|
366
|
+
return maxWidth / ENRMVideoAspectRatio(_config);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
+ (CGFloat)measureHeightForVideoNode:(__unused MarkdownASTNode *)node
|
|
370
|
+
config:(StyleConfig *)config
|
|
371
|
+
maxWidth:(CGFloat)maxWidth
|
|
372
|
+
{
|
|
373
|
+
return maxWidth / ENRMVideoAspectRatio(config);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
#pragma mark - Context Menu
|
|
377
|
+
|
|
378
|
+
- (void)copyURLToPasteboard
|
|
379
|
+
{
|
|
380
|
+
if (_currentURL.length > 0) {
|
|
381
|
+
copyStringToPasteboard(_currentURL);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
- (void)copyMarkdownToPasteboard
|
|
386
|
+
{
|
|
387
|
+
if (_currentURL.length > 0) {
|
|
388
|
+
NSString *markdown;
|
|
389
|
+
if ([_currentURL containsString:@"\""]) {
|
|
390
|
+
markdown = [NSString stringWithFormat:@"<video src='%@' />", _currentURL];
|
|
391
|
+
} else {
|
|
392
|
+
markdown = [NSString stringWithFormat:@"<video src=\"%@\" />", _currentURL];
|
|
393
|
+
}
|
|
394
|
+
copyStringToPasteboard(markdown);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
- (NSMenu *)menuForEvent:(NSEvent *)event
|
|
399
|
+
{
|
|
400
|
+
if (!self.dynamicProps.enableBlockContextMenu || _currentURL.length == 0) {
|
|
401
|
+
return [super menuForEvent:event];
|
|
402
|
+
}
|
|
403
|
+
NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
|
|
404
|
+
[menu addItem:ENRMCreateMenuItem(self.dynamicProps.menuCopyLabel, ^{ [self copyURLToPasteboard]; })];
|
|
405
|
+
[menu addItem:ENRMCreateMenuItem(self.dynamicProps.menuCopyAsMarkdownLabel, ^{ [self copyMarkdownToPasteboard]; })];
|
|
406
|
+
return menu;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
#pragma mark - Cleanup
|
|
410
|
+
|
|
411
|
+
- (void)dealloc
|
|
412
|
+
{
|
|
413
|
+
[_playerView.player pause];
|
|
414
|
+
_playerView.player = nil;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
@end
|
|
418
|
+
|
|
419
|
+
#endif // TARGET_OS_OSX
|
|
420
|
+
|
|
421
|
+
#endif // ENRICHED_MARKDOWN_VIDEO
|
|
@@ -11,7 +11,9 @@ typedef NS_ENUM(NSInteger, ENRMSegmentKind) {
|
|
|
11
11
|
ENRMSegmentKindText,
|
|
12
12
|
ENRMSegmentKindTable,
|
|
13
13
|
ENRMSegmentKindMath,
|
|
14
|
-
ENRMSegmentKindCodeBlock
|
|
14
|
+
ENRMSegmentKindCodeBlock,
|
|
15
|
+
ENRMSegmentKindBlockquote,
|
|
16
|
+
ENRMSegmentKindVideo
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
@interface ENRMTextSegment : NSObject
|
|
@@ -26,7 +28,8 @@ typedef NS_ENUM(NSInteger, ENRMSegmentKind) {
|
|
|
26
28
|
|
|
27
29
|
@interface ENRMMathSegment : NSObject
|
|
28
30
|
@property (nonatomic, strong) NSString *latex;
|
|
29
|
-
|
|
31
|
+
@property (nonatomic, assign) BOOL highlighted;
|
|
32
|
+
+ (instancetype)segmentWithLatex:(NSString *)latex highlighted:(BOOL)highlighted;
|
|
30
33
|
@end
|
|
31
34
|
|
|
32
35
|
@interface ENRMCodeBlockSegment : NSObject
|
|
@@ -34,6 +37,16 @@ typedef NS_ENUM(NSInteger, ENRMSegmentKind) {
|
|
|
34
37
|
+ (instancetype)segmentWithCodeBlockNode:(MarkdownASTNode *)node;
|
|
35
38
|
@end
|
|
36
39
|
|
|
40
|
+
@interface ENRMBlockquoteSegment : NSObject
|
|
41
|
+
@property (nonatomic, strong) MarkdownASTNode *blockquoteNode;
|
|
42
|
+
+ (instancetype)segmentWithBlockquoteNode:(MarkdownASTNode *)node;
|
|
43
|
+
@end
|
|
44
|
+
|
|
45
|
+
@interface ENRMVideoSegment : NSObject
|
|
46
|
+
@property (nonatomic, strong) MarkdownASTNode *videoNode;
|
|
47
|
+
+ (instancetype)segmentWithVideoNode:(MarkdownASTNode *)node;
|
|
48
|
+
@end
|
|
49
|
+
|
|
37
50
|
@interface ENRMRenderedSegment : NSObject
|
|
38
51
|
@property (nonatomic, assign) ENRMSegmentKind kind;
|
|
39
52
|
@property (nonatomic, assign) uint64_t signature;
|
|
@@ -41,10 +54,14 @@ typedef NS_ENUM(NSInteger, ENRMSegmentKind) {
|
|
|
41
54
|
@property (nonatomic, strong, nullable) ENRMTableSegment *tableSegment;
|
|
42
55
|
@property (nonatomic, strong, nullable) ENRMMathSegment *mathSegment;
|
|
43
56
|
@property (nonatomic, strong, nullable) ENRMCodeBlockSegment *codeBlockSegment;
|
|
57
|
+
@property (nonatomic, strong, nullable) ENRMBlockquoteSegment *blockquoteSegment;
|
|
58
|
+
@property (nonatomic, strong, nullable) ENRMVideoSegment *videoSegment;
|
|
44
59
|
+ (instancetype)textSegmentWithResult:(ENRMRenderResult *)result signature:(uint64_t)signature;
|
|
45
60
|
+ (instancetype)tableSegmentWithSegment:(ENRMTableSegment *)segment signature:(uint64_t)signature;
|
|
46
61
|
+ (instancetype)mathSegmentWithSegment:(ENRMMathSegment *)segment signature:(uint64_t)signature;
|
|
47
62
|
+ (instancetype)codeBlockSegmentWithSegment:(ENRMCodeBlockSegment *)segment signature:(uint64_t)signature;
|
|
63
|
+
+ (instancetype)blockquoteSegmentWithSegment:(ENRMBlockquoteSegment *)segment signature:(uint64_t)signature;
|
|
64
|
+
+ (instancetype)videoSegmentWithSegment:(ENRMVideoSegment *)segment signature:(uint64_t)signature;
|
|
48
65
|
@end
|
|
49
66
|
|
|
50
67
|
#ifdef __cplusplus
|
|
@@ -22,11 +22,12 @@
|
|
|
22
22
|
@end
|
|
23
23
|
|
|
24
24
|
@implementation ENRMMathSegment
|
|
25
|
-
+ (instancetype)segmentWithLatex:(NSString *)latex
|
|
25
|
+
+ (instancetype)segmentWithLatex:(NSString *)latex highlighted:(BOOL)highlighted
|
|
26
26
|
{
|
|
27
27
|
NSParameterAssert(latex != nil);
|
|
28
28
|
ENRMMathSegment *segment = [[ENRMMathSegment alloc] init];
|
|
29
29
|
segment.latex = latex;
|
|
30
|
+
segment.highlighted = highlighted;
|
|
30
31
|
return segment;
|
|
31
32
|
}
|
|
32
33
|
@end
|
|
@@ -41,6 +42,26 @@
|
|
|
41
42
|
}
|
|
42
43
|
@end
|
|
43
44
|
|
|
45
|
+
@implementation ENRMBlockquoteSegment
|
|
46
|
+
+ (instancetype)segmentWithBlockquoteNode:(MarkdownASTNode *)node
|
|
47
|
+
{
|
|
48
|
+
NSParameterAssert(node != nil);
|
|
49
|
+
ENRMBlockquoteSegment *segment = [[ENRMBlockquoteSegment alloc] init];
|
|
50
|
+
segment.blockquoteNode = node;
|
|
51
|
+
return segment;
|
|
52
|
+
}
|
|
53
|
+
@end
|
|
54
|
+
|
|
55
|
+
@implementation ENRMVideoSegment
|
|
56
|
+
+ (instancetype)segmentWithVideoNode:(MarkdownASTNode *)node
|
|
57
|
+
{
|
|
58
|
+
NSParameterAssert(node != nil);
|
|
59
|
+
ENRMVideoSegment *segment = [[ENRMVideoSegment alloc] init];
|
|
60
|
+
segment.videoNode = node;
|
|
61
|
+
return segment;
|
|
62
|
+
}
|
|
63
|
+
@end
|
|
64
|
+
|
|
44
65
|
@implementation ENRMRenderedSegment
|
|
45
66
|
+ (instancetype)textSegmentWithResult:(ENRMRenderResult *)result signature:(uint64_t)signature
|
|
46
67
|
{
|
|
@@ -81,6 +102,26 @@
|
|
|
81
102
|
segment.signature = signature;
|
|
82
103
|
return segment;
|
|
83
104
|
}
|
|
105
|
+
|
|
106
|
+
+ (instancetype)blockquoteSegmentWithSegment:(ENRMBlockquoteSegment *)blockquoteSegment signature:(uint64_t)signature
|
|
107
|
+
{
|
|
108
|
+
NSParameterAssert(blockquoteSegment != nil);
|
|
109
|
+
ENRMRenderedSegment *segment = [[ENRMRenderedSegment alloc] init];
|
|
110
|
+
segment.kind = ENRMSegmentKindBlockquote;
|
|
111
|
+
segment.blockquoteSegment = blockquoteSegment;
|
|
112
|
+
segment.signature = signature;
|
|
113
|
+
return segment;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
+ (instancetype)videoSegmentWithSegment:(ENRMVideoSegment *)videoSegment signature:(uint64_t)signature
|
|
117
|
+
{
|
|
118
|
+
NSParameterAssert(videoSegment != nil);
|
|
119
|
+
ENRMRenderedSegment *segment = [[ENRMRenderedSegment alloc] init];
|
|
120
|
+
segment.kind = ENRMSegmentKindVideo;
|
|
121
|
+
segment.videoSegment = videoSegment;
|
|
122
|
+
segment.signature = signature;
|
|
123
|
+
return segment;
|
|
124
|
+
}
|
|
84
125
|
@end
|
|
85
126
|
|
|
86
127
|
// FNV-1a 64-bit hash for segment signatures. Collisions are theoretically
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#import <Foundation/Foundation.h>
|
|
4
|
+
|
|
5
|
+
@class ENRMRenderedSegment;
|
|
6
|
+
@class MarkdownASTNode;
|
|
7
|
+
@class StyleConfig;
|
|
8
|
+
|
|
9
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
10
|
+
|
|
11
|
+
#ifdef __cplusplus
|
|
12
|
+
extern "C" {
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
// blockquoteContent = YES when splitting a blockquote's own children (called by
|
|
16
|
+
// ENRMBlockquoteContainerView): text segments are then rendered with blockquote styling
|
|
17
|
+
// (tight paragraphs, quote font/color/line height) instead of paragraph styling.
|
|
18
|
+
NSArray<ENRMRenderedSegment *> *
|
|
19
|
+
ENRMRenderSegmentsFromAST(MarkdownASTNode *ast, StyleConfig *config, BOOL allowTrailingMargin, BOOL allowFontScaling,
|
|
20
|
+
CGFloat maxFontSizeMultiplier, NSLineBreakStrategy lineBreakStrategy, BOOL blockquoteContent);
|
|
21
|
+
|
|
22
|
+
#ifdef __cplusplus
|
|
23
|
+
}
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
NS_ASSUME_NONNULL_END
|