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/ios/utils/LinkTapUtils.h
CHANGED
|
@@ -14,8 +14,23 @@ NSString *_Nullable linkURLAtTapLocation(ENRMPlatformTextView *textView, ENRMTap
|
|
|
14
14
|
/// Returns the link URL at the given character range, or nil if none found.
|
|
15
15
|
NSString *_Nullable linkURLAtRange(ENRMPlatformTextView *textView, NSRange characterRange);
|
|
16
16
|
|
|
17
|
-
/// Returns
|
|
18
|
-
|
|
17
|
+
/// Returns the tapped image as @{@"url": ..., @"altText": ...}, or nil if the
|
|
18
|
+
/// tap did not land on an image. A linked image resolves to its link (the
|
|
19
|
+
/// linkURL attribute wins), so this returns nil for it.
|
|
20
|
+
NSDictionary<NSString *, NSString *> *_Nullable imageAtTapLocation(ENRMPlatformTextView *textView,
|
|
21
|
+
ENRMTapRecognizer *recognizer);
|
|
22
|
+
|
|
23
|
+
/// Returns the tapped code block as @{@"code": ..., @"language": ...}, or nil if
|
|
24
|
+
/// the tap did not land on a commonmark code block.
|
|
25
|
+
NSDictionary<NSString *, NSString *> *_Nullable codeBlockAtTapLocation(ENRMPlatformTextView *textView,
|
|
26
|
+
ENRMTapRecognizer *recognizer);
|
|
27
|
+
|
|
28
|
+
/// Returns YES if the point (in textView coordinates) is on a link or task list
|
|
29
|
+
/// checkbox. When `includeImages` is YES, images also count as interactive
|
|
30
|
+
/// (used to stop a parent press handler once `onImagePress` is enabled), and
|
|
31
|
+
/// likewise `includeCodeBlock` for `onCodeBlockPress`.
|
|
32
|
+
BOOL isPointOnInteractiveElement(ENRMPlatformTextView *textView, CGPoint point, BOOL includeImages,
|
|
33
|
+
BOOL includeCodeBlock);
|
|
19
34
|
|
|
20
35
|
#ifdef __cplusplus
|
|
21
36
|
}
|
package/ios/utils/LinkTapUtils.m
CHANGED
|
@@ -21,12 +21,54 @@ NSString *_Nullable linkURLAtRange(ENRMPlatformTextView *textView, NSRange chara
|
|
|
21
21
|
return [attrText attribute:@"linkURL" atIndex:characterRange.location effectiveRange:NULL];
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
NSDictionary<NSString *, NSString *> *_Nullable imageAtTapLocation(ENRMPlatformTextView *textView,
|
|
25
|
+
ENRMTapRecognizer *recognizer)
|
|
26
|
+
{
|
|
27
|
+
NSUInteger characterIndex = ENRMCharacterIndexForTap(textView, recognizer);
|
|
28
|
+
if (characterIndex == NSNotFound)
|
|
29
|
+
return nil;
|
|
30
|
+
|
|
31
|
+
NSAttributedString *attrText = ENRMGetAttributedText(textView);
|
|
32
|
+
if ([attrText attribute:@"linkURL" atIndex:characterIndex effectiveRange:NULL] != nil)
|
|
33
|
+
return nil;
|
|
34
|
+
|
|
35
|
+
NSString *url = [attrText attribute:@"imageURL" atIndex:characterIndex effectiveRange:NULL];
|
|
36
|
+
if (!url)
|
|
37
|
+
return nil;
|
|
38
|
+
|
|
39
|
+
NSString *altText = [attrText attribute:@"imageAltText" atIndex:characterIndex effectiveRange:NULL];
|
|
40
|
+
return @{@"url" : url, @"altText" : altText ?: @""};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
NSDictionary<NSString *, NSString *> *_Nullable codeBlockAtTapLocation(ENRMPlatformTextView *textView,
|
|
44
|
+
ENRMTapRecognizer *recognizer)
|
|
45
|
+
{
|
|
46
|
+
NSUInteger characterIndex = ENRMCharacterIndexForTap(textView, recognizer);
|
|
47
|
+
if (characterIndex == NSNotFound)
|
|
48
|
+
return nil;
|
|
49
|
+
|
|
50
|
+
NSAttributedString *attrText = ENRMGetAttributedText(textView);
|
|
51
|
+
NSString *code = [attrText attribute:@"codeBlockText" atIndex:characterIndex effectiveRange:NULL];
|
|
52
|
+
if (!code)
|
|
53
|
+
return nil;
|
|
54
|
+
|
|
55
|
+
NSString *language = [attrText attribute:@"codeBlockLanguage" atIndex:characterIndex effectiveRange:NULL];
|
|
56
|
+
return @{@"code" : code, @"language" : language ?: @""};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
BOOL isPointOnInteractiveElement(ENRMPlatformTextView *textView, CGPoint point, BOOL includeImages,
|
|
60
|
+
BOOL includeCodeBlock)
|
|
25
61
|
{
|
|
26
62
|
NSUInteger charIndex = ENRMCharacterIndexAtPoint(textView, point);
|
|
27
63
|
if (charIndex == NSNotFound)
|
|
28
64
|
return NO;
|
|
29
65
|
|
|
30
66
|
NSDictionary *attrs = [ENRMGetAttributedText(textView) attributesAtIndex:charIndex effectiveRange:NULL];
|
|
31
|
-
|
|
67
|
+
if (attrs[@"linkURL"] != nil || [attrs[@"TaskItem"] boolValue] || attrs[SpoilerAttributeName] != nil)
|
|
68
|
+
return YES;
|
|
69
|
+
|
|
70
|
+
if (includeImages && attrs[@"imageURL"] != nil)
|
|
71
|
+
return YES;
|
|
72
|
+
|
|
73
|
+
return includeCodeBlock && attrs[@"codeBlockText"] != nil;
|
|
32
74
|
}
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
extern NSString *const ListItemMarkerStartAttribute;
|
|
9
9
|
|
|
10
|
+
static NSString *const kAppleColorEmojiFontName = @"AppleColorEmoji";
|
|
11
|
+
|
|
10
12
|
@implementation ListMarkerDrawer {
|
|
11
13
|
StyleConfig *_config;
|
|
12
14
|
}
|
|
@@ -57,7 +59,29 @@ extern NSString *const ListItemMarkerStartAttribute;
|
|
|
57
59
|
|
|
58
60
|
CGPoint glyphLoc = [layoutManager locationForGlyphAtIndex:glyphRange.location];
|
|
59
61
|
CGFloat baselineY = origin.y + rect.origin.y + glyphLoc.y;
|
|
60
|
-
|
|
62
|
+
|
|
63
|
+
// When the anchor character is an emoji, NSFontAttributeName
|
|
64
|
+
// returns AppleColorEmoji whose metrics (xHeight, capHeight)
|
|
65
|
+
// differ widely from the text font and would misplace the
|
|
66
|
+
// marker. Look past the first composed character sequence
|
|
67
|
+
// to find the actual text font used on the line.
|
|
68
|
+
UIFont *font = attrs[NSFontAttributeName];
|
|
69
|
+
if (charRange.length > 1) {
|
|
70
|
+
NSRange firstGrapheme =
|
|
71
|
+
[storage.string rangeOfComposedCharacterSequenceAtIndex:charRange.location];
|
|
72
|
+
NSUInteger afterFirst = NSMaxRange(firstGrapheme);
|
|
73
|
+
if (afterFirst < NSMaxRange(charRange)) {
|
|
74
|
+
UIFont *textFont = [storage attribute:NSFontAttributeName
|
|
75
|
+
atIndex:afterFirst
|
|
76
|
+
effectiveRange:NULL];
|
|
77
|
+
if (textFont) {
|
|
78
|
+
font = textFont;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (!font || [font.fontName isEqualToString:kAppleColorEmojiFontName]) {
|
|
83
|
+
font = [self defaultFont];
|
|
84
|
+
}
|
|
61
85
|
|
|
62
86
|
for (ENRMListMarkerDescriptor *marker in markers) {
|
|
63
87
|
CGFloat markerX = isRTL ? origin.x + container.size.width - marker.indent + gap
|
|
@@ -17,6 +17,13 @@ NSString *markdownFromASTNode(MarkdownASTNode *node);
|
|
|
17
17
|
/// Useful for extracting the markdown content of a container node (e.g. a table cell).
|
|
18
18
|
NSString *markdownFromASTNodeChildren(MarkdownASTNode *node);
|
|
19
19
|
|
|
20
|
+
/// Serializes a Blockquote or Admonition node to full markdown, including `> ` line
|
|
21
|
+
/// prefixes and `> [!TYPE]` header for admonitions.
|
|
22
|
+
NSString *markdownFromBlockquoteNode(MarkdownASTNode *node);
|
|
23
|
+
|
|
24
|
+
/// Extracts plain text content from an AST node recursively (no markdown syntax).
|
|
25
|
+
NSString *plainTextFromASTNode(MarkdownASTNode *node);
|
|
26
|
+
|
|
20
27
|
#ifdef __cplusplus
|
|
21
28
|
}
|
|
22
29
|
#endif
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
#import "MarkdownASTSerializer.h"
|
|
2
|
+
#import "ENRMCodeBlockContent.h"
|
|
2
3
|
#import "MarkdownASTNode.h"
|
|
3
4
|
|
|
4
5
|
static void serializeNode(MarkdownASTNode *node, NSMutableString *buffer);
|
|
5
6
|
static void serializeChildren(MarkdownASTNode *node, NSMutableString *buffer);
|
|
7
|
+
static void appendBlockNode(MarkdownASTNode *node, NSMutableString *buffer);
|
|
8
|
+
static void appendPlainText(MarkdownASTNode *node, NSMutableString *buffer);
|
|
6
9
|
|
|
7
10
|
static void serializeChildren(MarkdownASTNode *node, NSMutableString *buffer)
|
|
8
11
|
{
|
|
@@ -92,6 +95,16 @@ static void serializeNode(MarkdownASTNode *node, NSMutableString *buffer)
|
|
|
92
95
|
break;
|
|
93
96
|
}
|
|
94
97
|
|
|
98
|
+
case MarkdownNodeTypeVideo: {
|
|
99
|
+
NSString *url = node.attributes[@"url"] ?: @"";
|
|
100
|
+
if ([url containsString:@"\""]) {
|
|
101
|
+
[buffer appendFormat:@"<video src='%@' />", url];
|
|
102
|
+
} else {
|
|
103
|
+
[buffer appendFormat:@"<video src=\"%@\" />", url];
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
|
|
95
108
|
case MarkdownNodeTypeParagraph:
|
|
96
109
|
default:
|
|
97
110
|
serializeChildren(node, buffer);
|
|
@@ -99,6 +112,199 @@ static void serializeNode(MarkdownASTNode *node, NSMutableString *buffer)
|
|
|
99
112
|
}
|
|
100
113
|
}
|
|
101
114
|
|
|
115
|
+
// --- Block-level serialization ---
|
|
116
|
+
|
|
117
|
+
static void serializeBlockChildren(MarkdownASTNode *node, NSMutableString *buffer)
|
|
118
|
+
{
|
|
119
|
+
NSArray<MarkdownASTNode *> *children = node.children;
|
|
120
|
+
for (NSUInteger i = 0; i < children.count; i++) {
|
|
121
|
+
MarkdownASTNode *child = children[i];
|
|
122
|
+
appendBlockNode(child, buffer);
|
|
123
|
+
if (i < children.count - 1 && ENRMIsTopLevelBlockType(child.type)) {
|
|
124
|
+
[buffer appendString:@"\n"];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Table markdown reconstruction from raw AST nodes. This parallels
|
|
130
|
+
// TableContainerView's buildMarkdownFromRows which works from processed
|
|
131
|
+
// TableCellData; both must produce the same pipe-table format.
|
|
132
|
+
static void appendTableMarkdown(MarkdownASTNode *node, NSMutableString *buffer)
|
|
133
|
+
{
|
|
134
|
+
BOOL headerDone = NO;
|
|
135
|
+
for (MarkdownASTNode *section in node.children) {
|
|
136
|
+
for (MarkdownASTNode *row in section.children) {
|
|
137
|
+
if (row.type != MarkdownNodeTypeTableRow)
|
|
138
|
+
continue;
|
|
139
|
+
NSMutableArray<NSString *> *cells = [NSMutableArray arrayWithCapacity:row.children.count];
|
|
140
|
+
for (MarkdownASTNode *cell in row.children) {
|
|
141
|
+
[cells addObject:markdownFromASTNodeChildren(cell)];
|
|
142
|
+
}
|
|
143
|
+
[buffer appendFormat:@"| %@ |\n", [cells componentsJoinedByString:@" | "]];
|
|
144
|
+
if (!headerDone) {
|
|
145
|
+
BOOL isHeader = NO;
|
|
146
|
+
for (MarkdownASTNode *cell in row.children) {
|
|
147
|
+
if (cell.type == MarkdownNodeTypeTableHeaderCell) {
|
|
148
|
+
isHeader = YES;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (isHeader) {
|
|
153
|
+
NSMutableArray<NSString *> *sep = [NSMutableArray arrayWithCapacity:row.children.count];
|
|
154
|
+
for (MarkdownASTNode *cell in row.children) {
|
|
155
|
+
NSString *align = cell.attributes[@"align"];
|
|
156
|
+
if ([align isEqualToString:@"center"])
|
|
157
|
+
[sep addObject:@":---:"];
|
|
158
|
+
else if ([align isEqualToString:@"right"])
|
|
159
|
+
[sep addObject:@"---:"];
|
|
160
|
+
else
|
|
161
|
+
[sep addObject:@"---"];
|
|
162
|
+
}
|
|
163
|
+
[buffer appendFormat:@"| %@ |\n", [sep componentsJoinedByString:@" | "]];
|
|
164
|
+
headerDone = YES;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
static void appendListMarkdown(MarkdownASTNode *node, NSMutableString *buffer, BOOL ordered)
|
|
172
|
+
{
|
|
173
|
+
NSUInteger number = 1;
|
|
174
|
+
if (ordered) {
|
|
175
|
+
NSString *startAttr = node.attributes[@"start"];
|
|
176
|
+
if (startAttr != nil) {
|
|
177
|
+
NSInteger parsed = startAttr.integerValue;
|
|
178
|
+
number = (NSUInteger)MAX(0, parsed);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
for (MarkdownASTNode *item in node.children) {
|
|
182
|
+
if (item.type != MarkdownNodeTypeListItem)
|
|
183
|
+
continue;
|
|
184
|
+
NSString *prefix = ordered ? [NSString stringWithFormat:@"%lu. ", (unsigned long)number] : @"- ";
|
|
185
|
+
NSMutableString *content = [NSMutableString string];
|
|
186
|
+
serializeBlockChildren(item, content);
|
|
187
|
+
NSString *trimmed =
|
|
188
|
+
content.length > 0 ? [content stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]] : @"";
|
|
189
|
+
NSArray<NSString *> *lines = [trimmed componentsSeparatedByString:@"\n"];
|
|
190
|
+
NSString *indent = [@"" stringByPaddingToLength:prefix.length withString:@" " startingAtIndex:0];
|
|
191
|
+
for (NSUInteger l = 0; l < lines.count; l++) {
|
|
192
|
+
[buffer appendString:(l == 0) ? prefix : indent];
|
|
193
|
+
[buffer appendString:lines[l]];
|
|
194
|
+
[buffer appendString:@"\n"];
|
|
195
|
+
}
|
|
196
|
+
if (ordered)
|
|
197
|
+
number++;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
static void appendBlockNode(MarkdownASTNode *node, NSMutableString *buffer)
|
|
202
|
+
{
|
|
203
|
+
if (!node)
|
|
204
|
+
return;
|
|
205
|
+
|
|
206
|
+
switch (node.type) {
|
|
207
|
+
case MarkdownNodeTypeParagraph:
|
|
208
|
+
serializeChildren(node, buffer);
|
|
209
|
+
[buffer appendString:@"\n"];
|
|
210
|
+
break;
|
|
211
|
+
|
|
212
|
+
case MarkdownNodeTypeHeading: {
|
|
213
|
+
NSInteger level = [node.attributes[@"level"] integerValue];
|
|
214
|
+
if (level < 1)
|
|
215
|
+
level = 1;
|
|
216
|
+
for (NSInteger i = 0; i < level; i++)
|
|
217
|
+
[buffer appendString:@"#"];
|
|
218
|
+
[buffer appendString:@" "];
|
|
219
|
+
serializeChildren(node, buffer);
|
|
220
|
+
[buffer appendString:@"\n"];
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
case MarkdownNodeTypeCodeBlock: {
|
|
225
|
+
NSString *code = ENRMCodeBlockExtractCode(node);
|
|
226
|
+
NSString *language = ENRMCodeBlockLanguage(node);
|
|
227
|
+
NSString *fenceChar = ENRMCodeBlockFenceChar(node);
|
|
228
|
+
[buffer appendString:ENRMCodeBlockFencedMarkdown(code, language, fenceChar)];
|
|
229
|
+
[buffer appendString:@"\n"];
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
case MarkdownNodeTypeBlockquote:
|
|
234
|
+
case MarkdownNodeTypeAdmonition:
|
|
235
|
+
[buffer appendString:markdownFromBlockquoteNode(node)];
|
|
236
|
+
break;
|
|
237
|
+
|
|
238
|
+
case MarkdownNodeTypeThematicBreak:
|
|
239
|
+
[buffer appendString:@"---\n"];
|
|
240
|
+
break;
|
|
241
|
+
|
|
242
|
+
case MarkdownNodeTypeBlankLine: {
|
|
243
|
+
NSInteger count = [node.attributes[@"count"] integerValue];
|
|
244
|
+
for (NSInteger i = 0; i < count; i++) {
|
|
245
|
+
[buffer appendString:@"\n"];
|
|
246
|
+
}
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
case MarkdownNodeTypeTable:
|
|
251
|
+
appendTableMarkdown(node, buffer);
|
|
252
|
+
break;
|
|
253
|
+
|
|
254
|
+
case MarkdownNodeTypeUnorderedList:
|
|
255
|
+
appendListMarkdown(node, buffer, NO);
|
|
256
|
+
break;
|
|
257
|
+
|
|
258
|
+
case MarkdownNodeTypeOrderedList:
|
|
259
|
+
appendListMarkdown(node, buffer, YES);
|
|
260
|
+
break;
|
|
261
|
+
|
|
262
|
+
case MarkdownNodeTypeLatexMathDisplay:
|
|
263
|
+
[buffer appendString:@"$$\n"];
|
|
264
|
+
serializeChildren(node, buffer);
|
|
265
|
+
[buffer appendString:@"\n$$\n"];
|
|
266
|
+
break;
|
|
267
|
+
|
|
268
|
+
default:
|
|
269
|
+
serializeChildren(node, buffer);
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
static void appendPlainText(MarkdownASTNode *node, NSMutableString *buffer)
|
|
275
|
+
{
|
|
276
|
+
switch (node.type) {
|
|
277
|
+
case MarkdownNodeTypeSoftBreak:
|
|
278
|
+
case MarkdownNodeTypeLineBreak:
|
|
279
|
+
[buffer appendString:@"\n"];
|
|
280
|
+
break;
|
|
281
|
+
case MarkdownNodeTypeBlankLine: {
|
|
282
|
+
NSInteger count = [node.attributes[@"count"] integerValue];
|
|
283
|
+
for (NSInteger i = 0; i < count; i++) {
|
|
284
|
+
[buffer appendString:@"\n"];
|
|
285
|
+
}
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
case MarkdownNodeTypeParagraph:
|
|
289
|
+
case MarkdownNodeTypeHeading:
|
|
290
|
+
for (MarkdownASTNode *child in node.children) {
|
|
291
|
+
appendPlainText(child, buffer);
|
|
292
|
+
}
|
|
293
|
+
[buffer appendString:@"\n"];
|
|
294
|
+
break;
|
|
295
|
+
default:
|
|
296
|
+
if (node.content.length > 0) {
|
|
297
|
+
[buffer appendString:node.content];
|
|
298
|
+
}
|
|
299
|
+
for (MarkdownASTNode *child in node.children) {
|
|
300
|
+
appendPlainText(child, buffer);
|
|
301
|
+
}
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// --- Public API ---
|
|
307
|
+
|
|
102
308
|
NSString *markdownFromASTNode(MarkdownASTNode *node)
|
|
103
309
|
{
|
|
104
310
|
if (!node)
|
|
@@ -116,3 +322,40 @@ NSString *markdownFromASTNodeChildren(MarkdownASTNode *node)
|
|
|
116
322
|
serializeChildren(node, buffer);
|
|
117
323
|
return [buffer copy];
|
|
118
324
|
}
|
|
325
|
+
|
|
326
|
+
NSString *markdownFromBlockquoteNode(MarkdownASTNode *node)
|
|
327
|
+
{
|
|
328
|
+
if (!node)
|
|
329
|
+
return @"";
|
|
330
|
+
|
|
331
|
+
NSMutableString *result = [NSMutableString string];
|
|
332
|
+
BOOL isAdmonition = (node.type == MarkdownNodeTypeAdmonition);
|
|
333
|
+
|
|
334
|
+
if (isAdmonition) {
|
|
335
|
+
NSString *type = node.attributes[@"admonitionType"];
|
|
336
|
+
if (!type.length)
|
|
337
|
+
type = @"note";
|
|
338
|
+
[result appendFormat:@"> [!%@]\n", [type uppercaseString]];
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
NSMutableString *body = [NSMutableString string];
|
|
342
|
+
serializeBlockChildren(node, body);
|
|
343
|
+
|
|
344
|
+
NSString *trimmed = [body stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
|
|
345
|
+
NSArray<NSString *> *lines = [trimmed componentsSeparatedByString:@"\n"];
|
|
346
|
+
for (NSString *line in lines) {
|
|
347
|
+
[result appendString:@"> "];
|
|
348
|
+
[result appendString:line];
|
|
349
|
+
[result appendString:@"\n"];
|
|
350
|
+
}
|
|
351
|
+
return [result copy];
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
NSString *plainTextFromASTNode(MarkdownASTNode *node)
|
|
355
|
+
{
|
|
356
|
+
if (!node)
|
|
357
|
+
return @"";
|
|
358
|
+
NSMutableString *buffer = [NSMutableString string];
|
|
359
|
+
appendPlainText(node, buffer);
|
|
360
|
+
return [[buffer copy] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
|
361
|
+
}
|
|
@@ -163,12 +163,7 @@ static const CGFloat kFocusRectPadding = 2.0;
|
|
|
163
163
|
if (text.length > 0)
|
|
164
164
|
element.accessibilityLabel = text;
|
|
165
165
|
|
|
166
|
-
|
|
167
|
-
if (path) {
|
|
168
|
-
element.accessibilityPath = path;
|
|
169
|
-
} else {
|
|
170
|
-
element.accessibilityFrameInContainerSpace = [self frameForRange:range inTextView:textView container:container];
|
|
171
|
-
}
|
|
166
|
+
element.accessibilityFrameInContainerSpace = [self frameForRange:range inTextView:textView container:container];
|
|
172
167
|
|
|
173
168
|
if (type == ElementTypeImage) {
|
|
174
169
|
element.accessibilityTraits =
|
|
@@ -181,8 +176,10 @@ static const CGFloat kFocusRectPadding = 2.0;
|
|
|
181
176
|
}
|
|
182
177
|
|
|
183
178
|
NSMutableArray<NSString *> *valueParts = [NSMutableArray array];
|
|
184
|
-
|
|
185
|
-
|
|
179
|
+
NSString *listAnnouncement =
|
|
180
|
+
(listInfo && type != ElementTypeImage) ? [self formatListAnnouncement:listInfo labels:labels] : nil;
|
|
181
|
+
if (listAnnouncement) {
|
|
182
|
+
[valueParts addObject:listAnnouncement];
|
|
186
183
|
}
|
|
187
184
|
NSString *blockquoteAnnouncement = [self blockquoteAnnouncementForRange:range textView:textView labels:labels];
|
|
188
185
|
if (blockquoteAnnouncement) {
|
|
@@ -199,12 +196,11 @@ static const CGFloat kFocusRectPadding = 2.0;
|
|
|
199
196
|
textView:(UITextView *)textView
|
|
200
197
|
labels:(ENRMAccessibilityLabels *)labels
|
|
201
198
|
{
|
|
202
|
-
|
|
199
|
+
NSTextStorage *storage = textView.textStorage;
|
|
200
|
+
if (storage.length == 0 || range.location >= storage.length)
|
|
203
201
|
return nil;
|
|
204
202
|
NSRange effective;
|
|
205
|
-
NSNumber *depth = [
|
|
206
|
-
atIndex:range.location
|
|
207
|
-
effectiveRange:&effective];
|
|
203
|
+
NSNumber *depth = [storage attribute:BlockquoteDepthAttributeName atIndex:range.location effectiveRange:&effective];
|
|
208
204
|
if (depth == nil)
|
|
209
205
|
return nil;
|
|
210
206
|
return depth.integerValue >= 1 ? labels.nestedBlockquote : labels.blockquote;
|
|
@@ -231,63 +227,9 @@ static const CGFloat kFocusRectPadding = 2.0;
|
|
|
231
227
|
return NSMakeRange(range.location, MIN(range.length, text.length - range.location));
|
|
232
228
|
}
|
|
233
229
|
|
|
234
|
-
+ (NSArray<NSValue *> *)perLineRectsForGlyphRange:(NSRange)glyphRange inTextView:(UITextView *)textView
|
|
235
|
-
{
|
|
236
|
-
NSLayoutManager *layoutManager = textView.layoutManager;
|
|
237
|
-
UIEdgeInsets insets = textView.textContainerInset;
|
|
238
|
-
NSMutableArray<NSValue *> *rects = [NSMutableArray array];
|
|
239
|
-
|
|
240
|
-
[layoutManager
|
|
241
|
-
enumerateLineFragmentsForGlyphRange:glyphRange
|
|
242
|
-
usingBlock:^(CGRect lineRect, CGRect usedRect, NSTextContainer *textContainer,
|
|
243
|
-
NSRange lineGlyphRange, BOOL *stop) {
|
|
244
|
-
NSRange overlap = NSIntersectionRange(glyphRange, lineGlyphRange);
|
|
245
|
-
if (overlap.length == 0)
|
|
246
|
-
return;
|
|
247
|
-
|
|
248
|
-
CGFloat left = [layoutManager locationForGlyphAtIndex:overlap.location].x;
|
|
249
|
-
BOOL extendsToLineEnd = (NSMaxRange(overlap) == NSMaxRange(lineGlyphRange));
|
|
250
|
-
CGFloat right = extendsToLineEnd
|
|
251
|
-
? CGRectGetMaxX(usedRect)
|
|
252
|
-
: [layoutManager locationForGlyphAtIndex:NSMaxRange(overlap)].x;
|
|
253
|
-
|
|
254
|
-
CGRect rect =
|
|
255
|
-
CGRectMake(left, CGRectGetMinY(usedRect), right - left, CGRectGetHeight(usedRect));
|
|
256
|
-
rect = CGRectInset(rect, -kFocusRectPadding, -kFocusRectPadding);
|
|
257
|
-
rect = CGRectOffset(rect, insets.left, insets.top);
|
|
258
|
-
[rects addObject:[NSValue valueWithCGRect:rect]];
|
|
259
|
-
}];
|
|
260
|
-
|
|
261
|
-
return rects;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
+ (UIBezierPath *)accessibilityPathForRange:(NSRange)range inTextView:(UITextView *)textView
|
|
265
|
-
{
|
|
266
|
-
NSRange clamped = [self clampedRange:range forText:textView.attributedText.string];
|
|
267
|
-
if (clamped.location == NSNotFound)
|
|
268
|
-
return nil;
|
|
269
|
-
|
|
270
|
-
NSRange glyphRange = [textView.layoutManager glyphRangeForCharacterRange:clamped actualCharacterRange:NULL];
|
|
271
|
-
NSArray<NSValue *> *lineRects = [self perLineRectsForGlyphRange:glyphRange inTextView:textView];
|
|
272
|
-
if (lineRects.count <= 1)
|
|
273
|
-
return nil;
|
|
274
|
-
|
|
275
|
-
UIWindow *window = textView.window;
|
|
276
|
-
if (!window)
|
|
277
|
-
return nil;
|
|
278
|
-
|
|
279
|
-
id<UICoordinateSpace> screenSpace = window.screen.coordinateSpace;
|
|
280
|
-
UIBezierPath *path = [UIBezierPath bezierPath];
|
|
281
|
-
for (NSValue *value in lineRects) {
|
|
282
|
-
CGRect screenRect = [textView convertRect:CGRectIntegral(value.CGRectValue) toCoordinateSpace:screenSpace];
|
|
283
|
-
[path appendPath:[UIBezierPath bezierPathWithRect:screenRect]];
|
|
284
|
-
}
|
|
285
|
-
return path;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
230
|
+ (CGRect)frameForRange:(NSRange)range inTextView:(UITextView *)textView container:(id)container
|
|
289
231
|
{
|
|
290
|
-
NSRange clamped = [self clampedRange:range forText:textView.
|
|
232
|
+
NSRange clamped = [self clampedRange:range forText:textView.textStorage.string];
|
|
291
233
|
if (clamped.location == NSNotFound)
|
|
292
234
|
return CGRectZero;
|
|
293
235
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#import "MarkdownExtractor.h"
|
|
2
|
+
#import "BaselineShiftTextAttributes.h"
|
|
2
3
|
#import "BlockquoteBorder.h"
|
|
3
4
|
#import "ENRMFeatureFlags.h"
|
|
4
5
|
#import "ENRMImageAttachment.h"
|
|
@@ -301,9 +302,11 @@ NSString *_Nullable extractMarkdownFromAttributedString(NSAttributedString *attr
|
|
|
301
302
|
BOOL isStrikethrough = (strikethroughStyle != nil && [strikethroughStyle integerValue] != 0);
|
|
302
303
|
NSNumber *underlineStyle = attrs[NSUnderlineStyleAttributeName];
|
|
303
304
|
BOOL isUnderline = (underlineStyle != nil && [underlineStyle integerValue] != 0);
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
305
|
+
// Line-height alignment also shifts baselines. Only semantic script spans
|
|
306
|
+
// should produce superscript/subscript Markdown on the clipboard.
|
|
307
|
+
NSString *script = attrs[ENRMScriptAttributeName];
|
|
308
|
+
BOOL isSuperscript = [script isEqualToString:ENRMScriptValueSuperscript];
|
|
309
|
+
BOOL isSubscript = [script isEqualToString:ENRMScriptValueSubscript];
|
|
307
310
|
|
|
308
311
|
BOOL isHighlight = [attrs[HighlightAttributeName] boolValue];
|
|
309
312
|
NSString *linkURL = attrs[NSLinkAttributeName];
|
|
@@ -11,6 +11,12 @@ NSLineBreakStrategy ENRMResolveLineBreakStrategy(NSString *_Nullable strategy);
|
|
|
11
11
|
void ENRMApplyLineBreakStrategyToParagraphStyles(NSMutableAttributedString *output,
|
|
12
12
|
NSLineBreakStrategy lineBreakStrategy);
|
|
13
13
|
|
|
14
|
+
/// Resolves an ellipsizeMode prop value to the NSLineBreakMode used for
|
|
15
|
+
/// truncation on the text container (with maximumNumberOfLines). 'clip' maps to
|
|
16
|
+
/// NSLineBreakByClipping (truncate with no ellipsis). Defaults to tail. Mirrors
|
|
17
|
+
/// React Native Text's ellipsizeMode.
|
|
18
|
+
NSLineBreakMode ENRMResolveEllipsizeLineBreakMode(NSString *_Nullable mode);
|
|
19
|
+
|
|
14
20
|
/// Auto/LTR/RTL match React Native's writingDirection prop.
|
|
15
21
|
/// FirstStrong is the library extension: resolve each paragraph from its first strong
|
|
16
22
|
/// directional character (matches Android's TEXT_DIRECTION_FIRST_STRONG).
|
|
@@ -44,12 +50,30 @@ NSUInteger applyParagraphSpacingBefore(NSMutableAttributedString *output, NSRang
|
|
|
44
50
|
NSUInteger applyBlockSpacingBefore(NSMutableAttributedString *output, NSUInteger insertionPoint, CGFloat marginTop);
|
|
45
51
|
void applyBlockSpacingAfter(NSMutableAttributedString *output, CGFloat marginBottom);
|
|
46
52
|
void applyLineHeight(NSMutableAttributedString *output, NSRange range, CGFloat lineHeight);
|
|
47
|
-
void applyBaselineOffset(NSMutableAttributedString *output, NSRange range);
|
|
48
53
|
|
|
49
54
|
/// True when the range contains a block (non-inline) image attachment. Lines holding
|
|
50
55
|
/// such attachments must not be clamped by maximumLineHeight or the image box
|
|
51
56
|
/// overflows the line and paints over surrounding content.
|
|
52
57
|
BOOL ENRMRangeContainsBlockImage(NSAttributedString *output, NSRange range);
|
|
58
|
+
|
|
59
|
+
/// Stamps every styled run in `range` with `NSOriginalFont` set to its own
|
|
60
|
+
/// `NSFont`, so a line is sized from the font the renderer chose rather than
|
|
61
|
+
/// from whichever font ends up drawing the glyphs.
|
|
62
|
+
///
|
|
63
|
+
/// UIKit writes this attribute itself, but only into a UITextView's storage, so
|
|
64
|
+
/// the view-free measurement stack never saw it and sized a line from the
|
|
65
|
+
/// fallback font instead. Stamping it here keeps measuring and rendering agreed.
|
|
66
|
+
///
|
|
67
|
+
/// IMPORTANT:
|
|
68
|
+
/// Call this last, after every font in the range is final, on any attributed
|
|
69
|
+
/// string handed to a layout engine. A run whose `NSFont` changes after the
|
|
70
|
+
/// stamp is then sized from the stale font, in the measurement stack and in
|
|
71
|
+
/// `UITextView` alike, so the line comes out wrong in both.
|
|
72
|
+
/// `ENRMRenderASTNodes` and `ENRMRenderBlockquoteContentNodes` cover everything
|
|
73
|
+
/// built through the node renderers; the two paths that assemble their own
|
|
74
|
+
/// string (table cells, code block content) call it themselves.
|
|
75
|
+
void ENRMPinLineMetricsToStyledFonts(NSMutableAttributedString *output, NSRange range);
|
|
76
|
+
void applyBaselineOffset(NSMutableAttributedString *output, NSRange range);
|
|
53
77
|
void applyTextAlignment(NSMutableAttributedString *output, NSRange range, NSTextAlignment textAlign);
|
|
54
78
|
NSTextAlignment textAlignmentFromString(NSString *textAlign);
|
|
55
79
|
|