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
|
@@ -11,6 +11,54 @@
|
|
|
11
11
|
#import "ENRMUnderlineStyleHandler.h"
|
|
12
12
|
#import "ENRMUnorderedListBlockHandler.h"
|
|
13
13
|
|
|
14
|
+
/// Sets `key` to `value` only on sub-runs whose value differs, recording each
|
|
15
|
+
/// written range in `changed` so the caller can invalidate just what changed.
|
|
16
|
+
static void ENRMSetAttributeIfChanged(NSMutableAttributedString *storage, NSAttributedStringKey key, id value,
|
|
17
|
+
NSRange range, NSMutableIndexSet *changed)
|
|
18
|
+
{
|
|
19
|
+
if (range.length == 0) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
NSMutableArray<NSValue *> *rangesToSet = [NSMutableArray array];
|
|
23
|
+
[storage enumerateAttribute:key
|
|
24
|
+
inRange:range
|
|
25
|
+
options:0
|
|
26
|
+
usingBlock:^(id current, NSRange subRange, BOOL *stop) {
|
|
27
|
+
BOOL equal = (current == value) || (current != nil && [current isEqual:value]);
|
|
28
|
+
if (!equal) {
|
|
29
|
+
[rangesToSet addObject:[NSValue valueWithRange:subRange]];
|
|
30
|
+
}
|
|
31
|
+
}];
|
|
32
|
+
for (NSValue *rangeValue in rangesToSet) {
|
|
33
|
+
NSRange subRange = rangeValue.rangeValue;
|
|
34
|
+
[storage addAttribute:key value:value range:subRange];
|
|
35
|
+
[changed addIndexesInRange:subRange];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/// Removes `key` only where present, recording cleared ranges in `changed`.
|
|
40
|
+
static void ENRMRemoveAttributeIfPresent(NSMutableAttributedString *storage, NSAttributedStringKey key, NSRange range,
|
|
41
|
+
NSMutableIndexSet *changed)
|
|
42
|
+
{
|
|
43
|
+
if (range.length == 0) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
NSMutableArray<NSValue *> *rangesToClear = [NSMutableArray array];
|
|
47
|
+
[storage enumerateAttribute:key
|
|
48
|
+
inRange:range
|
|
49
|
+
options:0
|
|
50
|
+
usingBlock:^(id current, NSRange subRange, BOOL *stop) {
|
|
51
|
+
if (current != nil) {
|
|
52
|
+
[rangesToClear addObject:[NSValue valueWithRange:subRange]];
|
|
53
|
+
}
|
|
54
|
+
}];
|
|
55
|
+
for (NSValue *rangeValue in rangesToClear) {
|
|
56
|
+
NSRange subRange = rangeValue.rangeValue;
|
|
57
|
+
[storage removeAttribute:key range:subRange];
|
|
58
|
+
[changed addIndexesInRange:subRange];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
14
62
|
@implementation ENRMInputFormatter {
|
|
15
63
|
NSDictionary<NSNumber *, id<ENRMStyleHandler>> *_styleHandlers;
|
|
16
64
|
NSDictionary<NSNumber *, id<ENRMBlockHandler>> *_blockHandlers;
|
|
@@ -85,13 +133,17 @@
|
|
|
85
133
|
NSRange scopeRange = NSMakeRange(scopeStart, scopeEnd - scopeStart);
|
|
86
134
|
NSUInteger scopeLength = scopeRange.length;
|
|
87
135
|
|
|
136
|
+
// Diff every write and invalidate only what changed, so unchanged content in
|
|
137
|
+
// scope (e.g. a table below a plain-paragraph edit) is not re-laid out (#739).
|
|
138
|
+
NSMutableIndexSet *changed = [NSMutableIndexSet indexSet];
|
|
139
|
+
|
|
88
140
|
[textStorage beginEditing];
|
|
89
141
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
142
|
+
// Reset to base; fonts are resolved per trait run below.
|
|
143
|
+
ENRMSetAttributeIfChanged(textStorage, NSForegroundColorAttributeName, style.baseTextColor, scopeRange, changed);
|
|
144
|
+
ENRMRemoveAttributeIfPresent(textStorage, NSUnderlineStyleAttributeName, scopeRange, changed);
|
|
145
|
+
ENRMRemoveAttributeIfPresent(textStorage, NSStrikethroughStyleAttributeName, scopeRange, changed);
|
|
146
|
+
ENRMRemoveAttributeIfPresent(textStorage, NSBackgroundColorAttributeName, scopeRange, changed);
|
|
95
147
|
|
|
96
148
|
UIFontDescriptorSymbolicTraits *traitMap =
|
|
97
149
|
(UIFontDescriptorSymbolicTraits *)calloc(scopeLength, sizeof(UIFontDescriptorSymbolicTraits));
|
|
@@ -126,21 +178,21 @@
|
|
|
126
178
|
}
|
|
127
179
|
}
|
|
128
180
|
|
|
181
|
+
// Handler writes are not diffed; mark the styled run changed to keep its invalidation.
|
|
129
182
|
[handler applyNonFontAttributesToTextStorage:textStorage range:clipped formattingRange:formattingRange style:style];
|
|
183
|
+
[changed addIndexesInRange:clipped];
|
|
130
184
|
}
|
|
131
185
|
|
|
186
|
+
// Resolve the final font per trait run (base or styled), diffed.
|
|
132
187
|
NSUInteger runStart = 0;
|
|
133
188
|
UIFontDescriptorSymbolicTraits currentTraits = traitMap[0];
|
|
134
189
|
|
|
135
190
|
for (NSUInteger i = 1; i <= scopeLength; i++) {
|
|
136
191
|
UIFontDescriptorSymbolicTraits nextTraits = (i < scopeLength) ? traitMap[i] : ~currentTraits;
|
|
137
192
|
if (nextTraits != currentTraits) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
value:font
|
|
142
|
-
range:NSMakeRange(scopeStart + runStart, i - runStart)];
|
|
143
|
-
}
|
|
193
|
+
UIFont *font = (currentTraits != 0) ? [style fontForTraits:currentTraits] : style.baseFont;
|
|
194
|
+
ENRMSetAttributeIfChanged(textStorage, NSFontAttributeName, font,
|
|
195
|
+
NSMakeRange(scopeStart + runStart, i - runStart), changed);
|
|
144
196
|
runStart = i;
|
|
145
197
|
currentTraits = (i < scopeLength) ? traitMap[i] : 0;
|
|
146
198
|
}
|
|
@@ -152,7 +204,11 @@
|
|
|
152
204
|
|
|
153
205
|
NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject;
|
|
154
206
|
if (layoutManager) {
|
|
155
|
-
|
|
207
|
+
// Invalidate only changed ranges; ensureLayout over the scope only realizes
|
|
208
|
+
// already-dirty runs, so the inserted line still lays out.
|
|
209
|
+
[changed enumerateRangesUsingBlock:^(NSRange changedRange, BOOL *stop) {
|
|
210
|
+
[layoutManager invalidateLayoutForCharacterRange:changedRange actualCharacterRange:NULL];
|
|
211
|
+
}];
|
|
156
212
|
[layoutManager ensureLayoutForCharacterRange:scopeRange];
|
|
157
213
|
}
|
|
158
214
|
|
|
@@ -135,8 +135,15 @@
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
NSString *weightString = _headingFontWeights[level];
|
|
138
|
-
UIFont *font
|
|
139
|
-
|
|
138
|
+
UIFont *font;
|
|
139
|
+
if (weightString.length > 0) {
|
|
140
|
+
UIFontWeight weight = ENRMFontWeightFromString(weightString);
|
|
141
|
+
UIFontDescriptor *descriptor = [_baseFont.fontDescriptor
|
|
142
|
+
fontDescriptorByAddingAttributes:@{UIFontDescriptorTraitsAttribute : @{UIFontWeightTrait : @(weight)}}];
|
|
143
|
+
font = descriptor ? [UIFont fontWithDescriptor:descriptor size:size] : [UIFont systemFontOfSize:size weight:weight];
|
|
144
|
+
} else {
|
|
145
|
+
font = [_baseFont fontWithSize:size];
|
|
146
|
+
}
|
|
140
147
|
_headingFontCache[level] = font;
|
|
141
148
|
return font;
|
|
142
149
|
}
|
|
@@ -143,6 +143,9 @@ struct ParseContext {
|
|
|
143
143
|
std::vector<MathSpanInfo> openMathStack;
|
|
144
144
|
std::vector<MathSpanInfo> resolvedMath;
|
|
145
145
|
std::vector<size_t> textStartOffsets;
|
|
146
|
+
// Byte offsets of backslashes md4c resolved as escape sequences (the '\' of "\*"),
|
|
147
|
+
// stripped from the plain text alongside inline/block delimiters.
|
|
148
|
+
std::vector<size_t> escapeByteOffsets;
|
|
146
149
|
size_t lastTextEnd = 0;
|
|
147
150
|
// Open list containers, innermost last (true = ordered). An item's depth is
|
|
148
151
|
// the stack size - 1 and its type the innermost container's; md4c carries no
|
|
@@ -421,6 +424,10 @@ static int onText(MD_TEXTTYPE, const MD_CHAR *text, MD_SIZE size, void *userdata
|
|
|
421
424
|
size_t textEnd = textStart + size;
|
|
422
425
|
context->textStartOffsets.push_back(textStart);
|
|
423
426
|
|
|
427
|
+
if (textStart > 0 && context->buffer[textStart - 1] == '\\' && (textStart - 1) >= context->lastTextEnd) {
|
|
428
|
+
context->escapeByteOffsets.push_back(textStart - 1);
|
|
429
|
+
}
|
|
430
|
+
|
|
424
431
|
for (auto &openSpan : context->openStack) {
|
|
425
432
|
if (openSpan.contentStartByteOffset == kByteOffsetUnset) {
|
|
426
433
|
openSpan.contentStartByteOffset = textStart;
|
|
@@ -733,11 +740,20 @@ static std::vector<MathChip> mathChipsFromContext(const ParseContext &context, c
|
|
|
733
740
|
NSArray<ENRMInputStyledRange *> *styledRanges = @[];
|
|
734
741
|
NSArray<ENRMBlockRange *> *rawBlockRanges = @[];
|
|
735
742
|
std::vector<MathChip> mathChips;
|
|
743
|
+
// Upstream #798 (merge decision D2): backslash escapes are stripped from the plain text, matching
|
|
744
|
+
// Android. Escapes are not re-emitted by the serializer, so `\$x\$` does not round-trip (known issue).
|
|
745
|
+
NSMutableIndexSet *escapeIndexes = [NSMutableIndexSet indexSet];
|
|
736
746
|
if (runMd4cParse(markdown, context, remend)) {
|
|
737
747
|
auto byteMap = buildByteToUTF16Map(context.buffer, context.bufferLength);
|
|
738
748
|
styledRanges = styledRangesFromContext(context, byteMap);
|
|
739
749
|
rawBlockRanges = blockRangesFromContext(context, byteMap, markdown);
|
|
740
750
|
mathChips = mathChipsFromContext(context, byteMap, rawLength);
|
|
751
|
+
for (size_t escapeByte : context.escapeByteOffsets) {
|
|
752
|
+
NSUInteger escapeIndex = mapByteOffset(byteMap, escapeByte, context.bufferLength);
|
|
753
|
+
if (escapeIndex < rawLength) {
|
|
754
|
+
[escapeIndexes addIndex:escapeIndex];
|
|
755
|
+
}
|
|
756
|
+
}
|
|
741
757
|
}
|
|
742
758
|
|
|
743
759
|
NSMutableIndexSet *syntaxIndexes = [NSMutableIndexSet indexSet];
|
|
@@ -775,6 +791,8 @@ static std::vector<MathChip> mathChipsFromContext(const ParseContext &context, c
|
|
|
775
791
|
}
|
|
776
792
|
}
|
|
777
793
|
|
|
794
|
+
[syntaxIndexes addIndexes:escapeIndexes];
|
|
795
|
+
|
|
778
796
|
// Strip \n/\r from syntax ranges — newlines are structural content, not
|
|
779
797
|
// markdown syntax, and must survive into the plain text.
|
|
780
798
|
NSMutableIndexSet *newlineIndexes = [NSMutableIndexSet indexSet];
|
|
@@ -4,11 +4,14 @@ typedef struct {
|
|
|
4
4
|
NSString *__unsafe_unretained open;
|
|
5
5
|
NSString *__unsafe_unretained close;
|
|
6
6
|
BOOL symmetric;
|
|
7
|
+
// Emphasis-family delimiters (*, _, ~~) only open when left-flanking; code spans
|
|
8
|
+
// and spoilers open regardless of surrounding whitespace, so they skip the check.
|
|
9
|
+
BOOL flanking;
|
|
7
10
|
} ENRMDelimiterPair;
|
|
8
11
|
|
|
9
12
|
static const ENRMDelimiterPair kDelimiterPairs[] = {
|
|
10
|
-
{@"***", @"***", YES}, {@"**", @"**", YES}, {@"*", @"*", YES}, {@"_", @"_", YES},
|
|
11
|
-
{@"~~", @"~~", YES}, {@"||", @"||", YES},
|
|
13
|
+
{@"***", @"***", YES, YES}, {@"**", @"**", YES, YES}, {@"*", @"*", YES, YES}, {@"_", @"_", YES, YES},
|
|
14
|
+
{@"~~", @"~~", YES, YES}, {@"||", @"||", YES, NO}, {@"`", @"`", YES, NO}, {@"[", @"]", NO, NO},
|
|
12
15
|
};
|
|
13
16
|
static const NSUInteger kDelimiterPairCount = sizeof(kDelimiterPairs) / sizeof(kDelimiterPairs[0]);
|
|
14
17
|
|
|
@@ -22,6 +25,40 @@ static NSString *closingForStackEntry(NSString *entry)
|
|
|
22
25
|
return entry;
|
|
23
26
|
}
|
|
24
27
|
|
|
28
|
+
// 0 = whitespace or out-of-bounds boundary, 1 = punctuation, 2 = letter/digit.
|
|
29
|
+
static int flankingLevelAt(NSString *markdown, NSInteger index)
|
|
30
|
+
{
|
|
31
|
+
if (index < 0 || index >= (NSInteger)markdown.length) {
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
unichar c = [markdown characterAtIndex:(NSUInteger)index];
|
|
35
|
+
if ([[NSCharacterSet whitespaceAndNewlineCharacterSet] characterIsMember:c]) {
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
if ([[NSCharacterSet alphanumericCharacterSet] characterIsMember:c]) {
|
|
39
|
+
return 2;
|
|
40
|
+
}
|
|
41
|
+
return 1;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Mirrors md4c's emphasis opener test so completion only closes a delimiter md4c
|
|
45
|
+
// would actually treat as an opener: the run is a potential opener when its right
|
|
46
|
+
// side is "stronger" than its left (rightLevel > 0 and rightLevel >= leftLevel),
|
|
47
|
+
// where each side is scored 0 = whitespace/boundary, 1 = punctuation, 2 = other.
|
|
48
|
+
// Intraword underscore (both sides "other") never opens. This rejects lone or
|
|
49
|
+
// whitespace/punctuation-flanked delimiters (control*, 2 * 3, a*., a_b) that would
|
|
50
|
+
// otherwise fabricate a marker. Intraword * (a*b) is a genuine md4c opener, so it is
|
|
51
|
+
// not (and cannot be) rejected here.
|
|
52
|
+
static BOOL isEmphasisOpener(NSString *markdown, NSUInteger start, NSString *open)
|
|
53
|
+
{
|
|
54
|
+
int leftLevel = flankingLevelAt(markdown, (NSInteger)start - 1);
|
|
55
|
+
int rightLevel = flankingLevelAt(markdown, (NSInteger)start + (NSInteger)open.length);
|
|
56
|
+
if ([open isEqualToString:@"_"] && leftLevel == 2 && rightLevel == 2) {
|
|
57
|
+
return NO;
|
|
58
|
+
}
|
|
59
|
+
return rightLevel > 0 && rightLevel >= leftLevel;
|
|
60
|
+
}
|
|
61
|
+
|
|
25
62
|
NSString *ENRMInputRemendComplete(NSString *markdown)
|
|
26
63
|
{
|
|
27
64
|
if (markdown.length == 0) {
|
|
@@ -84,7 +121,7 @@ NSString *ENRMInputRemendComplete(NSString *markdown)
|
|
|
84
121
|
if ([substring isEqualToString:pair.open]) {
|
|
85
122
|
if (stack.count > 0 && [stack.lastObject isEqualToString:pair.open]) {
|
|
86
123
|
[stack removeLastObject];
|
|
87
|
-
} else {
|
|
124
|
+
} else if (!pair.flanking || isEmphasisOpener(markdown, i, pair.open)) {
|
|
88
125
|
[stack addObject:pair.open];
|
|
89
126
|
}
|
|
90
127
|
i += openLen;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#import "ENRMInputBlockType.h"
|
|
4
|
+
#import <Foundation/Foundation.h>
|
|
5
|
+
|
|
6
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
7
|
+
|
|
8
|
+
/// Which shortcut families are enabled, normalized on the JS side so native
|
|
9
|
+
/// never sees the public `boolean | MarkdownShortcutsConfig` union.
|
|
10
|
+
typedef struct {
|
|
11
|
+
BOOL heading;
|
|
12
|
+
BOOL unorderedList;
|
|
13
|
+
BOOL orderedList;
|
|
14
|
+
} ENRMMarkdownShortcutsConfig;
|
|
15
|
+
|
|
16
|
+
static inline BOOL ENRMMarkdownShortcutsEnabled(ENRMMarkdownShortcutsConfig config)
|
|
17
|
+
{
|
|
18
|
+
return config.heading || config.unorderedList || config.orderedList;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/// Recognizes the markdown block prefixes a user types at the start of a
|
|
22
|
+
/// paragraph — `#`…`######`, `-`/`*`/`+`, `1.`/`1)` — so the input can turn the
|
|
23
|
+
/// paragraph into the matching block and drop the prefix (Notion-style
|
|
24
|
+
/// markdown shortcuts). Pure text matching; the caller owns the mutation.
|
|
25
|
+
@interface ENRMMarkdownShortcutMatcher : NSObject
|
|
26
|
+
|
|
27
|
+
/// Matches `prefix` (the paragraph text before the space the user just typed,
|
|
28
|
+
/// with no leading whitespace) against the shortcut grammar. Returns YES and
|
|
29
|
+
/// fills `outType`/`outLevel` on a match whose family `config` enables. Ordered
|
|
30
|
+
/// items match any number — the block store renumbers ordinals, so `3.` on a
|
|
31
|
+
/// fresh line still starts at 1.
|
|
32
|
+
+ (BOOL)matchPrefix:(NSString *)prefix
|
|
33
|
+
config:(ENRMMarkdownShortcutsConfig)config
|
|
34
|
+
outType:(ENRMInputBlockType *)outType
|
|
35
|
+
outLevel:(NSInteger *)outLevel;
|
|
36
|
+
|
|
37
|
+
@end
|
|
38
|
+
|
|
39
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#import "ENRMMarkdownShortcutMatcher.h"
|
|
2
|
+
|
|
3
|
+
/// Upper bound on the digits accepted before `.`/`)`. Anything longer is a
|
|
4
|
+
/// number the user is writing, not a list marker.
|
|
5
|
+
static const NSUInteger kENRMMaxOrderedMarkerDigits = 9;
|
|
6
|
+
|
|
7
|
+
@implementation ENRMMarkdownShortcutMatcher
|
|
8
|
+
|
|
9
|
+
+ (BOOL)matchPrefix:(NSString *)prefix
|
|
10
|
+
config:(ENRMMarkdownShortcutsConfig)config
|
|
11
|
+
outType:(ENRMInputBlockType *)outType
|
|
12
|
+
outLevel:(NSInteger *)outLevel
|
|
13
|
+
{
|
|
14
|
+
NSUInteger length = prefix.length;
|
|
15
|
+
if (length == 0) {
|
|
16
|
+
return NO;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
unichar first = [prefix characterAtIndex:0];
|
|
20
|
+
|
|
21
|
+
// `#`{1,6} → heading at that level.
|
|
22
|
+
if (first == '#') {
|
|
23
|
+
if (!config.heading || length > 6) {
|
|
24
|
+
return NO;
|
|
25
|
+
}
|
|
26
|
+
for (NSUInteger i = 1; i < length; i++) {
|
|
27
|
+
if ([prefix characterAtIndex:i] != '#') {
|
|
28
|
+
return NO;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
*outType = ENRMBlockTypeForHeadingLevel((NSInteger)length);
|
|
32
|
+
*outLevel = (NSInteger)length;
|
|
33
|
+
return YES;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// `-`, `*`, `+` → bullet item at depth 0.
|
|
37
|
+
if (length == 1 && (first == '-' || first == '*' || first == '+')) {
|
|
38
|
+
if (!config.unorderedList) {
|
|
39
|
+
return NO;
|
|
40
|
+
}
|
|
41
|
+
*outType = ENRMInputBlockTypeUnorderedListItem;
|
|
42
|
+
*outLevel = 0;
|
|
43
|
+
return YES;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// digits followed by `.` or `)` → numbered item at depth 0.
|
|
47
|
+
unichar last = [prefix characterAtIndex:length - 1];
|
|
48
|
+
if ((last == '.' || last == ')') && length >= 2 && length - 1 <= kENRMMaxOrderedMarkerDigits) {
|
|
49
|
+
for (NSUInteger i = 0; i < length - 1; i++) {
|
|
50
|
+
unichar c = [prefix characterAtIndex:i];
|
|
51
|
+
if (c < '0' || c > '9') {
|
|
52
|
+
return NO;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!config.orderedList) {
|
|
56
|
+
return NO;
|
|
57
|
+
}
|
|
58
|
+
*outType = ENRMInputBlockTypeOrderedListItem;
|
|
59
|
+
*outLevel = 0;
|
|
60
|
+
return YES;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return NO;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@end
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
#import "ENRMInputTypingAttributesController.h"
|
|
21
21
|
#import "ENRMLinkCoordinator.h"
|
|
22
22
|
#import "ENRMLinkRegexConfig.h"
|
|
23
|
+
#import "ENRMMarkdownShortcutMatcher.h"
|
|
23
24
|
#import "ENRMMathChipController.h"
|
|
24
25
|
#import "ENRMMentionCoordinator.h"
|
|
25
26
|
#import "ENRMStyleHandler.h"
|
|
@@ -62,6 +63,7 @@ using namespace facebook::react;
|
|
|
62
63
|
- (void)setupTextView;
|
|
63
64
|
- (void)applyFormatting;
|
|
64
65
|
- (void)applyFormattingScopedToEditAtLocation:(NSUInteger)editLocation insertedLength:(NSUInteger)insertedLength;
|
|
66
|
+
- (void)applyFormattingScopedFromParagraphAtLocation:(NSUInteger)editLocation;
|
|
65
67
|
- (void)toggleInlineStyle:(ENRMInputStyleType)styleType;
|
|
66
68
|
- (void)resetBaseTypingAttributes;
|
|
67
69
|
@end
|
|
@@ -122,6 +124,7 @@ static const NSTimeInterval kENRMAtomicSnapPollInterval = 0.1;
|
|
|
122
124
|
// just set; consumed by the next selection change.
|
|
123
125
|
BOOL _suppressMathChipClearOnce;
|
|
124
126
|
|
|
127
|
+
ENRMMarkdownShortcutsConfig _markdownShortcutsConfig;
|
|
125
128
|
ENRMWritingDirectionMode _writingDirectionMode;
|
|
126
129
|
NSWritingDirection _resolvedLayoutDirection;
|
|
127
130
|
|
|
@@ -446,6 +449,14 @@ static const NSTimeInterval kENRMAtomicSnapPollInterval = 0.1;
|
|
|
446
449
|
_textView.editable = newViewProps.editable;
|
|
447
450
|
}
|
|
448
451
|
|
|
452
|
+
// Copied unconditionally: the generated struct only has `operator==` under
|
|
453
|
+
// RN_SERIALIZABLE_STATE, and three BOOLs are cheaper than the comparison.
|
|
454
|
+
_markdownShortcutsConfig = (ENRMMarkdownShortcutsConfig){
|
|
455
|
+
.heading = newViewProps.markdownShortcuts.heading,
|
|
456
|
+
.unorderedList = newViewProps.markdownShortcuts.unorderedList,
|
|
457
|
+
.orderedList = newViewProps.markdownShortcuts.orderedList,
|
|
458
|
+
};
|
|
459
|
+
|
|
449
460
|
#if !TARGET_OS_OSX
|
|
450
461
|
if (newViewProps.scrollEnabled != oldViewProps.scrollEnabled) {
|
|
451
462
|
_textView.scrollEnabled = newViewProps.scrollEnabled;
|
|
@@ -756,6 +767,10 @@ static const NSTimeInterval kENRMAtomicSnapPollInterval = 0.1;
|
|
|
756
767
|
[_editSession enterPhase:ENRMEditPhaseImporting];
|
|
757
768
|
|
|
758
769
|
[_editSession enterPhase:ENRMEditPhaseFormatting];
|
|
770
|
+
// UITextView stamps typingAttributes (including list headIndent from the
|
|
771
|
+
// previous cursor) onto all text set via .text. Reset before import so
|
|
772
|
+
// setValue does not indent non-list lines with the old list depth.
|
|
773
|
+
[self resetBaseTypingAttributes];
|
|
759
774
|
ENRMSetPlainText(_textView, parsed.plainText);
|
|
760
775
|
[_editSession enterPhase:ENRMEditPhaseImporting];
|
|
761
776
|
|
|
@@ -863,6 +878,7 @@ static const NSTimeInterval kENRMAtomicSnapPollInterval = 0.1;
|
|
|
863
878
|
// Positions are relative to the parsed fragment, so shift them onto the spot
|
|
864
879
|
// it landed. Pasted markdown carries formulas like any other source.
|
|
865
880
|
[_mathChipController applyAtoms:parsed.mathAtoms offset:insertLocation];
|
|
881
|
+
[self emitMarkdownAfterAppliedAtoms:parsed.mathAtoms];
|
|
866
882
|
return;
|
|
867
883
|
}
|
|
868
884
|
|
|
@@ -887,6 +903,17 @@ static const NSTimeInterval kENRMAtomicSnapPollInterval = 0.1;
|
|
|
887
903
|
formattingRanges:formattingRanges
|
|
888
904
|
blockRanges:blockRanges];
|
|
889
905
|
[_mathChipController applyAtoms:parsed.mathAtoms offset:insertLocation + lead];
|
|
906
|
+
[self emitMarkdownAfterAppliedAtoms:parsed.mathAtoms];
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
/// replaceTextInRange: emits markdown before the chips get their LaTeX, so that
|
|
910
|
+
/// markdown has a bare U+FFFC where each formula goes. Emit again once the chips
|
|
911
|
+
/// are applied. Android applies chips before its emit, so it does not need this.
|
|
912
|
+
- (void)emitMarkdownAfterAppliedAtoms:(NSArray<ENRMMathAtom *> *)atoms
|
|
913
|
+
{
|
|
914
|
+
if (atoms.count > 0 && _inputEventEmitter.emitMarkdown) {
|
|
915
|
+
[_inputEventEmitter emitOnChangeMarkdown];
|
|
916
|
+
}
|
|
890
917
|
}
|
|
891
918
|
|
|
892
919
|
#pragma mark - Formatting
|
|
@@ -922,6 +949,26 @@ static const NSTimeInterval kENRMAtomicSnapPollInterval = 0.1;
|
|
|
922
949
|
[self applyFormattingScopedToRange:scope];
|
|
923
950
|
}
|
|
924
951
|
|
|
952
|
+
/// Newline variant: a newline can only restructure the paragraph it lands in and
|
|
953
|
+
/// blocks below it, never content above. Scoping from the edit's paragraph start
|
|
954
|
+
/// to the end of the text leaves paragraphs above untouched (issue #739). A
|
|
955
|
+
/// backspace-merge is covered because editLocation lands at the merge point,
|
|
956
|
+
/// whose paragraph range extends back over the joined previous line.
|
|
957
|
+
- (void)applyFormattingScopedFromParagraphAtLocation:(NSUInteger)editLocation
|
|
958
|
+
{
|
|
959
|
+
NSString *plainText = ENRMGetPlainText(_textView);
|
|
960
|
+
NSUInteger textLength = plainText.length;
|
|
961
|
+
if (textLength == 0) {
|
|
962
|
+
[self applyFormatting];
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
NSUInteger location = MIN(editLocation, textLength);
|
|
967
|
+
NSRange paragraph = [plainText paragraphRangeForRange:NSMakeRange(location, 0)];
|
|
968
|
+
NSRange scope = NSMakeRange(paragraph.location, textLength - paragraph.location);
|
|
969
|
+
[self applyFormattingScopedToRange:scope];
|
|
970
|
+
}
|
|
971
|
+
|
|
925
972
|
- (void)applyFormattingScopedToRange:(NSRange)scope
|
|
926
973
|
{
|
|
927
974
|
if (_editSession.shouldSuppressFormatting) {
|
|
@@ -1517,6 +1564,7 @@ static const NSTimeInterval kENRMAtomicSnapPollInterval = 0.1;
|
|
|
1517
1564
|
|
|
1518
1565
|
// replaceTextInRange: already emitted text/selection/formatting for the edit, but
|
|
1519
1566
|
// the caret moved after it and the chip attribute changed the measured height.
|
|
1567
|
+
[self emitMarkdownAfterAppliedAtoms:@[ atom ]];
|
|
1520
1568
|
[_inputEventEmitter emitOnChangeSelection];
|
|
1521
1569
|
[self requestHeightUpdate];
|
|
1522
1570
|
[self scheduleRelayoutIfNeeded];
|
|
@@ -1835,6 +1883,78 @@ static const NSTimeInterval kENRMAtomicSnapPollInterval = 0.1;
|
|
|
1835
1883
|
|
|
1836
1884
|
#pragma mark - Text edit tracking
|
|
1837
1885
|
|
|
1886
|
+
/// Markdown shortcuts: when the user types a space after `#`…`######`,
|
|
1887
|
+
/// `-`/`*`/`+` or `1.`/`1)` at the start of a plain paragraph, drop the prefix
|
|
1888
|
+
/// and make the paragraph that block. Runs after the stores are adjusted for the
|
|
1889
|
+
/// edit and before scoped formatting. Returns YES when it converted, in which
|
|
1890
|
+
/// case the replace path has already reformatted and emitted.
|
|
1891
|
+
- (BOOL)applyMarkdownShortcutForEditAtLocation:(NSUInteger)editLocation
|
|
1892
|
+
deletedLength:(NSUInteger)deletedLength
|
|
1893
|
+
insertedLength:(NSUInteger)insertedLength
|
|
1894
|
+
{
|
|
1895
|
+
// A typing affordance, not a paste/import path: pure insertions only, which
|
|
1896
|
+
// is also how block continuation gates itself.
|
|
1897
|
+
if (!ENRMMarkdownShortcutsEnabled(_markdownShortcutsConfig) || deletedLength != 0 || insertedLength == 0) {
|
|
1898
|
+
return NO;
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
NSString *text = ENRMGetPlainText(_textView);
|
|
1902
|
+
if (editLocation >= text.length) {
|
|
1903
|
+
return NO;
|
|
1904
|
+
}
|
|
1905
|
+
NSUInteger insertedEnd = MIN(editLocation + insertedLength, text.length);
|
|
1906
|
+
|
|
1907
|
+
// The trigger is the first space inside the inserted run — a single
|
|
1908
|
+
// keystroke in the common case, a whole token when an automation inserts
|
|
1909
|
+
// several characters at once. A line break ends the search so the converted
|
|
1910
|
+
// line is always the one the insertion started on.
|
|
1911
|
+
NSCharacterSet *newlines = [NSCharacterSet newlineCharacterSet];
|
|
1912
|
+
NSUInteger spaceIndex = NSNotFound;
|
|
1913
|
+
for (NSUInteger i = editLocation; i < insertedEnd; i++) {
|
|
1914
|
+
unichar c = [text characterAtIndex:i];
|
|
1915
|
+
if (c == ' ') {
|
|
1916
|
+
spaceIndex = i;
|
|
1917
|
+
break;
|
|
1918
|
+
}
|
|
1919
|
+
if ([newlines characterIsMember:c]) {
|
|
1920
|
+
return NO;
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
if (spaceIndex == NSNotFound) {
|
|
1924
|
+
return NO;
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
NSUInteger lineStart = [text paragraphRangeForRange:NSMakeRange(spaceIndex, 0)].location;
|
|
1928
|
+
if (spaceIndex == lineStart || [_blockCoordinator blockAtPosition:lineStart inText:text] != nil) {
|
|
1929
|
+
return NO;
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
NSString *prefix = [text substringWithRange:NSMakeRange(lineStart, spaceIndex - lineStart)];
|
|
1933
|
+
ENRMInputBlockType type = ENRMInputBlockTypeParagraph;
|
|
1934
|
+
NSInteger level = 0;
|
|
1935
|
+
if (![ENRMMarkdownShortcutMatcher matchPrefix:prefix config:_markdownShortcutsConfig outType:&type outLevel:&level]) {
|
|
1936
|
+
return NO;
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
NSRange prefixRange = NSMakeRange(lineStart, spaceIndex + 1 - lineStart);
|
|
1940
|
+
NSRange caretBefore = _textView.selectedRange;
|
|
1941
|
+
|
|
1942
|
+
// A zero-length range at the line start: the store expands it to the whole
|
|
1943
|
+
// paragraph, and on an emptied line it persists as the block's anchor.
|
|
1944
|
+
ENRMBlockRange *block = [ENRMBlockRange rangeWithType:type range:NSMakeRange(0, 0) level:level];
|
|
1945
|
+
[self replaceTextInRange:prefixRange withText:@"" formattingRanges:@[] blockRanges:@[ block ]];
|
|
1946
|
+
|
|
1947
|
+
if (caretBefore.location >= NSMaxRange(prefixRange)) {
|
|
1948
|
+
NSUInteger caret = caretBefore.location - prefixRange.length;
|
|
1949
|
+
_textView.selectedRange = NSMakeRange(MIN(caret, ENRMGetPlainText(_textView).length), 0);
|
|
1950
|
+
}
|
|
1951
|
+
_lastSelectedRange = _textView.selectedRange;
|
|
1952
|
+
|
|
1953
|
+
[_typingController syncWithCursorBlock];
|
|
1954
|
+
[self updateEmptyBulletMarker];
|
|
1955
|
+
return YES;
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1838
1958
|
- (void)handleTextChanged
|
|
1839
1959
|
{
|
|
1840
1960
|
if (_editSession.isComposing) {
|
|
@@ -1887,6 +2007,14 @@ static const NSTimeInterval kENRMAtomicSnapPollInterval = 0.1;
|
|
|
1887
2007
|
|
|
1888
2008
|
_lastTextLength = newLength;
|
|
1889
2009
|
|
|
2010
|
+
// A typed markdown prefix turns the paragraph into a block; the replace path
|
|
2011
|
+
// reformats and emits on its own, so the rest of this pass is redundant.
|
|
2012
|
+
if ([self applyMarkdownShortcutForEditAtLocation:editLocation
|
|
2013
|
+
deletedLength:deletedLength
|
|
2014
|
+
insertedLength:insertedLength]) {
|
|
2015
|
+
return;
|
|
2016
|
+
}
|
|
2017
|
+
|
|
1890
2018
|
#if !TARGET_OS_OSX
|
|
1891
2019
|
if (newLength == 0) {
|
|
1892
2020
|
if ([self headingLevelForCursorParagraph] > 0 || [self listBlockForCursorParagraph] != nil) {
|
|
@@ -1898,7 +2026,7 @@ static const NSTimeInterval kENRMAtomicSnapPollInterval = 0.1;
|
|
|
1898
2026
|
#endif
|
|
1899
2027
|
|
|
1900
2028
|
if (touchedNewline) {
|
|
1901
|
-
[self
|
|
2029
|
+
[self applyFormattingScopedFromParagraphAtLocation:editLocation];
|
|
1902
2030
|
} else {
|
|
1903
2031
|
[self applyFormattingScopedToEditAtLocation:editLocation insertedLength:insertedLength];
|
|
1904
2032
|
}
|