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,164 @@
|
|
|
1
|
+
package com.swmansion.enriched.markdown.segments
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.view.View
|
|
5
|
+
import android.widget.FrameLayout
|
|
6
|
+
import kotlin.math.ceil
|
|
7
|
+
import kotlin.math.max
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Reusable view for an AST branch node that holds a vertical stack of block
|
|
11
|
+
* children (the document root and every blockquote). It owns the machinery
|
|
12
|
+
* shared by both: reconciling a list of RenderedSegment into real child views
|
|
13
|
+
* by signature, stacking them vertically with per-segment margins, and
|
|
14
|
+
* reporting the total height (including its own vertical padding).
|
|
15
|
+
*
|
|
16
|
+
* Per-kind view construction is delegated to a SegmentViewFactory the subclass
|
|
17
|
+
* supplies, so root-only wiring (link/copy callbacks, selection menu, spoiler,
|
|
18
|
+
* accessibility, task-list toggle, pending code block) lives with the root and
|
|
19
|
+
* the nested blockquote factory reuses only the shared creators.
|
|
20
|
+
*
|
|
21
|
+
* Layout honors paddingLeft/Top/Right/Bottom so a subclass can inset its
|
|
22
|
+
* children (e.g. a blockquote's border/gap/padding) via padding: children are
|
|
23
|
+
* measured at exactly width - paddingLeft - paddingRight and laid out starting
|
|
24
|
+
* at (paddingLeft, paddingTop). The root uses zero padding, so its behavior is
|
|
25
|
+
* unchanged.
|
|
26
|
+
*/
|
|
27
|
+
open class ContainerNodeView(
|
|
28
|
+
context: Context,
|
|
29
|
+
) : FrameLayout(context) {
|
|
30
|
+
protected val segmentViews = mutableListOf<View>()
|
|
31
|
+
protected val segmentSignatures = mutableListOf<Long>()
|
|
32
|
+
|
|
33
|
+
protected lateinit var segmentViewFactory: SegmentViewFactory
|
|
34
|
+
|
|
35
|
+
protected var trailingMarginEnabled: Boolean = false
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Reconciles the current child views against renderedSegments, attaching and
|
|
39
|
+
* removing views as needed and updating segmentViews/segmentSignatures.
|
|
40
|
+
* Returns whether the topology changed (any view attached or removed).
|
|
41
|
+
*/
|
|
42
|
+
protected fun applySegments(
|
|
43
|
+
renderedSegments: List<RenderedSegment>,
|
|
44
|
+
reset: Boolean,
|
|
45
|
+
): Boolean {
|
|
46
|
+
val result =
|
|
47
|
+
SegmentReconciler.reconcile(
|
|
48
|
+
currentViews = segmentViews.toList(),
|
|
49
|
+
currentSignatures = segmentSignatures.toList(),
|
|
50
|
+
renderedSegments = renderedSegments,
|
|
51
|
+
reset = reset,
|
|
52
|
+
matchesKind = segmentViewFactory::matchesKind,
|
|
53
|
+
createView = { segment ->
|
|
54
|
+
val view = segmentViewFactory.createView(segment)
|
|
55
|
+
segmentViewFactory.animateNewView(view, segment)
|
|
56
|
+
view
|
|
57
|
+
},
|
|
58
|
+
updateView = { view, segment -> segmentViewFactory.updateView(view, segment) },
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
result.viewsToRemove.forEach { removeView(it) }
|
|
62
|
+
result.viewsToAttach.forEach { addView(it) }
|
|
63
|
+
|
|
64
|
+
// Only created views are appended, so a signature-based reorder would leave
|
|
65
|
+
// getChildAt out of step with segmentViews. detach/attach splices the child array
|
|
66
|
+
// without a detach-from-window pass, so a moved child keeps its selection, focus
|
|
67
|
+
// and scroll state; each step fixes one index without disturbing the ones before it.
|
|
68
|
+
result.views.forEachIndexed { index, view ->
|
|
69
|
+
if (getChildAt(index) !== view) {
|
|
70
|
+
detachViewFromParent(view)
|
|
71
|
+
attachViewToParent(view, index, view.layoutParams)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
segmentViews.clear()
|
|
76
|
+
segmentViews.addAll(result.views)
|
|
77
|
+
segmentSignatures.clear()
|
|
78
|
+
segmentSignatures.addAll(result.signatures)
|
|
79
|
+
|
|
80
|
+
return result.viewsToAttach.isNotEmpty() || result.viewsToRemove.isNotEmpty()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
protected fun layoutSegments() {
|
|
84
|
+
val containerWidth = width
|
|
85
|
+
if (containerWidth <= 0) return
|
|
86
|
+
|
|
87
|
+
val contentWidth = (containerWidth - paddingLeft - paddingRight).coerceAtLeast(0)
|
|
88
|
+
|
|
89
|
+
val needsOverhang =
|
|
90
|
+
segmentViews.any { view ->
|
|
91
|
+
view is TableContainerView &&
|
|
92
|
+
ceil(view.tableStyle.horizontalOverflow.toDouble()).toInt() > 0
|
|
93
|
+
}
|
|
94
|
+
if (clipChildren == needsOverhang) {
|
|
95
|
+
clipChildren = !needsOverhang
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
var currentY = paddingTop
|
|
99
|
+
val lastIndex = segmentViews.lastIndex
|
|
100
|
+
val widthSpec = MeasureSpec.makeMeasureSpec(contentWidth, MeasureSpec.EXACTLY)
|
|
101
|
+
val heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)
|
|
102
|
+
|
|
103
|
+
segmentViews.forEachIndexed { index, view ->
|
|
104
|
+
val segment = view as? BlockSegmentView
|
|
105
|
+
val shouldAddBottomMargin = index != lastIndex || trailingMarginEnabled
|
|
106
|
+
|
|
107
|
+
currentY += segment?.segmentMarginTop ?: 0
|
|
108
|
+
|
|
109
|
+
val overhang =
|
|
110
|
+
if (view is TableContainerView) {
|
|
111
|
+
max(ceil(view.tableStyle.horizontalOverflow.toDouble()).toInt(), 0)
|
|
112
|
+
} else {
|
|
113
|
+
0
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (overhang > 0) {
|
|
117
|
+
val extendedWidth = contentWidth + overhang * 2
|
|
118
|
+
val extWidthSpec = MeasureSpec.makeMeasureSpec(extendedWidth, MeasureSpec.EXACTLY)
|
|
119
|
+
view.measure(extWidthSpec, heightSpec)
|
|
120
|
+
view.layout(
|
|
121
|
+
paddingLeft - overhang,
|
|
122
|
+
currentY,
|
|
123
|
+
paddingLeft + contentWidth + overhang,
|
|
124
|
+
currentY + view.measuredHeight,
|
|
125
|
+
)
|
|
126
|
+
} else {
|
|
127
|
+
view.measure(widthSpec, heightSpec)
|
|
128
|
+
view.layout(paddingLeft, currentY, paddingLeft + contentWidth, currentY + view.measuredHeight)
|
|
129
|
+
}
|
|
130
|
+
currentY += view.measuredHeight
|
|
131
|
+
|
|
132
|
+
if (shouldAddBottomMargin) {
|
|
133
|
+
currentY += segment?.segmentMarginBottom ?: 0
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Measures every child at the inner content width so computeSegmentsTotalHeight
|
|
140
|
+
* can read accurate measuredHeights during a subclass's onMeasure, before the
|
|
141
|
+
* onLayout pass runs layoutSegments. Without this a container that sizes itself
|
|
142
|
+
* from its children (a blockquote) would measure them as zero-height and clip.
|
|
143
|
+
*/
|
|
144
|
+
protected fun measureSegmentChildren(outerWidth: Int) {
|
|
145
|
+
val contentWidth = (outerWidth - paddingLeft - paddingRight).coerceAtLeast(0)
|
|
146
|
+
val widthSpec = MeasureSpec.makeMeasureSpec(contentWidth, MeasureSpec.EXACTLY)
|
|
147
|
+
val heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)
|
|
148
|
+
segmentViews.forEach { it.measure(widthSpec, heightSpec) }
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
protected fun computeSegmentsTotalHeight(): Int {
|
|
152
|
+
var totalHeight = paddingTop + paddingBottom
|
|
153
|
+
val lastIndex = segmentViews.lastIndex
|
|
154
|
+
segmentViews.forEachIndexed { index, view ->
|
|
155
|
+
val segment = view as? BlockSegmentView
|
|
156
|
+
totalHeight += segment?.segmentMarginTop ?: 0
|
|
157
|
+
totalHeight += view.measuredHeight
|
|
158
|
+
if (index != lastIndex || trailingMarginEnabled) {
|
|
159
|
+
totalHeight += segment?.segmentMarginBottom ?: 0
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return totalHeight
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package com.swmansion.enriched.markdown.
|
|
1
|
+
package com.swmansion.enriched.markdown.segments
|
|
2
2
|
|
|
3
3
|
import com.swmansion.enriched.markdown.parser.MarkdownASTNode
|
|
4
4
|
|
|
@@ -19,6 +19,14 @@ sealed interface MarkdownSegment {
|
|
|
19
19
|
data class CodeBlock(
|
|
20
20
|
val node: MarkdownASTNode,
|
|
21
21
|
) : MarkdownSegment
|
|
22
|
+
|
|
23
|
+
data class Blockquote(
|
|
24
|
+
val node: MarkdownASTNode,
|
|
25
|
+
) : MarkdownSegment
|
|
26
|
+
|
|
27
|
+
data class Video(
|
|
28
|
+
val node: MarkdownASTNode,
|
|
29
|
+
) : MarkdownSegment
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
fun splitASTIntoSegments(root: MarkdownASTNode): List<MarkdownSegment> {
|
|
@@ -55,6 +63,18 @@ fun splitASTIntoSegments(root: MarkdownASTNode): List<MarkdownSegment> {
|
|
|
55
63
|
segments.add(MarkdownSegment.CodeBlock(child))
|
|
56
64
|
}
|
|
57
65
|
|
|
66
|
+
MarkdownASTNode.NodeType.Blockquote,
|
|
67
|
+
MarkdownASTNode.NodeType.Admonition,
|
|
68
|
+
-> {
|
|
69
|
+
flushTextNodes()
|
|
70
|
+
segments.add(MarkdownSegment.Blockquote(child))
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
MarkdownASTNode.NodeType.Video -> {
|
|
74
|
+
flushTextNodes()
|
|
75
|
+
segments.add(MarkdownSegment.Video(child))
|
|
76
|
+
}
|
|
77
|
+
|
|
58
78
|
else -> {
|
|
59
79
|
currentTextNodes.add(child)
|
|
60
80
|
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
package com.swmansion.enriched.markdown.segments
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.text.Spannable
|
|
5
|
+
import com.swmansion.enriched.markdown.math.LatexErrorReporter
|
|
6
|
+
import com.swmansion.enriched.markdown.parser.MarkdownASTNode
|
|
7
|
+
import com.swmansion.enriched.markdown.renderer.BlockquoteTextRenderer
|
|
8
|
+
import com.swmansion.enriched.markdown.renderer.Renderer
|
|
9
|
+
import com.swmansion.enriched.markdown.spans.ImageSpan
|
|
10
|
+
import com.swmansion.enriched.markdown.styles.BlockquoteStyle
|
|
11
|
+
import com.swmansion.enriched.markdown.styles.StyleConfig
|
|
12
|
+
|
|
13
|
+
sealed interface RenderedSegment {
|
|
14
|
+
val signature: Long
|
|
15
|
+
|
|
16
|
+
data class Text(
|
|
17
|
+
/**
|
|
18
|
+
* The renderer's own buffer, which the segment's text view adopts uncopied.
|
|
19
|
+
* Once displayed it *is* the view's live text, so the view mutates it: `TextView`
|
|
20
|
+
* attaches its `ChangeWatcher`, the `Editor` its `SpanController`, and selection
|
|
21
|
+
* adds and moves the selection marks — all as spans on this very instance.
|
|
22
|
+
*
|
|
23
|
+
* A segment is therefore only a faithful record of what the renderer produced
|
|
24
|
+
* until the view takes it. Anything that caches, diffs, counts or hashes the spans
|
|
25
|
+
* here must read them before the segment is applied, or filter the view's spans
|
|
26
|
+
* out; reading afterwards yields the view's bookkeeping mixed in with the markdown
|
|
27
|
+
* spans, and a result that changes as the user merely selects text.
|
|
28
|
+
*/
|
|
29
|
+
val styledText: Spannable,
|
|
30
|
+
val imageSpans: List<ImageSpan>,
|
|
31
|
+
val needsJustify: Boolean,
|
|
32
|
+
val lastElementMarginBottom: Float,
|
|
33
|
+
override val signature: Long,
|
|
34
|
+
) : RenderedSegment
|
|
35
|
+
|
|
36
|
+
data class Table(
|
|
37
|
+
val node: MarkdownASTNode,
|
|
38
|
+
override val signature: Long,
|
|
39
|
+
) : RenderedSegment
|
|
40
|
+
|
|
41
|
+
data class Math(
|
|
42
|
+
val latex: String,
|
|
43
|
+
val highlighted: Boolean,
|
|
44
|
+
override val signature: Long,
|
|
45
|
+
) : RenderedSegment
|
|
46
|
+
|
|
47
|
+
data class CodeBlock(
|
|
48
|
+
val node: MarkdownASTNode,
|
|
49
|
+
override val signature: Long,
|
|
50
|
+
) : RenderedSegment
|
|
51
|
+
|
|
52
|
+
data class Blockquote(
|
|
53
|
+
val node: MarkdownASTNode,
|
|
54
|
+
override val signature: Long,
|
|
55
|
+
) : RenderedSegment
|
|
56
|
+
|
|
57
|
+
data class Video(
|
|
58
|
+
val node: MarkdownASTNode,
|
|
59
|
+
override val signature: Long,
|
|
60
|
+
) : RenderedSegment
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
object MarkdownSegmentRenderer {
|
|
64
|
+
fun render(
|
|
65
|
+
segments: List<MarkdownSegment>,
|
|
66
|
+
style: StyleConfig,
|
|
67
|
+
context: Context,
|
|
68
|
+
onLinkPress: ((String) -> Unit)?,
|
|
69
|
+
onLinkLongPress: ((String) -> Unit)?,
|
|
70
|
+
blockquoteStyle: BlockquoteStyle? = null,
|
|
71
|
+
onLatexError: LatexErrorReporter? = null,
|
|
72
|
+
): List<RenderedSegment> =
|
|
73
|
+
segments.map { segment ->
|
|
74
|
+
when (segment) {
|
|
75
|
+
is MarkdownSegment.Text -> {
|
|
76
|
+
renderTextSegment(segment.nodes, style, context, onLinkPress, onLinkLongPress, blockquoteStyle, onLatexError)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
is MarkdownSegment.Table -> {
|
|
80
|
+
val signature = SegmentSignature.signatureForNode(segment.node) xor SegmentSignature.TABLE_KIND_SALT
|
|
81
|
+
RenderedSegment.Table(segment.node, signature)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
is MarkdownSegment.Math -> {
|
|
85
|
+
var signature = SegmentSignature.signatureForNode(null) xor SegmentSignature.MATH_KIND_SALT
|
|
86
|
+
signature = SegmentSignature.fnvMixString(signature, segment.latex)
|
|
87
|
+
val highlighted = segment.node.getAttribute("highlight") == "true"
|
|
88
|
+
// A highlight toggle keeps the latex, so it must change the signature or the view is skipped.
|
|
89
|
+
if (highlighted) signature = SegmentSignature.fnvMixString(signature, "highlight")
|
|
90
|
+
RenderedSegment.Math(segment.latex, highlighted, signature)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
is MarkdownSegment.CodeBlock -> {
|
|
94
|
+
val signature = SegmentSignature.signatureForNode(segment.node) xor SegmentSignature.CODE_BLOCK_KIND_SALT
|
|
95
|
+
RenderedSegment.CodeBlock(segment.node, signature)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
is MarkdownSegment.Blockquote -> {
|
|
99
|
+
val signature = SegmentSignature.signatureForNode(segment.node) xor SegmentSignature.BLOCKQUOTE_KIND_SALT
|
|
100
|
+
RenderedSegment.Blockquote(segment.node, signature)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
is MarkdownSegment.Video -> {
|
|
104
|
+
val signature = SegmentSignature.signatureForNode(segment.node) xor SegmentSignature.VIDEO_KIND_SALT
|
|
105
|
+
RenderedSegment.Video(segment.node, signature)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private fun renderTextSegment(
|
|
111
|
+
nodes: List<MarkdownASTNode>,
|
|
112
|
+
style: StyleConfig,
|
|
113
|
+
context: Context,
|
|
114
|
+
onLinkPress: ((String) -> Unit)?,
|
|
115
|
+
onLinkLongPress: ((String) -> Unit)?,
|
|
116
|
+
blockquoteStyle: BlockquoteStyle?,
|
|
117
|
+
onLatexError: LatexErrorReporter?,
|
|
118
|
+
): RenderedSegment.Text {
|
|
119
|
+
val renderer = Renderer().apply { configure(style, context, onLatexError) }
|
|
120
|
+
val signature = SegmentSignature.signatureForNodes(nodes) xor SegmentSignature.TEXT_KIND_SALT
|
|
121
|
+
|
|
122
|
+
val styledText =
|
|
123
|
+
if (blockquoteStyle != null) {
|
|
124
|
+
BlockquoteTextRenderer(blockquoteStyle).render(renderer, nodes, onLinkPress, onLinkLongPress)
|
|
125
|
+
} else {
|
|
126
|
+
renderer.renderContent(nodes, onLinkPress, onLinkLongPress)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return RenderedSegment.Text(
|
|
130
|
+
styledText = styledText,
|
|
131
|
+
imageSpans = renderer.getCollectedImageSpans().toList(),
|
|
132
|
+
needsJustify = style.needsJustify,
|
|
133
|
+
lastElementMarginBottom = renderer.getLastElementMarginBottom(),
|
|
134
|
+
signature = signature,
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
}
|
package/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentHeightMeasurer.kt
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
package com.swmansion.enriched.markdown.segments
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.graphics.Paint
|
|
5
|
+
import android.os.Build
|
|
6
|
+
import android.text.Layout
|
|
7
|
+
import android.text.StaticLayout
|
|
8
|
+
import android.text.TextPaint
|
|
9
|
+
import com.swmansion.enriched.markdown.MeasurementStore
|
|
10
|
+
import com.swmansion.enriched.markdown.styles.StyleConfig
|
|
11
|
+
import com.swmansion.enriched.markdown.utils.text.extensions.replaceMathSpansWithPlaceholders
|
|
12
|
+
import kotlin.math.ceil
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* View-free height summation for a vertical stack of RenderedSegments at a fixed
|
|
16
|
+
* content width, single-sourced so the shadow-node measurement pass
|
|
17
|
+
* (MeasurementStore) and the blockquote container's own static measurer report
|
|
18
|
+
* identical heights.
|
|
19
|
+
*
|
|
20
|
+
* Math heights must be measured up front on the main thread by the caller and
|
|
21
|
+
* supplied through mathHeightForIndex, because the summation runs off the main
|
|
22
|
+
* thread. Blockquote children recurse through
|
|
23
|
+
* BlockquoteContainerView.measureBlockquoteNodeHeight.
|
|
24
|
+
*/
|
|
25
|
+
object SegmentHeightMeasurer {
|
|
26
|
+
fun measureSegmentsHeight(
|
|
27
|
+
segments: List<RenderedSegment>,
|
|
28
|
+
style: StyleConfig,
|
|
29
|
+
context: Context,
|
|
30
|
+
contentWidthPx: Float,
|
|
31
|
+
fontSizePx: Float,
|
|
32
|
+
breakStrategy: Int,
|
|
33
|
+
allowTrailingMargin: Boolean,
|
|
34
|
+
mathHeightForIndex: (Int) -> Float,
|
|
35
|
+
): Float {
|
|
36
|
+
val widthPx = ceil(contentWidthPx).toInt().coerceAtLeast(1)
|
|
37
|
+
val lastIndex = segments.lastIndex
|
|
38
|
+
var totalHeightPx = 0f
|
|
39
|
+
|
|
40
|
+
for ((index, segment) in segments.withIndex()) {
|
|
41
|
+
val isLastSegment = index == lastIndex
|
|
42
|
+
val includeBottomMargin = if (isLastSegment) allowTrailingMargin else true
|
|
43
|
+
|
|
44
|
+
when (segment) {
|
|
45
|
+
is RenderedSegment.Text -> {
|
|
46
|
+
// Same inlineMath.paddingVertical (+ glyphOverflow) the real spans are built with,
|
|
47
|
+
// or the measured line box won't match the drawn one.
|
|
48
|
+
segment.styledText.replaceMathSpansWithPlaceholders(context, style.inlineMathStyle.boxPaddingVertical)
|
|
49
|
+
val layout = createStaticLayout(segment.styledText, fontSizePx, widthPx, breakStrategy)
|
|
50
|
+
totalHeightPx += layout.height
|
|
51
|
+
if (includeBottomMargin) {
|
|
52
|
+
totalHeightPx += segment.lastElementMarginBottom
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
is RenderedSegment.Table -> {
|
|
57
|
+
totalHeightPx += style.tableStyle.marginTop
|
|
58
|
+
totalHeightPx += TableContainerView.measureTableNodeHeight(segment.node, style, context)
|
|
59
|
+
if (includeBottomMargin) {
|
|
60
|
+
totalHeightPx += style.tableStyle.marginBottom
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
is RenderedSegment.Math -> {
|
|
65
|
+
totalHeightPx += style.mathStyle.marginTop
|
|
66
|
+
totalHeightPx += mathHeightForIndex(index)
|
|
67
|
+
if (includeBottomMargin) {
|
|
68
|
+
totalHeightPx += style.mathStyle.marginBottom
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
is RenderedSegment.CodeBlock -> {
|
|
73
|
+
totalHeightPx += style.codeBlockStyle.marginTop
|
|
74
|
+
totalHeightPx += CodeBlockContainerView.measureCodeBlockNodeHeight(segment.node, style, context, contentWidthPx)
|
|
75
|
+
if (includeBottomMargin) {
|
|
76
|
+
totalHeightPx += style.codeBlockStyle.marginBottom
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
is RenderedSegment.Blockquote -> {
|
|
81
|
+
// A quote encountered here is always nested inside another quote, so it
|
|
82
|
+
// carries no vertical margin (only the outermost quote does, added by
|
|
83
|
+
// MeasurementStore); this mirrors BlockquoteContainerView.nested.
|
|
84
|
+
totalHeightPx += BlockquoteContainerView.measureBlockquoteNodeHeight(segment.node, style, context, contentWidthPx)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
is RenderedSegment.Video -> {
|
|
88
|
+
totalHeightPx += style.videoStyle.marginTop
|
|
89
|
+
totalHeightPx += contentWidthPx / style.videoStyle.resolvedAspectRatio
|
|
90
|
+
if (includeBottomMargin) {
|
|
91
|
+
totalHeightPx += style.videoStyle.marginBottom
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return totalHeightPx
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fun createStaticLayout(
|
|
100
|
+
text: CharSequence,
|
|
101
|
+
fontSizePx: Float,
|
|
102
|
+
widthPx: Int,
|
|
103
|
+
breakStrategy: Int,
|
|
104
|
+
): StaticLayout {
|
|
105
|
+
val paint =
|
|
106
|
+
TextPaint(Paint.ANTI_ALIAS_FLAG).apply {
|
|
107
|
+
textSize = fontSizePx
|
|
108
|
+
}
|
|
109
|
+
// HWK-1415: AppCompatTextView draws emoji through EmojiCompat, which can be wider than
|
|
110
|
+
// the fallback glyph and wrap a line earlier, so measure the same glyphs here too
|
|
111
|
+
// (MeasurementStore measures every blockquote through this path).
|
|
112
|
+
val content = MeasurementStore.withEmojiSpans(text)
|
|
113
|
+
prepareImageSpansForMeasurement(content, widthPx)
|
|
114
|
+
return StaticLayout.Builder
|
|
115
|
+
.obtain(content, 0, content.length, paint, widthPx)
|
|
116
|
+
.setIncludePad(false)
|
|
117
|
+
.setLineSpacing(0f, 1f)
|
|
118
|
+
.apply {
|
|
119
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
120
|
+
@Suppress("WrongConstant")
|
|
121
|
+
setBreakStrategy(breakStrategy)
|
|
122
|
+
}
|
|
123
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
124
|
+
setUseLineSpacingFromFallbacks(true)
|
|
125
|
+
}
|
|
126
|
+
}.build()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private fun prepareImageSpansForMeasurement(
|
|
130
|
+
text: CharSequence?,
|
|
131
|
+
widthPx: Int,
|
|
132
|
+
) {
|
|
133
|
+
if (widthPx <= 1) return
|
|
134
|
+
val spanned = text as? android.text.Spanned ?: return
|
|
135
|
+
spanned
|
|
136
|
+
.getSpans(0, spanned.length, com.swmansion.enriched.markdown.spans.ImageSpan::class.java)
|
|
137
|
+
.forEach { it.prepareForMeasurement(spanned, widthPx) }
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package com.swmansion.enriched.markdown.
|
|
1
|
+
package com.swmansion.enriched.markdown.segments
|
|
2
2
|
|
|
3
3
|
import com.swmansion.enriched.markdown.parser.MarkdownASTNode
|
|
4
4
|
|
|
@@ -12,6 +12,8 @@ object SegmentSignature {
|
|
|
12
12
|
internal const val TABLE_KIND_SALT = 0x7461626C00000000L // "tabl"
|
|
13
13
|
internal const val MATH_KIND_SALT = 0x6D61746800000000L // "math"
|
|
14
14
|
internal const val CODE_BLOCK_KIND_SALT = 0x63626C6B00000000L // "cblk"
|
|
15
|
+
internal const val BLOCKQUOTE_KIND_SALT = 0x6271746500000000L // "bqte"
|
|
16
|
+
internal const val VIDEO_KIND_SALT = 0x7669646F00000000L // "video"
|
|
15
17
|
|
|
16
18
|
private fun fnvMixByte(
|
|
17
19
|
hash: Long,
|