react-native-enriched-markdown-scaffold 1.0.2-scaffold.8 → 1.2.0-scaffold.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReactNativeEnrichedMarkdown.podspec +31 -10
- package/android/build.gradle +51 -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 +718 -768
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownInternalText.kt +11 -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 +220 -7
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownTextManager.kt +65 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/MeasurementStore.kt +228 -29
- 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/HeadlessActionMode.kt +12 -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
package/android/src/main/java/com/swmansion/enriched/markdown/input/EnrichedMarkdownTextInputView.kt
CHANGED
|
@@ -10,6 +10,7 @@ import android.os.Build
|
|
|
10
10
|
import android.text.Editable
|
|
11
11
|
import android.text.InputType
|
|
12
12
|
import android.text.Layout
|
|
13
|
+
import android.util.Log
|
|
13
14
|
import android.util.TypedValue
|
|
14
15
|
import android.view.Gravity
|
|
15
16
|
import android.view.KeyEvent
|
|
@@ -40,6 +41,7 @@ import com.swmansion.enriched.markdown.input.editing.EditSession
|
|
|
40
41
|
import com.swmansion.enriched.markdown.input.editing.InputConnectionWrapper
|
|
41
42
|
import com.swmansion.enriched.markdown.input.editing.LinkCoordinator
|
|
42
43
|
import com.swmansion.enriched.markdown.input.editing.MarkdownEditableFactory
|
|
44
|
+
import com.swmansion.enriched.markdown.input.editing.MarkdownShortcutsConfig
|
|
43
45
|
import com.swmansion.enriched.markdown.input.editing.MarkdownTextWatcher
|
|
44
46
|
import com.swmansion.enriched.markdown.input.editing.MentionCoordinator
|
|
45
47
|
import com.swmansion.enriched.markdown.input.editing.MentionEvent
|
|
@@ -69,6 +71,8 @@ class EnrichedMarkdownTextInputView(
|
|
|
69
71
|
context: Context,
|
|
70
72
|
) : AppCompatEditText(context) {
|
|
71
73
|
private var isComponentReady = false
|
|
74
|
+
private var lastEmittedSelectionStart = -1
|
|
75
|
+
private var lastEmittedSelectionEnd = -1
|
|
72
76
|
|
|
73
77
|
val formattingStore = FormattingStore()
|
|
74
78
|
val blockStore = BlockStore()
|
|
@@ -116,6 +120,9 @@ class EnrichedMarkdownTextInputView(
|
|
|
116
120
|
override fun runAsATransaction(block: () -> Unit) = this@EnrichedMarkdownTextInputView.runAsATransaction(block)
|
|
117
121
|
|
|
118
122
|
override fun setViewSelection(position: Int) = setSelection(position)
|
|
123
|
+
|
|
124
|
+
override val markdownShortcuts: MarkdownShortcutsConfig
|
|
125
|
+
get() = this@EnrichedMarkdownTextInputView.markdownShortcuts
|
|
119
126
|
}
|
|
120
127
|
|
|
121
128
|
val editPipeline =
|
|
@@ -133,6 +140,9 @@ class EnrichedMarkdownTextInputView(
|
|
|
133
140
|
private var detectScrollMovement = false
|
|
134
141
|
var scrollEnabled: Boolean = true
|
|
135
142
|
|
|
143
|
+
/** Typed `# `, `- `, `1. ` become blocks (opt-in per family from JS). */
|
|
144
|
+
var markdownShortcuts: MarkdownShortcutsConfig = MarkdownShortcutsConfig()
|
|
145
|
+
|
|
136
146
|
private val clipboardCoordinator = ClipboardCoordinator(formattingStore, blockStore, detectorPipeline, formatter)
|
|
137
147
|
|
|
138
148
|
// region Math chip state
|
|
@@ -392,6 +402,28 @@ class EnrichedMarkdownTextInputView(
|
|
|
392
402
|
|
|
393
403
|
override fun performClick(): Boolean = super.performClick()
|
|
394
404
|
|
|
405
|
+
// Framework bug (issue #728): inside Editor.performLongClick, the guarded branch calls
|
|
406
|
+
// Selection.setSelection, whose SpanWatcher callback runs our onSelectionChanged override
|
|
407
|
+
// synchronously; that can re-run prepareCursorControllers and flip mInsertionControllerEnabled
|
|
408
|
+
// to false before the immediately following getInsertionController().show(), which then
|
|
409
|
+
// dereferences null. Absorb only that specific NPE (thrown from Editor.performLongClick) and
|
|
410
|
+
// rethrow anything else so unrelated regressions in our own callbacks aren't masked. We log it
|
|
411
|
+
// rather than swallowing silently (RN's ReactSoftExceptionLogger is internal to RN, so we use a
|
|
412
|
+
// plain warning under our own tag), and return true so the long press counts as handled (else
|
|
413
|
+
// View.CheckForLongPress leaves mHasPerformedLongPress unset and a spurious click fires on
|
|
414
|
+
// ACTION_UP); the long press just skips the insertion UI on that frame instead of crashing.
|
|
415
|
+
override fun performLongClick(): Boolean =
|
|
416
|
+
try {
|
|
417
|
+
super.performLongClick()
|
|
418
|
+
} catch (e: NullPointerException) {
|
|
419
|
+
val top = e.stackTrace.firstOrNull()
|
|
420
|
+
if (top == null || !top.className.startsWith("android.widget.Editor") || top.methodName != "performLongClick") {
|
|
421
|
+
throw e
|
|
422
|
+
}
|
|
423
|
+
Log.w(TAG, "Absorbed framework NPE in performLongClick (issue #728)", e)
|
|
424
|
+
true
|
|
425
|
+
}
|
|
426
|
+
|
|
395
427
|
// In auto-grow mode (scrollEnabled=false) TextView's internal bringPointIntoView
|
|
396
428
|
// scrolls content before Fabric has resized the view, causing a visible flicker.
|
|
397
429
|
override fun scrollTo(
|
|
@@ -463,6 +495,7 @@ class EnrichedMarkdownTextInputView(
|
|
|
463
495
|
} finally {
|
|
464
496
|
editSession.exit()
|
|
465
497
|
}
|
|
498
|
+
emitSelectionIfChanged()
|
|
466
499
|
}
|
|
467
500
|
|
|
468
501
|
override fun onSelectionChanged(
|
|
@@ -503,12 +536,34 @@ class EnrichedMarkdownTextInputView(
|
|
|
503
536
|
activeMathChipPosition = -1
|
|
504
537
|
}
|
|
505
538
|
|
|
506
|
-
|
|
539
|
+
// Deduplicated emit (#884) keeps lastEmittedSelection* in sync for every caller.
|
|
540
|
+
emitSelectionIfChanged()
|
|
507
541
|
dispatchMentionUpdate()
|
|
508
542
|
eventEmitter.emitState()
|
|
509
543
|
eventEmitter.emitCaretRectChangeIfNeeded()
|
|
510
544
|
}
|
|
511
545
|
|
|
546
|
+
/**
|
|
547
|
+
* Sends the caret range to JS when it differs from the last range JS received.
|
|
548
|
+
*
|
|
549
|
+
* [onSelectionChanged] returns immediately while an edit phase is active, so
|
|
550
|
+
* a caret move from setValue, a programmatic insert, or anchor management is
|
|
551
|
+
* not reported there. Those callers invoke this once the edit phase has ended.
|
|
552
|
+
*
|
|
553
|
+
* This function then rereads the latest range at that point before emitting
|
|
554
|
+
* the selection.
|
|
555
|
+
*/
|
|
556
|
+
private fun emitSelectionIfChanged() {
|
|
557
|
+
if (!isComponentReady) return
|
|
558
|
+
val start = selectionStart
|
|
559
|
+
val end = selectionEnd
|
|
560
|
+
if (start == lastEmittedSelectionStart && end == lastEmittedSelectionEnd) return
|
|
561
|
+
if (eventEmitter.emitSelection(start, end)) {
|
|
562
|
+
lastEmittedSelectionStart = start
|
|
563
|
+
lastEmittedSelectionEnd = end
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
512
567
|
/**
|
|
513
568
|
* Text typed over a non-empty selection inherits the inline styles of the first
|
|
514
569
|
* selected character (mirrors iOS rebuildFromContext and the range-inheritance
|
|
@@ -565,6 +620,7 @@ class EnrichedMarkdownTextInputView(
|
|
|
565
620
|
} finally {
|
|
566
621
|
editSession.exit()
|
|
567
622
|
}
|
|
623
|
+
emitSelectionIfChanged()
|
|
568
624
|
}
|
|
569
625
|
|
|
570
626
|
fun applyFormatting() {
|
|
@@ -796,11 +852,13 @@ class EnrichedMarkdownTextInputView(
|
|
|
796
852
|
// and block ranges survive the round trip — mirrors iOS's copy:/cut:/paste:
|
|
797
853
|
// overrides. External clips keep default handling.
|
|
798
854
|
//
|
|
799
|
-
// Paste arrives by
|
|
855
|
+
// Paste arrives by three different routes and only the first one is a menu.
|
|
800
856
|
// This override covers the context menu and the hardware Ctrl+V /
|
|
801
857
|
// KEYCODE_PASTE shortcuts; drag-and-drop, autofill and IME `commitContent`
|
|
802
|
-
// reach the view through `onReceiveContent` instead
|
|
803
|
-
//
|
|
858
|
+
// reach the view through `onReceiveContent` instead, and a keyboard
|
|
859
|
+
// clipboard chip commits the text through the input connection (see
|
|
860
|
+
// interceptImePaste). Hooking only some of them leaves the others pasting
|
|
861
|
+
// straight into the buffer with nobody intercepting.
|
|
804
862
|
override fun onTextContextMenuItem(id: Int): Boolean {
|
|
805
863
|
// Checked before the markdown paste below, which would otherwise insert first.
|
|
806
864
|
if (interceptPaste && (id == android.R.id.paste || id == android.R.id.pasteAsPlainText)) {
|
|
@@ -976,6 +1034,26 @@ class EnrichedMarkdownTextInputView(
|
|
|
976
1034
|
parts.second
|
|
977
1035
|
}
|
|
978
1036
|
|
|
1037
|
+
/**
|
|
1038
|
+
* Keyboard clipboard chips (Gboard, Samsung Keyboard) paste through
|
|
1039
|
+
* `InputConnection.commitText`, a route neither [onTextContextMenuItem] nor
|
|
1040
|
+
* the receive-content listener sees, so the text landed in the buffer with no
|
|
1041
|
+
* `onPaste`. A commit that equals the primary clip is treated as that paste
|
|
1042
|
+
* and reported like the other two routes; the IME commit is then dropped and
|
|
1043
|
+
* JS completes it through [resolvePaste].
|
|
1044
|
+
*
|
|
1045
|
+
* Short typing-sized commits are not compared, so the clipboard is not read
|
|
1046
|
+
* (and Android 12's clipboard toast not shown) while the user types; see
|
|
1047
|
+
* [PasteTextUtils.mayBeImePaste] and [PasteTextUtils.isImePaste].
|
|
1048
|
+
*/
|
|
1049
|
+
internal fun interceptImePaste(committed: String): Boolean {
|
|
1050
|
+
if (!interceptPaste || !PasteTextUtils.mayBeImePaste(committed)) return false
|
|
1051
|
+
val clip = readClipboardText()
|
|
1052
|
+
if (!PasteTextUtils.isImePaste(committed, clip)) return false
|
|
1053
|
+
eventEmitter.emitPaste(clip, "")
|
|
1054
|
+
return true
|
|
1055
|
+
}
|
|
1056
|
+
|
|
979
1057
|
private fun readClipboardText(): String {
|
|
980
1058
|
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager ?: return ""
|
|
981
1059
|
val clip = clipboard.primaryClip ?: return ""
|
|
@@ -1470,6 +1548,7 @@ class EnrichedMarkdownTextInputView(
|
|
|
1470
1548
|
} finally {
|
|
1471
1549
|
editSession.exit()
|
|
1472
1550
|
}
|
|
1551
|
+
emitSelectionIfChanged()
|
|
1473
1552
|
}
|
|
1474
1553
|
|
|
1475
1554
|
override fun setBackgroundColor(color: Int) {
|
|
@@ -1535,10 +1614,22 @@ class EnrichedMarkdownTextInputView(
|
|
|
1535
1614
|
AutoCapitalizeUtils.apply(this, flagName)
|
|
1536
1615
|
}
|
|
1537
1616
|
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1617
|
+
/**
|
|
1618
|
+
* Programmatic focus for ref.focus() and for the focus command that the JS
|
|
1619
|
+
* pressability onPress sends on finger-up (including after a long-press word
|
|
1620
|
+
* select).
|
|
1621
|
+
*
|
|
1622
|
+
* Matches ReactEditText.requestFocusProgrammatically: request focus and show
|
|
1623
|
+
* the keyboard without touching the selection, so a long-press word selection
|
|
1624
|
+
* isn't collapsed:
|
|
1625
|
+
* https://github.com/react/react-native/blob/v0.86.2/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.kt#L396-L402
|
|
1626
|
+
*/
|
|
1627
|
+
fun requestFocusProgrammatically(): Boolean {
|
|
1628
|
+
val focused = super.requestFocus(FOCUS_DOWN, null)
|
|
1629
|
+
if (isInTouchMode && showSoftInputOnFocus) {
|
|
1630
|
+
inputMethodManager?.showSoftInput(this, 0)
|
|
1631
|
+
}
|
|
1632
|
+
return focused
|
|
1542
1633
|
}
|
|
1543
1634
|
|
|
1544
1635
|
private fun showAutoFocusKeyboardIfPending() {
|
|
@@ -1597,7 +1688,8 @@ class EnrichedMarkdownTextInputView(
|
|
|
1597
1688
|
}
|
|
1598
1689
|
}
|
|
1599
1690
|
|
|
1600
|
-
|
|
1691
|
+
companion object {
|
|
1601
1692
|
private val PASTE_MIME_TYPES = arrayOf("text/*")
|
|
1693
|
+
private val TAG: String = EnrichedMarkdownTextInputView::class.java.simpleName
|
|
1602
1694
|
}
|
|
1603
1695
|
}
|
|
@@ -37,6 +37,9 @@ interface EditPipelineHost {
|
|
|
37
37
|
fun runAsATransaction(block: () -> Unit)
|
|
38
38
|
|
|
39
39
|
fun setViewSelection(position: Int)
|
|
40
|
+
|
|
41
|
+
/** Which typed markdown prefixes (`# `, `- `, `1. `) convert into blocks. */
|
|
42
|
+
val markdownShortcuts: MarkdownShortcutsConfig
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
/**
|
|
@@ -64,6 +67,7 @@ class EditPipeline(
|
|
|
64
67
|
adjustStores(context)
|
|
65
68
|
pruneOrphanedAnchors()
|
|
66
69
|
continueBlocks(context)
|
|
70
|
+
convertMarkdownShortcut(context)
|
|
67
71
|
host.editable?.let { blockStore.normalizeToLineBounds(it) }
|
|
68
72
|
applyPendingStyles(context)
|
|
69
73
|
|
|
@@ -148,6 +152,50 @@ class EditPipeline(
|
|
|
148
152
|
blockStore.setBlock(prevBlock.type, prevBlock.level, newLineStart, newLineStart, editable)
|
|
149
153
|
}
|
|
150
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Markdown shortcuts: a space typed after `#`…`######`, `-`/`*`/`+` or
|
|
157
|
+
* `1.`/`1)` at the start of a plain paragraph drops the prefix and makes the
|
|
158
|
+
* paragraph that block. Mirrors [continueBlocks]: mutate inside a transaction,
|
|
159
|
+
* then re-adjust the stores for the deletion before normalization stamps spans.
|
|
160
|
+
*/
|
|
161
|
+
private fun convertMarkdownShortcut(context: EditContext) {
|
|
162
|
+
val config = host.markdownShortcuts
|
|
163
|
+
if (!config.isEnabled) return
|
|
164
|
+
val editable = host.editable ?: return
|
|
165
|
+
if (context.deletedLength != 0 || context.insertedLength <= 0) return
|
|
166
|
+
|
|
167
|
+
// The trigger is the first space in the inserted run, and a line break ends
|
|
168
|
+
// the search so the converted line is always the one the insertion started
|
|
169
|
+
// on. The line start itself is scanned the way [BlockStore] bounds a
|
|
170
|
+
// paragraph, or the lookup below would miss the block.
|
|
171
|
+
val insertedEnd = (context.editStart + context.insertedLength).coerceAtMost(editable.length)
|
|
172
|
+
val spaceIndex =
|
|
173
|
+
(context.editStart until insertedEnd)
|
|
174
|
+
.asSequence()
|
|
175
|
+
.takeWhile { !editable[it].isLineBreak() }
|
|
176
|
+
.firstOrNull { editable[it] == ' ' } ?: return
|
|
177
|
+
|
|
178
|
+
var lineStart = spaceIndex
|
|
179
|
+
while (lineStart > 0 && editable[lineStart - 1] != '\n') lineStart--
|
|
180
|
+
if (spaceIndex == lineStart || blockStore.blockStartingAt(lineStart) != null) return
|
|
181
|
+
|
|
182
|
+
val match =
|
|
183
|
+
MarkdownShortcutMatcher.match(
|
|
184
|
+
editable.subSequence(lineStart, spaceIndex),
|
|
185
|
+
config,
|
|
186
|
+
) ?: return
|
|
187
|
+
|
|
188
|
+
val deleteEnd = spaceIndex + 1
|
|
189
|
+
val deletedLength = deleteEnd - lineStart
|
|
190
|
+
host.runAsATransaction { editable.delete(lineStart, deleteEnd) }
|
|
191
|
+
formattingStore.adjustForEdit(lineStart, deletedLength, 0)
|
|
192
|
+
blockStore.adjustForEdit(lineStart, deletedLength, 0)
|
|
193
|
+
blockStore.setBlock(match.type, match.level, lineStart, lineStart, editable)
|
|
194
|
+
|
|
195
|
+
val caret = (context.editStart + context.insertedLength - deletedLength).coerceIn(0, editable.length)
|
|
196
|
+
host.setViewSelection(caret)
|
|
197
|
+
}
|
|
198
|
+
|
|
151
199
|
private fun applyPendingStyles(context: EditContext) {
|
|
152
200
|
if (context.insertedLength == 0) return
|
|
153
201
|
if (context.pendingStyles.isEmpty() && context.pendingStyleRemovals.isEmpty()) return
|
|
@@ -106,6 +106,13 @@ class InputConnectionWrapper(
|
|
|
106
106
|
if (key.length <= 2) {
|
|
107
107
|
dispatchKeyPressOrEnqueue(key.ifEmpty { BACKSPACE_KEY_VALUE })
|
|
108
108
|
}
|
|
109
|
+
// A keyboard clipboard chip pastes here. When the view claims it as a
|
|
110
|
+
// paste, the commit is dropped; the composing region is closed first so the
|
|
111
|
+
// word being typed stays in the buffer instead of being replaced.
|
|
112
|
+
if (editText.interceptImePaste(key)) {
|
|
113
|
+
super.finishComposingText()
|
|
114
|
+
return true
|
|
115
|
+
}
|
|
109
116
|
return super.commitText(text, newCursorPosition)
|
|
110
117
|
}
|
|
111
118
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
package com.swmansion.enriched.markdown.input.editing
|
|
2
|
+
|
|
3
|
+
import com.swmansion.enriched.markdown.input.model.BlockType
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Which shortcut families are enabled, normalized on the JS side so native
|
|
7
|
+
* never sees the public `boolean | MarkdownShortcutsConfig` union.
|
|
8
|
+
*/
|
|
9
|
+
data class MarkdownShortcutsConfig(
|
|
10
|
+
val heading: Boolean = false,
|
|
11
|
+
val unorderedList: Boolean = false,
|
|
12
|
+
val orderedList: Boolean = false,
|
|
13
|
+
) {
|
|
14
|
+
val isEnabled: Boolean
|
|
15
|
+
get() = heading || unorderedList || orderedList
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Recognizes the markdown block prefixes a user types at the start of a
|
|
20
|
+
* paragraph — `#`…`######`, `-`/`*`/`+`, `1.`/`1)` — so the input can turn the
|
|
21
|
+
* paragraph into the matching block and drop the prefix (Notion-style markdown
|
|
22
|
+
* shortcuts). Pure text matching; the caller owns the mutation.
|
|
23
|
+
*/
|
|
24
|
+
internal object MarkdownShortcutMatcher {
|
|
25
|
+
data class Match(
|
|
26
|
+
val type: BlockType,
|
|
27
|
+
val level: Int,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
/** Anything longer is a number the user is writing, not a list marker. */
|
|
31
|
+
private const val MAX_ORDERED_MARKER_DIGITS = 9
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Matches [prefix] (the paragraph text before the space the user just typed,
|
|
35
|
+
* with no leading whitespace) against the families [config] enables. Ordered
|
|
36
|
+
* items match any number — the block store renumbers ordinals, so `3.` on a
|
|
37
|
+
* fresh line still starts at 1.
|
|
38
|
+
*/
|
|
39
|
+
fun match(
|
|
40
|
+
prefix: CharSequence,
|
|
41
|
+
config: MarkdownShortcutsConfig,
|
|
42
|
+
): Match? {
|
|
43
|
+
if (prefix.isEmpty()) return null
|
|
44
|
+
val first = prefix[0]
|
|
45
|
+
|
|
46
|
+
if (first == '#') {
|
|
47
|
+
if (!config.heading || prefix.length > 6 || !prefix.all { it == '#' }) return null
|
|
48
|
+
val type = BlockType.forHeadingLevel(prefix.length) ?: return null
|
|
49
|
+
return Match(type, prefix.length)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (prefix.length == 1 && first in "-*+") {
|
|
53
|
+
return if (config.unorderedList) Match(BlockType.UNORDERED_LIST_ITEM, 0) else null
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
val last = prefix.last()
|
|
57
|
+
if ((last == '.' || last == ')') && prefix.length >= 2 && prefix.length - 1 <= MAX_ORDERED_MARKER_DIGITS) {
|
|
58
|
+
if (prefix.subSequence(0, prefix.length - 1).all { it in '0'..'9' }) {
|
|
59
|
+
return if (config.orderedList) Match(BlockType.ORDERED_LIST_ITEM, 0) else null
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return null
|
|
63
|
+
}
|
|
64
|
+
}
|
package/android/src/main/java/com/swmansion/enriched/markdown/input/formatting/InputRemend.kt
CHANGED
|
@@ -5,15 +5,18 @@ object InputRemend {
|
|
|
5
5
|
val open: String,
|
|
6
6
|
val close: String,
|
|
7
7
|
val symmetric: Boolean,
|
|
8
|
+
// Emphasis-family delimiters (*, _, ~~) only open when left-flanking; code spans
|
|
9
|
+
// and spoilers open regardless of surrounding whitespace, so they skip the check.
|
|
10
|
+
val flanking: Boolean = false,
|
|
8
11
|
)
|
|
9
12
|
|
|
10
13
|
private val DELIMITER_PAIRS =
|
|
11
14
|
arrayOf(
|
|
12
|
-
DelimiterPair("***", "***", true),
|
|
13
|
-
DelimiterPair("**", "**", true),
|
|
14
|
-
DelimiterPair("*", "*", true),
|
|
15
|
-
DelimiterPair("_", "_", true),
|
|
16
|
-
DelimiterPair("~~", "~~", true),
|
|
15
|
+
DelimiterPair("***", "***", true, flanking = true),
|
|
16
|
+
DelimiterPair("**", "**", true, flanking = true),
|
|
17
|
+
DelimiterPair("*", "*", true, flanking = true),
|
|
18
|
+
DelimiterPair("_", "_", true, flanking = true),
|
|
19
|
+
DelimiterPair("~~", "~~", true, flanking = true),
|
|
17
20
|
DelimiterPair("||", "||", true),
|
|
18
21
|
DelimiterPair("`", "`", true),
|
|
19
22
|
DelimiterPair("[", "]", false),
|
|
@@ -68,7 +71,7 @@ object InputRemend {
|
|
|
68
71
|
if (substring == pair.open) {
|
|
69
72
|
if (stack.isNotEmpty() && stack.last() == pair.open) {
|
|
70
73
|
stack.removeAt(stack.lastIndex)
|
|
71
|
-
} else {
|
|
74
|
+
} else if (!pair.flanking || isEmphasisOpener(markdown, i, pair.open)) {
|
|
72
75
|
stack.add(pair.open)
|
|
73
76
|
}
|
|
74
77
|
i += openLen
|
|
@@ -118,4 +121,39 @@ object InputRemend {
|
|
|
118
121
|
}
|
|
119
122
|
|
|
120
123
|
private fun closingFor(entry: String): String = DELIMITER_PAIRS.firstOrNull { it.open == entry }?.close ?: entry
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Mirrors md4c's emphasis opener test so completion only closes a delimiter md4c
|
|
127
|
+
* would actually treat as an opener: the run is a potential opener when its right
|
|
128
|
+
* side is "stronger" than its left (rightLevel > 0 and rightLevel >= leftLevel),
|
|
129
|
+
* where each side is scored 0 = whitespace/boundary, 1 = punctuation, 2 = other.
|
|
130
|
+
* Intraword underscore (both sides "other") never opens. This rejects lone or
|
|
131
|
+
* whitespace/punctuation-flanked delimiters (`control*`, `2 * 3`, `a*.`, `a_b`)
|
|
132
|
+
* that would otherwise fabricate a marker. Intraword `*` (`a*b`) is a genuine md4c
|
|
133
|
+
* opener, so it is not (and cannot be) rejected here.
|
|
134
|
+
*/
|
|
135
|
+
private fun isEmphasisOpener(
|
|
136
|
+
markdown: String,
|
|
137
|
+
start: Int,
|
|
138
|
+
open: String,
|
|
139
|
+
): Boolean {
|
|
140
|
+
val leftLevel = flankingLevelAt(markdown, start - 1)
|
|
141
|
+
val rightLevel = flankingLevelAt(markdown, start + open.length)
|
|
142
|
+
if (open == "_" && leftLevel == 2 && rightLevel == 2) return false
|
|
143
|
+
return rightLevel > 0 && rightLevel >= leftLevel
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** 0 = whitespace or out-of-bounds boundary, 1 = punctuation, 2 = letter/digit. */
|
|
147
|
+
private fun flankingLevelAt(
|
|
148
|
+
markdown: String,
|
|
149
|
+
index: Int,
|
|
150
|
+
): Int {
|
|
151
|
+
if (index !in markdown.indices) return 0
|
|
152
|
+
val c = markdown[index]
|
|
153
|
+
return when {
|
|
154
|
+
c.isWhitespace() -> 0
|
|
155
|
+
c.isLetterOrDigit() -> 2
|
|
156
|
+
else -> 1
|
|
157
|
+
}
|
|
158
|
+
}
|
|
121
159
|
}
|
package/android/src/main/java/com/swmansion/enriched/markdown/input/layout/InputEventEmitter.kt
CHANGED
|
@@ -59,9 +59,7 @@ class InputEventEmitter(
|
|
|
59
59
|
fun emitSelection(
|
|
60
60
|
start: Int,
|
|
61
61
|
end: Int,
|
|
62
|
-
)
|
|
63
|
-
dispatch(OnChangeSelectionEvent(surfaceId(), view.id, start, end))
|
|
64
|
-
}
|
|
62
|
+
): Boolean = dispatch(OnChangeSelectionEvent(surfaceId(), view.id, start, end))
|
|
65
63
|
|
|
66
64
|
fun emitState() {
|
|
67
65
|
val pos = view.selectionStart
|
|
@@ -268,10 +266,13 @@ class InputEventEmitter(
|
|
|
268
266
|
return UIManagerHelper.getSurfaceId(reactContext)
|
|
269
267
|
}
|
|
270
268
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
val
|
|
275
|
-
dispatcher
|
|
269
|
+
/** Returns true when [event] was handed to the React event dispatcher */
|
|
270
|
+
private fun dispatch(event: Event<*>): Boolean {
|
|
271
|
+
if (view.editSession.shouldSuppressEvents) return false
|
|
272
|
+
val reactContext = view.context as? ReactContext ?: return false
|
|
273
|
+
val dispatcher =
|
|
274
|
+
UIManagerHelper.getEventDispatcherForReactTag(reactContext, view.id) ?: return false
|
|
275
|
+
dispatcher.dispatchEvent(event)
|
|
276
|
+
return true
|
|
276
277
|
}
|
|
277
278
|
}
|
|
@@ -38,6 +38,9 @@ data class MarkdownASTNode(
|
|
|
38
38
|
Subscript,
|
|
39
39
|
Highlight,
|
|
40
40
|
SoftBreak,
|
|
41
|
+
BlankLine,
|
|
42
|
+
Admonition,
|
|
43
|
+
Video,
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
fun getAttribute(key: String): String? = attributes[key]
|
|
@@ -49,12 +52,15 @@ internal fun MarkdownASTNode.NodeType.isTopLevelBlock(): Boolean =
|
|
|
49
52
|
MarkdownASTNode.NodeType.Paragraph,
|
|
50
53
|
MarkdownASTNode.NodeType.Heading,
|
|
51
54
|
MarkdownASTNode.NodeType.Blockquote,
|
|
55
|
+
MarkdownASTNode.NodeType.Admonition,
|
|
52
56
|
MarkdownASTNode.NodeType.UnorderedList,
|
|
53
57
|
MarkdownASTNode.NodeType.OrderedList,
|
|
54
58
|
MarkdownASTNode.NodeType.CodeBlock,
|
|
55
59
|
MarkdownASTNode.NodeType.ThematicBreak,
|
|
60
|
+
MarkdownASTNode.NodeType.BlankLine,
|
|
56
61
|
MarkdownASTNode.NodeType.Table,
|
|
57
62
|
MarkdownASTNode.NodeType.LatexMathDisplay,
|
|
63
|
+
MarkdownASTNode.NodeType.Video,
|
|
58
64
|
-> true
|
|
59
65
|
|
|
60
66
|
else -> false
|
|
@@ -11,6 +11,8 @@ data class Md4cFlags(
|
|
|
11
11
|
val highlight: Boolean = false,
|
|
12
12
|
val permissiveAutolinks: Boolean = true,
|
|
13
13
|
val hardSoftBreaks: Boolean = false,
|
|
14
|
+
val preserveBlankLines: Boolean = false,
|
|
15
|
+
val admonitions: Boolean = true,
|
|
14
16
|
) {
|
|
15
17
|
companion object {
|
|
16
18
|
val DEFAULT = Md4cFlags()
|
|
@@ -35,6 +37,7 @@ class Parser {
|
|
|
35
37
|
private external fun nativeParseMarkdown(
|
|
36
38
|
markdown: String,
|
|
37
39
|
flags: Md4cFlags,
|
|
40
|
+
isGFM: Boolean,
|
|
38
41
|
): MarkdownASTNode?
|
|
39
42
|
|
|
40
43
|
/**
|
|
@@ -47,13 +50,14 @@ class Parser {
|
|
|
47
50
|
fun parseMarkdown(
|
|
48
51
|
markdown: String,
|
|
49
52
|
flags: Md4cFlags = Md4cFlags.DEFAULT,
|
|
53
|
+
isGFM: Boolean = true,
|
|
50
54
|
): MarkdownASTNode? {
|
|
51
55
|
if (markdown.isBlank()) {
|
|
52
56
|
return null
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
try {
|
|
56
|
-
val ast = nativeParseMarkdown(markdown, flags)
|
|
60
|
+
val ast = nativeParseMarkdown(markdown, flags, isGFM)
|
|
57
61
|
|
|
58
62
|
if (ast != null) {
|
|
59
63
|
return ast
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
package com.swmansion.enriched.markdown.renderer
|
|
2
|
+
|
|
3
|
+
import android.text.SpannableStringBuilder
|
|
4
|
+
import com.swmansion.enriched.markdown.parser.MarkdownASTNode
|
|
5
|
+
import com.swmansion.enriched.markdown.utils.text.span.applyLineHeightSkippingImages
|
|
6
|
+
|
|
7
|
+
// Renders a run of consecutive blank lines emitted when preserveBlankLines is
|
|
8
|
+
// enabled. Each blank line in the source is drawn as one empty line, using the
|
|
9
|
+
// paragraph line height so its vertical rhythm matches the surrounding
|
|
10
|
+
// paragraphs. Any extra block spacing comes from the paragraph style and is left
|
|
11
|
+
// to the caller to configure.
|
|
12
|
+
class BlankLineRenderer(
|
|
13
|
+
private val config: RendererConfig,
|
|
14
|
+
) : NodeRenderer {
|
|
15
|
+
override fun render(
|
|
16
|
+
node: MarkdownASTNode,
|
|
17
|
+
builder: SpannableStringBuilder,
|
|
18
|
+
onLinkPress: ((String) -> Unit)?,
|
|
19
|
+
onLinkLongPress: ((String) -> Unit)?,
|
|
20
|
+
factory: RendererFactory,
|
|
21
|
+
) {
|
|
22
|
+
val count = node.getAttribute("count")?.toIntOrNull() ?: 0
|
|
23
|
+
if (count <= 0) {
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
builder.ensureNewline()
|
|
28
|
+
val start = builder.length
|
|
29
|
+
builder.append("\n".repeat(count))
|
|
30
|
+
applyLineHeightSkippingImages(builder, start, builder.length, config.style.paragraphStyle.lineHeight)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private fun SpannableStringBuilder.ensureNewline() {
|
|
34
|
+
if (isNotEmpty() && this[length - 1] != '\n') {
|
|
35
|
+
append('\n')
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -103,8 +103,6 @@ class BlockStyleContext {
|
|
|
103
103
|
|
|
104
104
|
fun setCodeBlockStyle(style: CodeBlockStyle) = pushBlockStyle(BlockType.CODE_BLOCK, style)
|
|
105
105
|
|
|
106
|
-
fun isInsideBlockElement(): Boolean = blockquoteDepth > 0 || listDepth > 0
|
|
107
|
-
|
|
108
106
|
fun incrementListItemNumber() {
|
|
109
107
|
listItemNumber++
|
|
110
108
|
}
|
|
@@ -143,6 +141,8 @@ class BlockStyleContext {
|
|
|
143
141
|
)
|
|
144
142
|
}
|
|
145
143
|
|
|
144
|
+
fun currentBlockStyleOrNull(): BlockStyle? = blockStyleStack.lastOrNull()?.blockStyle
|
|
145
|
+
|
|
146
146
|
fun resetForNewRender() {
|
|
147
147
|
blockStyleStack.clear()
|
|
148
148
|
currentBlockType = BlockType.NONE
|
package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockquoteRenderer.kt
CHANGED
|
@@ -8,6 +8,7 @@ import com.swmansion.enriched.markdown.parser.MarkdownASTNode
|
|
|
8
8
|
import com.swmansion.enriched.markdown.spans.BlockquoteSpan
|
|
9
9
|
import com.swmansion.enriched.markdown.utils.text.span.SPAN_FLAGS_CONTAINER_BACKGROUND
|
|
10
10
|
import com.swmansion.enriched.markdown.utils.text.span.SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE
|
|
11
|
+
import com.swmansion.enriched.markdown.utils.text.span.SPAN_FLAGS_LINE_HEIGHT_PRIORITY
|
|
11
12
|
import com.swmansion.enriched.markdown.utils.text.span.applyLineHeightSkippingImages
|
|
12
13
|
import com.swmansion.enriched.markdown.utils.text.span.applyMarginBottom
|
|
13
14
|
import com.swmansion.enriched.markdown.utils.text.span.applyMarginTop
|
|
@@ -164,12 +165,12 @@ class BlockquoteRenderer(
|
|
|
164
165
|
var currentPos = start
|
|
165
166
|
for ((nestedStart, nestedEnd) in nestedRanges) {
|
|
166
167
|
if (currentPos < nestedStart) {
|
|
167
|
-
applyLineHeightSkippingImages(builder, currentPos, nestedStart, lineHeight)
|
|
168
|
+
applyLineHeightSkippingImages(builder, currentPos, nestedStart, lineHeight, SPAN_FLAGS_LINE_HEIGHT_PRIORITY)
|
|
168
169
|
}
|
|
169
170
|
currentPos = nestedEnd
|
|
170
171
|
}
|
|
171
172
|
if (currentPos < end) {
|
|
172
|
-
applyLineHeightSkippingImages(builder, currentPos, end, lineHeight)
|
|
173
|
+
applyLineHeightSkippingImages(builder, currentPos, end, lineHeight, SPAN_FLAGS_LINE_HEIGHT_PRIORITY)
|
|
173
174
|
}
|
|
174
175
|
}
|
|
175
176
|
}
|
package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockquoteTextRenderer.kt
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
package com.swmansion.enriched.markdown.renderer
|
|
2
|
+
|
|
3
|
+
import android.text.SpannableStringBuilder
|
|
4
|
+
import com.swmansion.enriched.markdown.parser.MarkdownASTNode
|
|
5
|
+
import com.swmansion.enriched.markdown.styles.BlockquoteStyle
|
|
6
|
+
import com.swmansion.enriched.markdown.utils.text.span.SPAN_FLAGS_LINE_HEIGHT_PRIORITY
|
|
7
|
+
import com.swmansion.enriched.markdown.utils.text.span.applyLineHeightSkippingImages
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Renders a GFM blockquote's own prose content - the nodes left after nested
|
|
11
|
+
* quotes, code blocks and other block segments have been split out - into a
|
|
12
|
+
* standalone buffer styled as blockquote text.
|
|
13
|
+
*
|
|
14
|
+
* It decorates a generic [Renderer.renderContent] pass rather than owning the
|
|
15
|
+
* render envelope itself: [push] enters the blockquote block style so text picks
|
|
16
|
+
* up the quote's font/color while still emitting block margins between children,
|
|
17
|
+
* matching the commonmark BlockquoteRenderer; [postProcess] applies the quote's
|
|
18
|
+
* line height once the builder is complete. It draws no border/background/padding
|
|
19
|
+
* - the BlockquoteContainerView draws the box.
|
|
20
|
+
*/
|
|
21
|
+
class BlockquoteTextRenderer(
|
|
22
|
+
private val style: BlockquoteStyle,
|
|
23
|
+
) {
|
|
24
|
+
fun render(
|
|
25
|
+
renderer: Renderer,
|
|
26
|
+
nodes: List<MarkdownASTNode>,
|
|
27
|
+
onLinkPress: ((String) -> Unit)?,
|
|
28
|
+
onLinkLongPress: ((String) -> Unit)?,
|
|
29
|
+
): SpannableStringBuilder = renderer.renderContent(nodes, onLinkPress, onLinkLongPress, block = this)
|
|
30
|
+
|
|
31
|
+
fun push(context: BlockStyleContext) {
|
|
32
|
+
context.blockquoteDepth += 1
|
|
33
|
+
context.setBlockquoteStyle(style)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
fun pop(context: BlockStyleContext) {
|
|
37
|
+
context.popBlockStyle()
|
|
38
|
+
context.blockquoteDepth -= 1
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fun postProcess(builder: SpannableStringBuilder) {
|
|
42
|
+
if (builder.isNotEmpty()) {
|
|
43
|
+
// Priority flag so this block-wide line height iterates before the per-block
|
|
44
|
+
// MarginBottomSpans, which then add their gap on top instead of being
|
|
45
|
+
// normalized away (see SPAN_FLAGS_LINE_HEIGHT_PRIORITY).
|
|
46
|
+
applyLineHeightSkippingImages(
|
|
47
|
+
builder,
|
|
48
|
+
0,
|
|
49
|
+
builder.length,
|
|
50
|
+
style.lineHeight,
|
|
51
|
+
SPAN_FLAGS_LINE_HEIGHT_PRIORITY,
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|