@mathers101/react-native-render-rich-text 0.0.0-stage → 0.1.10
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/LICENSE +20 -0
- package/README.md +140 -3
- package/ReactNativeRenderRichText.podspec +23 -0
- package/android/build.gradle +86 -0
- package/android/consumer-rules.pro +3 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/jni-adapter.cpp +191 -0
- package/android/src/main/java/com/renderrichtext/EnrichedTiptapText.kt +673 -0
- package/android/src/main/java/com/renderrichtext/EnrichedTiptapTextLayoutManager.kt +24 -0
- package/android/src/main/java/com/renderrichtext/EnrichedTiptapTextManager.kt +405 -0
- package/android/src/main/java/com/renderrichtext/EnrichedTiptapTextPackage.kt +13 -0
- package/android/src/main/java/com/renderrichtext/MeasurementStore.kt +644 -0
- package/android/src/main/java/com/renderrichtext/accessibility/AccessibilityLabels.kt +17 -0
- package/android/src/main/java/com/renderrichtext/accessibility/AccessibleTiptapTextView.kt +112 -0
- package/android/src/main/java/com/renderrichtext/accessibility/TiptapAccessibilityHelper.kt +576 -0
- package/android/src/main/java/com/renderrichtext/events/CodeBlockPressEvent.kt +24 -0
- package/android/src/main/java/com/renderrichtext/events/ContextMenuItemPressEvent.kt +28 -0
- package/android/src/main/java/com/renderrichtext/events/CopyPressEvent.kt +24 -0
- package/android/src/main/java/com/renderrichtext/events/FactoidPressEvent.kt +23 -0
- package/android/src/main/java/com/renderrichtext/events/ImagePressEvent.kt +25 -0
- package/android/src/main/java/com/renderrichtext/events/LatexErrorEvent.kt +29 -0
- package/android/src/main/java/com/renderrichtext/events/LinkLongPressEvent.kt +23 -0
- package/android/src/main/java/com/renderrichtext/events/LinkPressEvent.kt +23 -0
- package/android/src/main/java/com/renderrichtext/events/MentionLongPressEvent.kt +25 -0
- package/android/src/main/java/com/renderrichtext/events/MentionPressEvent.kt +25 -0
- package/android/src/main/java/com/renderrichtext/events/TaskListItemPressEvent.kt +26 -0
- package/android/src/main/java/com/renderrichtext/math/LatexErrorReporter.kt +9 -0
- package/android/src/main/java/com/renderrichtext/parser/Parser.kt +59 -0
- package/android/src/main/java/com/renderrichtext/parser/TextLinkMatching.kt +35 -0
- package/android/src/main/java/com/renderrichtext/parser/TiptapASTNode.kt +69 -0
- package/android/src/main/java/com/renderrichtext/renderer/BaselineShiftRenderer.kt +45 -0
- package/android/src/main/java/com/renderrichtext/renderer/BlankLineRenderer.kt +39 -0
- package/android/src/main/java/com/renderrichtext/renderer/BlockStyleContext.kt +181 -0
- package/android/src/main/java/com/renderrichtext/renderer/BlockquoteRenderer.kt +243 -0
- package/android/src/main/java/com/renderrichtext/renderer/BlockquoteTextRenderer.kt +56 -0
- package/android/src/main/java/com/renderrichtext/renderer/CodeBlockRenderer.kt +135 -0
- package/android/src/main/java/com/renderrichtext/renderer/CodeRenderer.kt +37 -0
- package/android/src/main/java/com/renderrichtext/renderer/EmphasisRenderer.kt +28 -0
- package/android/src/main/java/com/renderrichtext/renderer/FactoidRenderer.kt +97 -0
- package/android/src/main/java/com/renderrichtext/renderer/HeadingRenderer.kt +81 -0
- package/android/src/main/java/com/renderrichtext/renderer/HighlightRenderer.kt +26 -0
- package/android/src/main/java/com/renderrichtext/renderer/LineBreakRenderer.kt +17 -0
- package/android/src/main/java/com/renderrichtext/renderer/LinkRenderer.kt +90 -0
- package/android/src/main/java/com/renderrichtext/renderer/ListContextManager.kt +109 -0
- package/android/src/main/java/com/renderrichtext/renderer/ListItemRenderer.kt +211 -0
- package/android/src/main/java/com/renderrichtext/renderer/ListRenderer.kt +133 -0
- package/android/src/main/java/com/renderrichtext/renderer/MentionRenderer.kt +85 -0
- package/android/src/main/java/com/renderrichtext/renderer/NodeRenderer.kt +207 -0
- package/android/src/main/java/com/renderrichtext/renderer/ParagraphRenderer.kt +91 -0
- package/android/src/main/java/com/renderrichtext/renderer/Renderer.kt +148 -0
- package/android/src/main/java/com/renderrichtext/renderer/SoftBreakRenderer.kt +17 -0
- package/android/src/main/java/com/renderrichtext/renderer/SpanStyleCache.kt +143 -0
- package/android/src/main/java/com/renderrichtext/renderer/StrikethroughRenderer.kt +28 -0
- package/android/src/main/java/com/renderrichtext/renderer/StrongRenderer.kt +28 -0
- package/android/src/main/java/com/renderrichtext/renderer/TextRenderer.kt +31 -0
- package/android/src/main/java/com/renderrichtext/renderer/ThematicBreakRenderer.kt +46 -0
- package/android/src/main/java/com/renderrichtext/renderer/UnderlineRenderer.kt +28 -0
- package/android/src/main/java/com/renderrichtext/spans/BaseListSpan.kt +164 -0
- package/android/src/main/java/com/renderrichtext/spans/BaselineShiftSpan.kt +27 -0
- package/android/src/main/java/com/renderrichtext/spans/BlockquoteSpan.kt +302 -0
- package/android/src/main/java/com/renderrichtext/spans/CodeBackgroundSpan.kt +205 -0
- package/android/src/main/java/com/renderrichtext/spans/CodeBlockSpan.kt +216 -0
- package/android/src/main/java/com/renderrichtext/spans/CodeSpan.kt +32 -0
- package/android/src/main/java/com/renderrichtext/spans/EmphasisSpan.kt +42 -0
- package/android/src/main/java/com/renderrichtext/spans/FactoidBackgroundSpan.kt +265 -0
- package/android/src/main/java/com/renderrichtext/spans/FactoidPaddingSpan.kt +258 -0
- package/android/src/main/java/com/renderrichtext/spans/FactoidSpan.kt +32 -0
- package/android/src/main/java/com/renderrichtext/spans/FadeInSpan.kt +29 -0
- package/android/src/main/java/com/renderrichtext/spans/HeadingSpan.kt +38 -0
- package/android/src/main/java/com/renderrichtext/spans/HighlightSpan.kt +80 -0
- package/android/src/main/java/com/renderrichtext/spans/ImageSpan.kt +481 -0
- package/android/src/main/java/com/renderrichtext/spans/InlineBackgroundGeometry.kt +42 -0
- package/android/src/main/java/com/renderrichtext/spans/LineHeightSpan.kt +39 -0
- package/android/src/main/java/com/renderrichtext/spans/LinkPillIconCache.kt +154 -0
- package/android/src/main/java/com/renderrichtext/spans/LinkPillSpan.kt +381 -0
- package/android/src/main/java/com/renderrichtext/spans/LinkSpan.kt +68 -0
- package/android/src/main/java/com/renderrichtext/spans/ListItemSpacingSpan.kt +33 -0
- package/android/src/main/java/com/renderrichtext/spans/ListMarkerAnchorSpan.kt +38 -0
- package/android/src/main/java/com/renderrichtext/spans/MarginBottomSpan.kt +76 -0
- package/android/src/main/java/com/renderrichtext/spans/MentionChipSpan.kt +132 -0
- package/android/src/main/java/com/renderrichtext/spans/MentionSpan.kt +46 -0
- package/android/src/main/java/com/renderrichtext/spans/OrderedListSpan.kt +127 -0
- package/android/src/main/java/com/renderrichtext/spans/SpoilerSpan.kt +33 -0
- package/android/src/main/java/com/renderrichtext/spans/StrikethroughSpan.kt +12 -0
- package/android/src/main/java/com/renderrichtext/spans/StrongSpan.kt +39 -0
- package/android/src/main/java/com/renderrichtext/spans/TaskListSpan.kt +143 -0
- package/android/src/main/java/com/renderrichtext/spans/TextSpan.kt +26 -0
- package/android/src/main/java/com/renderrichtext/spans/ThematicBreakSpan.kt +69 -0
- package/android/src/main/java/com/renderrichtext/spans/UnorderedListSpan.kt +96 -0
- package/android/src/main/java/com/renderrichtext/spoiler/SpoilerStubs.kt +46 -0
- package/android/src/main/java/com/renderrichtext/styles/BaseBlockStyle.kt +11 -0
- package/android/src/main/java/com/renderrichtext/styles/BlockquoteStyle.kt +83 -0
- package/android/src/main/java/com/renderrichtext/styles/CodeBlockStyle.kt +80 -0
- package/android/src/main/java/com/renderrichtext/styles/CodeStyle.kt +26 -0
- package/android/src/main/java/com/renderrichtext/styles/EmphasisStyle.kt +21 -0
- package/android/src/main/java/com/renderrichtext/styles/FactoidStyle.kt +21 -0
- package/android/src/main/java/com/renderrichtext/styles/HeadingStyle.kt +33 -0
- package/android/src/main/java/com/renderrichtext/styles/HighlightStyle.kt +19 -0
- package/android/src/main/java/com/renderrichtext/styles/ImageStyle.kt +29 -0
- package/android/src/main/java/com/renderrichtext/styles/InlineImageStyle.kt +17 -0
- package/android/src/main/java/com/renderrichtext/styles/InlineMathStyle.kt +17 -0
- package/android/src/main/java/com/renderrichtext/styles/LinkPillContent.kt +36 -0
- package/android/src/main/java/com/renderrichtext/styles/LinkPillStyle.kt +44 -0
- package/android/src/main/java/com/renderrichtext/styles/LinkStyle.kt +23 -0
- package/android/src/main/java/com/renderrichtext/styles/LinkVariantEntry.kt +34 -0
- package/android/src/main/java/com/renderrichtext/styles/ListStyle.kt +65 -0
- package/android/src/main/java/com/renderrichtext/styles/MathStyle.kt +29 -0
- package/android/src/main/java/com/renderrichtext/styles/MentionStyle.kt +19 -0
- package/android/src/main/java/com/renderrichtext/styles/ParagraphStyle.kt +33 -0
- package/android/src/main/java/com/renderrichtext/styles/SpoilerStyle.kt +27 -0
- package/android/src/main/java/com/renderrichtext/styles/StrikethroughStyle.kt +17 -0
- package/android/src/main/java/com/renderrichtext/styles/StrongStyle.kt +21 -0
- package/android/src/main/java/com/renderrichtext/styles/StyleConfig.kt +411 -0
- package/android/src/main/java/com/renderrichtext/styles/StyleParser.kt +92 -0
- package/android/src/main/java/com/renderrichtext/styles/SubscriptStyle.kt +16 -0
- package/android/src/main/java/com/renderrichtext/styles/SuperscriptStyle.kt +16 -0
- package/android/src/main/java/com/renderrichtext/styles/TableStyle.kt +75 -0
- package/android/src/main/java/com/renderrichtext/styles/TaskListStyle.kt +29 -0
- package/android/src/main/java/com/renderrichtext/styles/TextAlignment.kt +32 -0
- package/android/src/main/java/com/renderrichtext/styles/ThematicBreakStyle.kt +23 -0
- package/android/src/main/java/com/renderrichtext/styles/UnderlineStyle.kt +17 -0
- package/android/src/main/java/com/renderrichtext/styles/VideoStyle.kt +31 -0
- package/android/src/main/java/com/renderrichtext/utils/common/BorderStyleUtils.kt +86 -0
- package/android/src/main/java/com/renderrichtext/utils/common/BreakStrategyUtils.kt +32 -0
- package/android/src/main/java/com/renderrichtext/utils/common/CodeBlockHighlighter.kt +36 -0
- package/android/src/main/java/com/renderrichtext/utils/common/CodeBlockNode.kt +42 -0
- package/android/src/main/java/com/renderrichtext/utils/common/EllipsizeUtils.kt +27 -0
- package/android/src/main/java/com/renderrichtext/utils/common/EnrichedTiptapAncestorUtils.kt +10 -0
- package/android/src/main/java/com/renderrichtext/utils/common/FeatureFlags.kt +9 -0
- package/android/src/main/java/com/renderrichtext/utils/common/LinkRecognitionProps.kt +31 -0
- package/android/src/main/java/com/renderrichtext/utils/common/LinkRegexConfig.kt +56 -0
- package/android/src/main/java/com/renderrichtext/utils/common/MotionPreferences.kt +18 -0
- package/android/src/main/java/com/renderrichtext/utils/common/ReadableMapExtensions.kt +28 -0
- package/android/src/main/java/com/renderrichtext/utils/common/TiptapViewManagerUtils.kt +242 -0
- package/android/src/main/java/com/renderrichtext/utils/common/layout/RTLUtils.kt +6 -0
- package/android/src/main/java/com/renderrichtext/utils/common/serialization/TiptapASTSerializer.kt +368 -0
- package/android/src/main/java/com/renderrichtext/utils/text/ImageCache.kt +88 -0
- package/android/src/main/java/com/renderrichtext/utils/text/ImageDownloader.kt +203 -0
- package/android/src/main/java/com/renderrichtext/utils/text/LocalImageLoader.kt +167 -0
- package/android/src/main/java/com/renderrichtext/utils/text/TailFadeInAnimator.kt +84 -0
- package/android/src/main/java/com/renderrichtext/utils/text/conversion/HTMLGenerator.kt +1105 -0
- package/android/src/main/java/com/renderrichtext/utils/text/conversion/TiptapExtractor.kt +423 -0
- package/android/src/main/java/com/renderrichtext/utils/text/extensions/ParagraphUtils.kt +9 -0
- package/android/src/main/java/com/renderrichtext/utils/text/extensions/SpannableExtensions.kt +9 -0
- package/android/src/main/java/com/renderrichtext/utils/text/extensions/TextPaintExtensions.kt +76 -0
- package/android/src/main/java/com/renderrichtext/utils/text/interaction/CheckboxTouchHelper.kt +61 -0
- package/android/src/main/java/com/renderrichtext/utils/text/interaction/TaskListTapUtils.kt +286 -0
- package/android/src/main/java/com/renderrichtext/utils/text/span/ApplyLineHeight.kt +39 -0
- package/android/src/main/java/com/renderrichtext/utils/text/span/BlockSpacing.kt +142 -0
- package/android/src/main/java/com/renderrichtext/utils/text/span/SpanFlags.kt +43 -0
- package/android/src/main/java/com/renderrichtext/utils/text/span/WidthAwareSpans.kt +30 -0
- package/android/src/main/java/com/renderrichtext/utils/text/view/CodeBlockPressHost.kt +15 -0
- package/android/src/main/java/com/renderrichtext/utils/text/view/ImagePressHost.kt +19 -0
- package/android/src/main/java/com/renderrichtext/utils/text/view/LinkEvents.kt +88 -0
- package/android/src/main/java/com/renderrichtext/utils/text/view/LinkLongPressMovementMethod.kt +449 -0
- package/android/src/main/java/com/renderrichtext/utils/text/view/SelectionActionMode.kt +235 -0
- package/android/src/main/java/com/renderrichtext/utils/text/view/TextSelectionColors.kt +48 -0
- package/android/src/main/java/com/renderrichtext/utils/text/view/TextViewSetup.kt +119 -0
- package/android/src/main/java/com/renderrichtext/views/ContextMenuPopup.kt +217 -0
- package/android/src/main/java/com/renderrichtext/views/CopyGlyph.kt +101 -0
- package/android/src/main/java/com/renderrichtext/views/WrapGlyph.kt +40 -0
- package/android/src/main/jni/CMakeLists.txt +52 -0
- package/android/src/main/jni/react/renderer/components/RichTextSpec/ComponentDescriptors.h +30 -0
- package/android/src/main/jni/react/renderer/components/RichTextSpec/TiptapTextComponentDescriptor.h +29 -0
- package/android/src/main/jni/react/renderer/components/RichTextSpec/TiptapTextMeasurementManager.cpp +45 -0
- package/android/src/main/jni/react/renderer/components/RichTextSpec/TiptapTextMeasurementManager.h +21 -0
- package/android/src/main/jni/react/renderer/components/RichTextSpec/TiptapTextShadowNode.cpp +38 -0
- package/android/src/main/jni/react/renderer/components/RichTextSpec/TiptapTextShadowNode.h +53 -0
- package/android/src/main/jni/react/renderer/components/RichTextSpec/TiptapTextState.cpp +9 -0
- package/android/src/main/jni/react/renderer/components/RichTextSpec/TiptapTextState.h +24 -0
- package/android/src/main/jni/react/renderer/components/RichTextSpec/conversions.h +40 -0
- package/cpp/parser/TiptapASTNode.hpp +68 -0
- package/cpp/parser/TiptapParser.cpp +233 -0
- package/cpp/parser/TiptapParser.hpp +13 -0
- package/cpp/vendor/nlohmann/json.hpp +24765 -0
- package/ios/EnrichedTiptapText.h +27 -0
- package/ios/EnrichedTiptapText.mm +1222 -0
- package/ios/attachments/ENRMImageAttachment.h +51 -0
- package/ios/attachments/ENRMImageAttachment.m +398 -0
- package/ios/attachments/ENRMLinkPillAttachment.h +47 -0
- package/ios/attachments/ENRMLinkPillAttachment.m +324 -0
- package/ios/attachments/ENRMLinkPillIconCache.h +28 -0
- package/ios/attachments/ENRMLinkPillIconCache.m +181 -0
- package/ios/attachments/ENRMLinkPillText.h +27 -0
- package/ios/attachments/ENRMLinkPillText.m +118 -0
- package/ios/attachments/ENRMMathInlineAttachment.h +7 -0
- package/ios/attachments/ENRMMathInlineAttachment.m +4 -0
- package/ios/attachments/ThematicBreakAttachment.h +15 -0
- package/ios/attachments/ThematicBreakAttachment.m +33 -0
- package/ios/internals/ENRMViewFreeMeasurement.h +208 -0
- package/ios/internals/EnrichedTiptapTextComponentDescriptor.h +19 -0
- package/ios/internals/EnrichedTiptapTextShadowNode.h +43 -0
- package/ios/internals/EnrichedTiptapTextShadowNode.mm +69 -0
- package/ios/internals/EnrichedTiptapTextState.h +24 -0
- package/ios/internals/MeasurementCache.h +308 -0
- package/ios/internals/ShadowMeasurementUtils.h +145 -0
- package/ios/parser/ENRMTextLinkAttributes.h +7 -0
- package/ios/parser/ENRMTiptapParser.h +33 -0
- package/ios/parser/ENRMTiptapParser.mm +73 -0
- package/ios/parser/TiptapASTNode.h +57 -0
- package/ios/parser/TiptapASTNode.m +52 -0
- package/ios/parser/TiptapParserBridge.mm +179 -0
- package/ios/renderer/AttributedRenderer.h +23 -0
- package/ios/renderer/AttributedRenderer.m +229 -0
- package/ios/renderer/BaseRenderer.h +33 -0
- package/ios/renderer/BaseRenderer.m +46 -0
- package/ios/renderer/BaselineShiftTextAttributes.h +10 -0
- package/ios/renderer/BaselineShiftTextAttributes.m +26 -0
- package/ios/renderer/BlankLineRenderer.h +4 -0
- package/ios/renderer/BlankLineRenderer.m +51 -0
- package/ios/renderer/BlockquoteRenderer.h +6 -0
- package/ios/renderer/BlockquoteRenderer.m +258 -0
- package/ios/renderer/CodeBlockRenderer.h +9 -0
- package/ios/renderer/CodeBlockRenderer.m +99 -0
- package/ios/renderer/CodeRenderer.h +9 -0
- package/ios/renderer/CodeRenderer.m +69 -0
- package/ios/renderer/ENRMBlockquoteTextRenderer.h +25 -0
- package/ios/renderer/ENRMBlockquoteTextRenderer.m +48 -0
- package/ios/renderer/EmphasisRenderer.h +5 -0
- package/ios/renderer/EmphasisRenderer.m +100 -0
- package/ios/renderer/FactoidRenderer.h +9 -0
- package/ios/renderer/FactoidRenderer.m +130 -0
- package/ios/renderer/HeadingRenderer.h +6 -0
- package/ios/renderer/HeadingRenderer.m +103 -0
- package/ios/renderer/HighlightRenderer.h +7 -0
- package/ios/renderer/HighlightRenderer.m +33 -0
- package/ios/renderer/LinkRenderer.h +6 -0
- package/ios/renderer/LinkRenderer.m +158 -0
- package/ios/renderer/ListItemRenderer.h +24 -0
- package/ios/renderer/ListItemRenderer.m +283 -0
- package/ios/renderer/ListRenderer.h +13 -0
- package/ios/renderer/ListRenderer.m +126 -0
- package/ios/renderer/MentionRenderer.h +9 -0
- package/ios/renderer/MentionRenderer.m +96 -0
- package/ios/renderer/NodeRenderer.h +8 -0
- package/ios/renderer/ParagraphRenderer.h +6 -0
- package/ios/renderer/ParagraphRenderer.m +85 -0
- package/ios/renderer/RenderContext.h +145 -0
- package/ios/renderer/RenderContext.m +403 -0
- package/ios/renderer/RendererFactory.h +12 -0
- package/ios/renderer/RendererFactory.m +158 -0
- package/ios/renderer/StrikethroughRenderer.h +5 -0
- package/ios/renderer/StrikethroughRenderer.m +30 -0
- package/ios/renderer/StrongRenderer.h +5 -0
- package/ios/renderer/StrongRenderer.m +88 -0
- package/ios/renderer/TextRenderer.h +6 -0
- package/ios/renderer/TextRenderer.m +18 -0
- package/ios/renderer/ThematicBreakRenderer.h +4 -0
- package/ios/renderer/ThematicBreakRenderer.m +42 -0
- package/ios/renderer/UnderlineRenderer.h +4 -0
- package/ios/renderer/UnderlineRenderer.m +41 -0
- package/ios/styles/ENRMFontSlot.h +12 -0
- package/ios/styles/ENRMFontSlot.m +24 -0
- package/ios/styles/StyleConfig.h +488 -0
- package/ios/styles/StyleConfig.mm +2820 -0
- package/ios/utils/AccessibilityInfo.h +35 -0
- package/ios/utils/AccessibilityInfo.m +24 -0
- package/ios/utils/BlockquoteBorder.h +26 -0
- package/ios/utils/BlockquoteBorder.m +294 -0
- package/ios/utils/CodeBackground.h +19 -0
- package/ios/utils/CodeBackground.m +197 -0
- package/ios/utils/CodeBlockBackground.h +17 -0
- package/ios/utils/CodeBlockBackground.m +103 -0
- package/ios/utils/ContextMenuUtils.h +76 -0
- package/ios/utils/ContextMenuUtils.mm +75 -0
- package/ios/utils/ENRMAccessibilityLabels.h +40 -0
- package/ios/utils/ENRMAccessibilityLabels.m +5 -0
- package/ios/utils/ENRMAsyncRenderCoordinator.h +24 -0
- package/ios/utils/ENRMAsyncRenderCoordinator.m +37 -0
- package/ios/utils/ENRMAtomicSize.h +65 -0
- package/ios/utils/ENRMCodeBlockContent.h +37 -0
- package/ios/utils/ENRMCodeBlockContent.mm +89 -0
- package/ios/utils/ENRMFeatureFlags.h +25 -0
- package/ios/utils/ENRMImageDownloader.h +30 -0
- package/ios/utils/ENRMImageDownloader.m +168 -0
- package/ios/utils/ENRMLatexErrorCoordinator.h +27 -0
- package/ios/utils/ENRMLatexErrorCoordinator.mm +75 -0
- package/ios/utils/ENRMLatexErrorReporting.h +13 -0
- package/ios/utils/ENRMLinkContextMenus.h +93 -0
- package/ios/utils/ENRMLinkContextMenus.m +178 -0
- package/ios/utils/ENRMLinkRegexConfig.h +30 -0
- package/ios/utils/ENRMLinkRegexConfig.mm +104 -0
- package/ios/utils/ENRMLinkRegexProps.h +23 -0
- package/ios/utils/ENRMLocalImageLoader.h +35 -0
- package/ios/utils/ENRMLocalImageLoader.m +111 -0
- package/ios/utils/ENRMMenuAction.h +27 -0
- package/ios/utils/ENRMMenuAction.m +33 -0
- package/ios/utils/ENRMSpoilerOverlayManager.h +15 -0
- package/ios/utils/ENRMSpoilerOverlayManager.m +19 -0
- package/ios/utils/ENRMSpoilerTapUtils.h +6 -0
- package/ios/utils/ENRMSpoilerTapUtils.m +11 -0
- package/ios/utils/ENRMTailFadeInAnimator.h +16 -0
- package/ios/utils/ENRMTailFadeInAnimator.m +161 -0
- package/ios/utils/ENRMTextHitTest.h +23 -0
- package/ios/utils/ENRMTextHitTest.m +20 -0
- package/ios/utils/ENRMTextInteractionUtils.h +20 -0
- package/ios/utils/ENRMTextInteractionUtils.m +15 -0
- package/ios/utils/ENRMTextRenderer.h +38 -0
- package/ios/utils/ENRMTextRenderer.m +54 -0
- package/ios/utils/ENRMTextViewSetup.h +132 -0
- package/ios/utils/ENRMUIKit.h +429 -0
- package/ios/utils/EditMenuUtils.h +105 -0
- package/ios/utils/EditMenuUtils.m +143 -0
- package/ios/utils/FactoidBackground.h +20 -0
- package/ios/utils/FactoidBackground.m +161 -0
- package/ios/utils/FontScaleObserver.h +10 -0
- package/ios/utils/FontScaleObserver.m +55 -0
- package/ios/utils/FontUtils.h +31 -0
- package/ios/utils/FontUtils.m +63 -0
- package/ios/utils/HTMLGenerator.h +25 -0
- package/ios/utils/HTMLGenerator.m +1041 -0
- package/ios/utils/HeightUpdateUtils.h +25 -0
- package/ios/utils/ImageRequestHeaderUtils.h +35 -0
- package/ios/utils/LastElementUtils.h +97 -0
- package/ios/utils/LinkContextMenuUtils.h +55 -0
- package/ios/utils/LinkPillContentUtils.h +46 -0
- package/ios/utils/LinkTapUtils.h +56 -0
- package/ios/utils/LinkTapUtils.m +139 -0
- package/ios/utils/ListMarkerDrawer.h +15 -0
- package/ios/utils/ListMarkerDrawer.m +239 -0
- package/ios/utils/MentionBackground.h +26 -0
- package/ios/utils/MentionBackground.m +86 -0
- package/ios/utils/ParagraphStyleUtils.h +87 -0
- package/ios/utils/ParagraphStyleUtils.m +484 -0
- package/ios/utils/PasteboardUtils.h +48 -0
- package/ios/utils/PasteboardUtils.m +166 -0
- package/ios/utils/RTFExportUtils.h +24 -0
- package/ios/utils/RTFExportUtils.m +299 -0
- package/ios/utils/RuntimeKeys.h +44 -0
- package/ios/utils/RuntimeKeys.m +13 -0
- package/ios/utils/SelectionColorUtils.h +14 -0
- package/ios/utils/StylePropsUtils.h +1340 -0
- package/ios/utils/TaskListTapUtils.h +6 -0
- package/ios/utils/TaskListTapUtils.m +14 -0
- package/ios/utils/TextViewLayoutManager.h +14 -0
- package/ios/utils/TextViewLayoutManager.mm +198 -0
- package/ios/utils/TiptapAccessibilityElementBuilder.h +43 -0
- package/ios/utils/TiptapAccessibilityElementBuilder.m +432 -0
- package/ios/utils/TiptapExtractor.h +17 -0
- package/ios/utils/TiptapExtractor.m +367 -0
- package/ios/views/ENRMTiptapTextView.h +25 -0
- package/ios/views/ENRMTiptapTextView.m +247 -0
- package/package.json +70 -6
- package/react-native.config.js +10 -0
- package/src/EnrichedTiptapTextNativeComponent.ts +739 -0
- package/src/RichText.tsx +164 -0
- package/src/admonitionDefaults.ts +58 -0
- package/src/darkModeTextStyle.ts +99 -0
- package/src/headingDefaults.ts +21 -0
- package/src/index.tsx +4 -0
- package/src/linkVariantUtils.ts +120 -0
- package/src/normalizeTiptapStyle.ts +397 -0
- package/src/rn-globals.d.ts +1 -0
- package/src/styleUtils.ts +107 -0
- package/src/types/TiptapStyle.ts +532 -0
- package/src/types/TiptapStyleInternal.ts +299 -0
- package/src/types/linkPill.ts +9 -0
- package/src/utils/isDev.ts +4 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
package com.renderrichtext.renderer
|
|
2
|
+
|
|
3
|
+
import android.graphics.Color
|
|
4
|
+
import android.text.SpannableStringBuilder
|
|
5
|
+
import com.renderrichtext.parser.TiptapASTNode
|
|
6
|
+
import com.renderrichtext.spans.FactoidBackgroundSpan
|
|
7
|
+
import com.renderrichtext.spans.FactoidPaddingSpan
|
|
8
|
+
import com.renderrichtext.spans.FactoidSpan
|
|
9
|
+
import com.renderrichtext.spans.leadingFactoidEdge
|
|
10
|
+
import com.renderrichtext.spans.trailingFactoidEdge
|
|
11
|
+
import com.renderrichtext.utils.text.span.SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE
|
|
12
|
+
|
|
13
|
+
class FactoidRenderer(
|
|
14
|
+
private val config: RendererConfig,
|
|
15
|
+
) : NodeRenderer {
|
|
16
|
+
override fun render(
|
|
17
|
+
node: TiptapASTNode,
|
|
18
|
+
builder: SpannableStringBuilder,
|
|
19
|
+
onLinkPress: ((String) -> Unit)?,
|
|
20
|
+
onLinkLongPress: ((String) -> Unit)?,
|
|
21
|
+
onFactoidPress: ((String) -> Unit)?,
|
|
22
|
+
factory: RendererFactory,
|
|
23
|
+
) {
|
|
24
|
+
// Node attributes replace one channel. Otherwise the spans use the same objects code uses:
|
|
25
|
+
// SpanStyleCache for the text color, StyleConfig for the background and border.
|
|
26
|
+
val textColor = node.getAttribute("color").toColorOrNull()
|
|
27
|
+
val backgroundColor = node.getAttribute("backgroundColor").toColorOrNull()
|
|
28
|
+
val borderColor = node.getAttribute("borderColor").toColorOrNull()
|
|
29
|
+
val factoidId = node.getAttribute("id").orEmpty()
|
|
30
|
+
|
|
31
|
+
// Children are inline nodes (text, marks, links). Push the text color onto the block style
|
|
32
|
+
// so they keep the surrounding font and pick up this color as their base.
|
|
33
|
+
factory.blockStyleContext.pushInlineColor(textColor ?: factory.styleCache.factoidColor)
|
|
34
|
+
try {
|
|
35
|
+
val contentStart = builder.length
|
|
36
|
+
factory.renderChildren(node, builder, onLinkPress, onLinkLongPress, onFactoidPress)
|
|
37
|
+
val contentEnd = builder.length
|
|
38
|
+
if (contentEnd == contentStart) return
|
|
39
|
+
|
|
40
|
+
// The gap is extra advance on the edge word, not its own character. A character
|
|
41
|
+
// is a separate metric run, and the line breaker will leave those 8px on the
|
|
42
|
+
// previous line when the word wraps. A pill already has its own padding; the edge
|
|
43
|
+
// helpers refuse a run that is already a replacement.
|
|
44
|
+
val lead = leadingFactoidEdge(builder, contentStart, contentEnd)
|
|
45
|
+
val trail = trailingFactoidEdge(builder, contentStart, contentEnd)
|
|
46
|
+
if (lead != null && trail != null && lead.runEnd >= trail.runStart) {
|
|
47
|
+
builder.setSpan(
|
|
48
|
+
FactoidPaddingSpan(padStart = true, padEnd = true),
|
|
49
|
+
lead.runStart,
|
|
50
|
+
trail.runEnd,
|
|
51
|
+
SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE,
|
|
52
|
+
)
|
|
53
|
+
} else {
|
|
54
|
+
if (lead != null) {
|
|
55
|
+
builder.setSpan(
|
|
56
|
+
FactoidPaddingSpan(padStart = true, padEnd = false),
|
|
57
|
+
lead.runStart,
|
|
58
|
+
lead.runEnd,
|
|
59
|
+
SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE,
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
if (trail != null) {
|
|
63
|
+
builder.setSpan(
|
|
64
|
+
FactoidPaddingSpan(padStart = false, padEnd = true),
|
|
65
|
+
trail.runStart,
|
|
66
|
+
trail.runEnd,
|
|
67
|
+
SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE,
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
builder.setSpan(
|
|
72
|
+
FactoidSpan(factory.styleCache, factoidId, onFactoidPress, textColor),
|
|
73
|
+
contentStart,
|
|
74
|
+
contentEnd,
|
|
75
|
+
SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE,
|
|
76
|
+
)
|
|
77
|
+
builder.setSpan(
|
|
78
|
+
FactoidBackgroundSpan(config.style, backgroundColor, borderColor),
|
|
79
|
+
contentStart,
|
|
80
|
+
contentEnd,
|
|
81
|
+
SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE,
|
|
82
|
+
)
|
|
83
|
+
} finally {
|
|
84
|
+
factory.blockStyleContext.popInlineColor()
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private fun String?.toColorOrNull(): Int? {
|
|
90
|
+
val value = this?.trim().orEmpty()
|
|
91
|
+
if (value.isEmpty()) return null
|
|
92
|
+
return try {
|
|
93
|
+
Color.parseColor(value)
|
|
94
|
+
} catch (_: IllegalArgumentException) {
|
|
95
|
+
null
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
package com.renderrichtext.renderer
|
|
2
|
+
|
|
3
|
+
import android.text.SpannableStringBuilder
|
|
4
|
+
import android.text.style.AlignmentSpan
|
|
5
|
+
import com.renderrichtext.parser.TiptapASTNode
|
|
6
|
+
import com.renderrichtext.spans.HeadingSpan
|
|
7
|
+
import com.renderrichtext.utils.text.span.SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE
|
|
8
|
+
import com.renderrichtext.utils.text.span.SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE_PRIORITY
|
|
9
|
+
import com.renderrichtext.utils.text.span.applyLinkPillLineHeight
|
|
10
|
+
import com.renderrichtext.utils.text.span.applyMarginBottom
|
|
11
|
+
import com.renderrichtext.utils.text.span.applyMarginTop
|
|
12
|
+
import com.renderrichtext.utils.text.span.createLineHeightSpan
|
|
13
|
+
|
|
14
|
+
class HeadingRenderer(
|
|
15
|
+
private val config: RendererConfig,
|
|
16
|
+
) : NodeRenderer {
|
|
17
|
+
override fun render(
|
|
18
|
+
node: TiptapASTNode,
|
|
19
|
+
builder: SpannableStringBuilder,
|
|
20
|
+
onLinkPress: ((String) -> Unit)?,
|
|
21
|
+
onLinkLongPress: ((String) -> Unit)?,
|
|
22
|
+
onFactoidPress: ((String) -> Unit)?,
|
|
23
|
+
factory: RendererFactory,
|
|
24
|
+
) {
|
|
25
|
+
if (builder.isNotEmpty() && builder.last() != '\n') {
|
|
26
|
+
builder.append("\n")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
val level = node.getAttribute("level")?.toIntOrNull() ?: 1
|
|
30
|
+
val start = builder.length
|
|
31
|
+
|
|
32
|
+
val headingStyle = config.style.headingStyles[level]!!
|
|
33
|
+
val blockStyleContext = factory.blockStyleContext
|
|
34
|
+
blockStyleContext.setHeadingStyle(headingStyle, level)
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
factory.renderChildren(node, builder, onLinkPress, onLinkLongPress, onFactoidPress)
|
|
38
|
+
} finally {
|
|
39
|
+
blockStyleContext.popBlockStyle()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
val end = builder.length
|
|
43
|
+
val contentLength = end - start
|
|
44
|
+
|
|
45
|
+
if (contentLength > 0) {
|
|
46
|
+
// Set after the children, so top priority makes it apply first and the
|
|
47
|
+
// inline spans inside the heading (code, links, strong, emphasis) win.
|
|
48
|
+
builder.setSpan(
|
|
49
|
+
HeadingSpan(
|
|
50
|
+
level,
|
|
51
|
+
config.style,
|
|
52
|
+
),
|
|
53
|
+
start,
|
|
54
|
+
end,
|
|
55
|
+
SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE_PRIORITY,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
builder.setSpan(
|
|
59
|
+
createLineHeightSpan(headingStyle.lineHeight),
|
|
60
|
+
start,
|
|
61
|
+
end,
|
|
62
|
+
SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE,
|
|
63
|
+
)
|
|
64
|
+
applyLinkPillLineHeight(builder, start, end)
|
|
65
|
+
|
|
66
|
+
// Only apply AlignmentSpan for non-default alignments (Center/Right).
|
|
67
|
+
// Justify is handled at the TextView level (API 26+).
|
|
68
|
+
if (headingStyle.textAlign.needsAlignmentSpan) {
|
|
69
|
+
builder.setSpan(
|
|
70
|
+
AlignmentSpan.Standard(headingStyle.textAlign.layoutAlignment),
|
|
71
|
+
start,
|
|
72
|
+
end,
|
|
73
|
+
SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE,
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
applyMarginTop(builder, start, headingStyle.marginTop)
|
|
78
|
+
applyMarginBottom(builder, headingStyle.marginBottom)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
package com.renderrichtext.renderer
|
|
2
|
+
|
|
3
|
+
import android.text.SpannableStringBuilder
|
|
4
|
+
import com.renderrichtext.parser.TiptapASTNode
|
|
5
|
+
import com.renderrichtext.spans.HighlightSpan
|
|
6
|
+
import com.renderrichtext.utils.text.span.SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE
|
|
7
|
+
|
|
8
|
+
class HighlightRenderer : NodeRenderer {
|
|
9
|
+
override fun render(
|
|
10
|
+
node: TiptapASTNode,
|
|
11
|
+
builder: SpannableStringBuilder,
|
|
12
|
+
onLinkPress: ((String) -> Unit)?,
|
|
13
|
+
onLinkLongPress: ((String) -> Unit)?,
|
|
14
|
+
onFactoidPress: ((String) -> Unit)?,
|
|
15
|
+
factory: RendererFactory,
|
|
16
|
+
) {
|
|
17
|
+
factory.renderWithSpan(builder, { factory.renderChildren(node, builder, onLinkPress, onLinkLongPress, onFactoidPress) }) { start, end, blockStyle ->
|
|
18
|
+
builder.setSpan(
|
|
19
|
+
HighlightSpan(factory.styleCache, blockStyle),
|
|
20
|
+
start,
|
|
21
|
+
end,
|
|
22
|
+
SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE,
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package com.renderrichtext.renderer
|
|
2
|
+
|
|
3
|
+
import android.text.SpannableStringBuilder
|
|
4
|
+
import com.renderrichtext.parser.TiptapASTNode
|
|
5
|
+
|
|
6
|
+
class LineBreakRenderer : NodeRenderer {
|
|
7
|
+
override fun render(
|
|
8
|
+
node: TiptapASTNode,
|
|
9
|
+
builder: SpannableStringBuilder,
|
|
10
|
+
onLinkPress: ((String) -> Unit)?,
|
|
11
|
+
onLinkLongPress: ((String) -> Unit)?,
|
|
12
|
+
onFactoidPress: ((String) -> Unit)?,
|
|
13
|
+
factory: RendererFactory,
|
|
14
|
+
) {
|
|
15
|
+
builder.append("\n")
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
package com.renderrichtext.renderer
|
|
2
|
+
|
|
3
|
+
import android.text.SpannableStringBuilder
|
|
4
|
+
import android.text.TextPaint
|
|
5
|
+
import android.text.style.ReplacementSpan
|
|
6
|
+
import com.renderrichtext.parser.TiptapASTNode
|
|
7
|
+
import com.renderrichtext.spans.FactoidPaddingSpan
|
|
8
|
+
import com.renderrichtext.spans.LinkPillSpan
|
|
9
|
+
import com.renderrichtext.spans.LinkSpan
|
|
10
|
+
import com.renderrichtext.spans.SpoilerSpan
|
|
11
|
+
import com.renderrichtext.spans.stripFactoidPadding
|
|
12
|
+
import com.renderrichtext.utils.text.extensions.applyBlockStyleFont
|
|
13
|
+
import com.renderrichtext.utils.text.span.SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE
|
|
14
|
+
|
|
15
|
+
class LinkRenderer(
|
|
16
|
+
private val config: RendererConfig,
|
|
17
|
+
) : NodeRenderer {
|
|
18
|
+
// Reused to resolve each pill's typeface; a renderer serves one render at a time.
|
|
19
|
+
private val fontProbe = TextPaint()
|
|
20
|
+
|
|
21
|
+
override fun render(
|
|
22
|
+
node: TiptapASTNode,
|
|
23
|
+
builder: SpannableStringBuilder,
|
|
24
|
+
onLinkPress: ((String) -> Unit)?,
|
|
25
|
+
onLinkLongPress: ((String) -> Unit)?,
|
|
26
|
+
onFactoidPress: ((String) -> Unit)?,
|
|
27
|
+
factory: RendererFactory,
|
|
28
|
+
) {
|
|
29
|
+
val url = node.getAttribute("url") ?: return
|
|
30
|
+
val recognizedLink = node.getAttribute("recognizedLink") == "true"
|
|
31
|
+
|
|
32
|
+
factory.renderWithSpan(builder, { factory.renderChildren(node, builder, onLinkPress, onLinkLongPress, onFactoidPress) }) { start, end, blockStyle ->
|
|
33
|
+
val variant = factory.styleCache.resolvedVariantForUrl(url)
|
|
34
|
+
if (variant?.pill != null && canPresentAsPill(builder, start, end)) {
|
|
35
|
+
val fontFamily = variant.fontFamily.ifEmpty { factory.styleCache.linkFontFamily }.ifEmpty { blockStyle.fontFamily }
|
|
36
|
+
val font = fontProbe.apply { applyBlockStyleFont(blockStyle.copy(fontFamily = fontFamily), factory.context) }
|
|
37
|
+
val pill =
|
|
38
|
+
LinkPillSpan(
|
|
39
|
+
variant,
|
|
40
|
+
font.typeface,
|
|
41
|
+
blockStyle.fontSize,
|
|
42
|
+
builder.subSequence(start, end).stripFactoidPadding(),
|
|
43
|
+
factory.context,
|
|
44
|
+
config.style.linkPillContent[url],
|
|
45
|
+
config.style.imageRequestHeaders,
|
|
46
|
+
followsRunTypeface = variant.fontFamily.isEmpty() && factory.styleCache.linkFontFamily.isEmpty(),
|
|
47
|
+
)
|
|
48
|
+
// Set directly, not deferred: the pill measures with its own font, so it does not
|
|
49
|
+
// need to come after the block spans, and a late insertion makes the builder re-sort.
|
|
50
|
+
builder.setSpan(pill, start, end, SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE)
|
|
51
|
+
factory.runAfterRender { text -> pill.resolveLeadingMargin(text, text.getSpanStart(pill), text.getSpanEnd(pill)) }
|
|
52
|
+
}
|
|
53
|
+
builder.setSpan(
|
|
54
|
+
LinkSpan(
|
|
55
|
+
url,
|
|
56
|
+
onLinkPress,
|
|
57
|
+
onLinkLongPress,
|
|
58
|
+
factory.styleCache,
|
|
59
|
+
blockStyle,
|
|
60
|
+
factory.context,
|
|
61
|
+
recognizedLink = recognizedLink,
|
|
62
|
+
keepsCodeFont = recognizedLink && node.children.any { it.type == TiptapASTNode.NodeType.Code },
|
|
63
|
+
),
|
|
64
|
+
start,
|
|
65
|
+
end,
|
|
66
|
+
SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE,
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A pill replaces one unbroken run. Links that already hold a replacement (image,
|
|
73
|
+
* math) or span a line break stay ordinary links: a replacement straddling two
|
|
74
|
+
* paragraphs would be drawn once per paragraph. So do links holding a spoiler,
|
|
75
|
+
* whose hidden text the label would show. Factoid padding only reserves a gap.
|
|
76
|
+
*/
|
|
77
|
+
private fun canPresentAsPill(
|
|
78
|
+
builder: SpannableStringBuilder,
|
|
79
|
+
start: Int,
|
|
80
|
+
end: Int,
|
|
81
|
+
): Boolean {
|
|
82
|
+
if (builder.getSpans(start, end, ReplacementSpan::class.java).any { it !is FactoidPaddingSpan }) return false
|
|
83
|
+
if (builder.getSpans(start, end, SpoilerSpan::class.java).isNotEmpty()) return false
|
|
84
|
+
for (index in start until end) {
|
|
85
|
+
val char = builder[index]
|
|
86
|
+
if (char == '\n' || char == '\r' || char == '\u2028' || char == '\u2029') return false
|
|
87
|
+
}
|
|
88
|
+
return true
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
package com.renderrichtext.renderer
|
|
2
|
+
|
|
3
|
+
import com.renderrichtext.styles.ListStyle
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Manages list context transitions (entering/exiting lists, handling nesting, etc.).
|
|
7
|
+
* Centralizes logic for managing list depth, item numbers, and parent context restoration.
|
|
8
|
+
*
|
|
9
|
+
* Key concepts:
|
|
10
|
+
* - **listDepth**: Tracks nesting level (0 = top-level, 1 = first nested, etc.)
|
|
11
|
+
* - **Stack-based numbering**: Pushes parent's item number when entering nested ordered lists,
|
|
12
|
+
* allowing each level to maintain its own counter while preserving parent's position.
|
|
13
|
+
* - **Parent context restoration**: Restores parent list's style when exiting nested lists
|
|
14
|
+
* so subsequent parent items render correctly.
|
|
15
|
+
* - **Marker column**: An ordered list widens its `99.` column to fit its widest marker, and a
|
|
16
|
+
* nested list inherits the widening of the item it sits in.
|
|
17
|
+
*/
|
|
18
|
+
class ListContextManager(
|
|
19
|
+
private val context: BlockStyleContext,
|
|
20
|
+
) {
|
|
21
|
+
/**
|
|
22
|
+
* Captures the state when entering a list, needed for proper restoration when exiting.
|
|
23
|
+
* This ensures we can restore the exact parent context even after nested lists modify it.
|
|
24
|
+
*/
|
|
25
|
+
data class ListEntryState(
|
|
26
|
+
val previousDepth: Int,
|
|
27
|
+
val parentListType: BlockStyleContext.ListType?,
|
|
28
|
+
val wasNestedInOrderedList: Boolean,
|
|
29
|
+
val previousMarkerExtra: Float,
|
|
30
|
+
val previousMarkerOffset: Float,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Enters a list context. Handles:
|
|
35
|
+
* - Saving parent list item numbers to stack (for ordered lists) before resetting counter
|
|
36
|
+
* - Incrementing list depth
|
|
37
|
+
* - Setting the appropriate list style
|
|
38
|
+
* - Resetting item number for the new list
|
|
39
|
+
* - Widening the marker column by [markerExtraWidth] and shifting a nested list by its parent item's widening
|
|
40
|
+
*/
|
|
41
|
+
fun enterList(
|
|
42
|
+
listType: BlockStyleContext.ListType,
|
|
43
|
+
style: ListStyle,
|
|
44
|
+
startNumber: Int = 1,
|
|
45
|
+
markerExtraWidth: Float = 0f,
|
|
46
|
+
): ListEntryState {
|
|
47
|
+
val previousDepth = context.listDepth
|
|
48
|
+
val isNested = previousDepth > 0
|
|
49
|
+
val parentListType = if (isNested) context.listType else null
|
|
50
|
+
val parentIsOrdered = parentListType == BlockStyleContext.ListType.ORDERED
|
|
51
|
+
|
|
52
|
+
// Push parent's item number to stack before resetting for nested list.
|
|
53
|
+
// Even if entering an unordered list, we need to save if parent is ordered.
|
|
54
|
+
if (isNested && parentIsOrdered) {
|
|
55
|
+
context.pushOrderedListItemNumber()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
context.listDepth = previousDepth + 1
|
|
59
|
+
when (listType) {
|
|
60
|
+
BlockStyleContext.ListType.ORDERED -> {
|
|
61
|
+
context.setOrderedListStyle(style)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
BlockStyleContext.ListType.UNORDERED -> {
|
|
65
|
+
context.setUnorderedListStyle(style)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
context.resetListItemNumber(startNumber)
|
|
69
|
+
|
|
70
|
+
val previousMarkerExtra = context.listMarkerExtra
|
|
71
|
+
val previousMarkerOffset = context.ancestorMarkerOffset
|
|
72
|
+
if (isNested) {
|
|
73
|
+
context.ancestorMarkerOffset += context.listItemMarkerExtra
|
|
74
|
+
}
|
|
75
|
+
context.listMarkerExtra = markerExtraWidth
|
|
76
|
+
|
|
77
|
+
return ListEntryState(
|
|
78
|
+
previousDepth = previousDepth,
|
|
79
|
+
parentListType = parentListType,
|
|
80
|
+
wasNestedInOrderedList = isNested && parentIsOrdered,
|
|
81
|
+
previousMarkerExtra = previousMarkerExtra,
|
|
82
|
+
previousMarkerOffset = previousMarkerOffset,
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Exits a list context. Handles:
|
|
88
|
+
* - Popping current list block style from stack
|
|
89
|
+
* - Decrementing list depth back to previousDepth
|
|
90
|
+
* - Restoring parent list item numbers from stack (if applicable)
|
|
91
|
+
* - Restoring parent list metadata (if nested) so subsequent parent items render correctly
|
|
92
|
+
* - Restoring the parent list's marker column and offset
|
|
93
|
+
*/
|
|
94
|
+
fun exitList(entryState: ListEntryState) {
|
|
95
|
+
context.listDepth = entryState.previousDepth
|
|
96
|
+
context.clearListStyle()
|
|
97
|
+
|
|
98
|
+
if (entryState.wasNestedInOrderedList) {
|
|
99
|
+
context.popOrderedListItemNumber()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (entryState.previousDepth > 0) {
|
|
103
|
+
context.listType = entryState.parentListType
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
context.listMarkerExtra = entryState.previousMarkerExtra
|
|
107
|
+
context.ancestorMarkerOffset = entryState.previousMarkerOffset
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
package com.renderrichtext.renderer
|
|
2
|
+
|
|
3
|
+
import android.text.SpannableStringBuilder
|
|
4
|
+
import android.text.style.ForegroundColorSpan
|
|
5
|
+
import android.text.style.StrikethroughSpan
|
|
6
|
+
import com.renderrichtext.parser.TiptapASTNode
|
|
7
|
+
import com.renderrichtext.spans.BaseListSpan
|
|
8
|
+
import com.renderrichtext.spans.CodeBlockSpan
|
|
9
|
+
import com.renderrichtext.spans.ListMarkerAnchorSpan
|
|
10
|
+
import com.renderrichtext.spans.OrderedListSpan
|
|
11
|
+
import com.renderrichtext.spans.TaskListSpan
|
|
12
|
+
import com.renderrichtext.spans.UnorderedListSpan
|
|
13
|
+
import com.renderrichtext.utils.text.span.SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE
|
|
14
|
+
import com.renderrichtext.utils.text.span.SPAN_FLAGS_LIST_ITEM
|
|
15
|
+
|
|
16
|
+
class ListItemRenderer(
|
|
17
|
+
private val config: RendererConfig,
|
|
18
|
+
) : NodeRenderer {
|
|
19
|
+
override fun render(
|
|
20
|
+
node: TiptapASTNode,
|
|
21
|
+
builder: SpannableStringBuilder,
|
|
22
|
+
onLinkPress: ((String) -> Unit)?,
|
|
23
|
+
onLinkLongPress: ((String) -> Unit)?,
|
|
24
|
+
onFactoidPress: ((String) -> Unit)?,
|
|
25
|
+
factory: RendererFactory,
|
|
26
|
+
) {
|
|
27
|
+
val styleContext = factory.blockStyleContext
|
|
28
|
+
val start = builder.length
|
|
29
|
+
val listType = styleContext.listType ?: return
|
|
30
|
+
|
|
31
|
+
val isTask = node.attributes["isTask"] == "true"
|
|
32
|
+
val isChecked = isTask && node.attributes["taskChecked"] == "true"
|
|
33
|
+
|
|
34
|
+
if (listType == BlockStyleContext.ListType.ORDERED) {
|
|
35
|
+
styleContext.incrementListItemNumber()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
val taskIndex = if (isTask) styleContext.taskItemCount++ else -1
|
|
39
|
+
|
|
40
|
+
val depth = styleContext.listDepth - 1
|
|
41
|
+
val listStyle = config.style.listStyle
|
|
42
|
+
|
|
43
|
+
fun makeSpan(drawsMarker: Boolean): BaseListSpan =
|
|
44
|
+
if (isTask) {
|
|
45
|
+
TaskListSpan(
|
|
46
|
+
taskStyle = config.style.taskListStyle,
|
|
47
|
+
listStyle = listStyle,
|
|
48
|
+
depth = depth,
|
|
49
|
+
context = factory.context,
|
|
50
|
+
styleCache = factory.styleCache,
|
|
51
|
+
taskIndex = taskIndex,
|
|
52
|
+
isChecked = isChecked,
|
|
53
|
+
drawsMarker = drawsMarker,
|
|
54
|
+
ancestorMarkerOffset = styleContext.ancestorMarkerOffset,
|
|
55
|
+
markerExtraWidth = styleContext.listMarkerExtra,
|
|
56
|
+
parentMarkerWidth = styleContext.listItemMarkerWidth,
|
|
57
|
+
)
|
|
58
|
+
} else {
|
|
59
|
+
when (listType) {
|
|
60
|
+
BlockStyleContext.ListType.UNORDERED -> {
|
|
61
|
+
UnorderedListSpan(
|
|
62
|
+
listStyle,
|
|
63
|
+
depth,
|
|
64
|
+
factory.context,
|
|
65
|
+
factory.styleCache,
|
|
66
|
+
drawsMarker,
|
|
67
|
+
ancestorMarkerOffset = styleContext.ancestorMarkerOffset,
|
|
68
|
+
parentMarkerWidth = styleContext.listItemMarkerWidth,
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
BlockStyleContext.ListType.ORDERED -> {
|
|
73
|
+
OrderedListSpan(
|
|
74
|
+
listStyle,
|
|
75
|
+
depth,
|
|
76
|
+
factory.context,
|
|
77
|
+
factory.styleCache,
|
|
78
|
+
drawsMarker,
|
|
79
|
+
markerExtraWidth = styleContext.listMarkerExtra,
|
|
80
|
+
ancestorMarkerOffset = styleContext.ancestorMarkerOffset,
|
|
81
|
+
parentMarkerWidth = styleContext.listItemMarkerWidth,
|
|
82
|
+
).apply {
|
|
83
|
+
setItemNumber(styleContext.listItemNumber)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
val markerSpan = makeSpan(drawsMarker = true)
|
|
90
|
+
|
|
91
|
+
val previousMarkerExtra = styleContext.listItemMarkerExtra
|
|
92
|
+
styleContext.listItemMarkerExtra = markerSpan.markerExtraWidth
|
|
93
|
+
val previousMarkerWidth = styleContext.listItemMarkerWidth
|
|
94
|
+
styleContext.listItemMarkerWidth = markerSpan.baselineMarkerWidth
|
|
95
|
+
val prevIndent = styleContext.accumulatedIndent
|
|
96
|
+
styleContext.accumulatedIndent = prevIndent + markerSpan.getLeadingMargin(false)
|
|
97
|
+
try {
|
|
98
|
+
factory.renderChildren(node, builder, onLinkPress, onLinkLongPress, onFactoidPress)
|
|
99
|
+
} finally {
|
|
100
|
+
styleContext.accumulatedIndent = prevIndent
|
|
101
|
+
styleContext.listItemMarkerExtra = previousMarkerExtra
|
|
102
|
+
styleContext.listItemMarkerWidth = previousMarkerWidth
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (builder.length == start || builder.substring(start).isBlank()) return
|
|
106
|
+
|
|
107
|
+
styleContext.listItemStarts.add(start)
|
|
108
|
+
|
|
109
|
+
if (builder.last() != '\n') {
|
|
110
|
+
builder.append("\n")
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
val itemEnd = builder.length
|
|
114
|
+
|
|
115
|
+
// Anchor the marker on the first content character so items that open with
|
|
116
|
+
// a code block or nested sublist still get their marker.
|
|
117
|
+
var anchor = start
|
|
118
|
+
while (anchor < itemEnd && builder[anchor].isWhitespace()) anchor++
|
|
119
|
+
if (anchor == itemEnd) anchor = start
|
|
120
|
+
|
|
121
|
+
val plainAnchor =
|
|
122
|
+
builder.getSpans(anchor, anchor + 1, CodeBlockSpan::class.java).isEmpty() &&
|
|
123
|
+
builder.getSpans(anchor, anchor + 1, BaseListSpan::class.java).none { it.depth > depth }
|
|
124
|
+
|
|
125
|
+
val codeBlockRanges =
|
|
126
|
+
builder
|
|
127
|
+
.getSpans(start, itemEnd, CodeBlockSpan::class.java)
|
|
128
|
+
.map { builder.getSpanStart(it) to builder.getSpanEnd(it) }
|
|
129
|
+
.filter { it.first < it.second }
|
|
130
|
+
.sortedBy { it.first }
|
|
131
|
+
|
|
132
|
+
var pos = start
|
|
133
|
+
var isFirstSegment = true
|
|
134
|
+
for ((cbStart, cbEnd) in codeBlockRanges) {
|
|
135
|
+
if (pos < cbStart) {
|
|
136
|
+
builder.setSpan(
|
|
137
|
+
if (isFirstSegment && plainAnchor) markerSpan else makeSpan(drawsMarker = false),
|
|
138
|
+
pos,
|
|
139
|
+
cbStart,
|
|
140
|
+
SPAN_FLAGS_LIST_ITEM,
|
|
141
|
+
)
|
|
142
|
+
isFirstSegment = false
|
|
143
|
+
}
|
|
144
|
+
pos = maxOf(pos, cbEnd)
|
|
145
|
+
}
|
|
146
|
+
if (pos < itemEnd) {
|
|
147
|
+
builder.setSpan(
|
|
148
|
+
if (isFirstSegment && plainAnchor) markerSpan else makeSpan(drawsMarker = false),
|
|
149
|
+
pos,
|
|
150
|
+
itemEnd,
|
|
151
|
+
SPAN_FLAGS_LIST_ITEM,
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (!plainAnchor) {
|
|
156
|
+
builder.setSpan(ListMarkerAnchorSpan(markerSpan), anchor, anchor + 1, SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (isTask && isChecked) {
|
|
160
|
+
applyCheckedDecorations(builder, start, itemEnd, depth)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private fun applyCheckedDecorations(
|
|
165
|
+
builder: SpannableStringBuilder,
|
|
166
|
+
itemStart: Int,
|
|
167
|
+
itemEnd: Int,
|
|
168
|
+
itemDepth: Int,
|
|
169
|
+
) {
|
|
170
|
+
val taskStyle = config.style.taskListStyle
|
|
171
|
+
val checkedTextColor = taskStyle.checkedTextColor
|
|
172
|
+
val strikethrough = taskStyle.checkedStrikethrough
|
|
173
|
+
|
|
174
|
+
if (checkedTextColor == 0 && !strikethrough) return
|
|
175
|
+
|
|
176
|
+
val excludedRanges =
|
|
177
|
+
(
|
|
178
|
+
builder.getSpans(itemStart, itemEnd, BaseListSpan::class.java).filter { it.depth > itemDepth } +
|
|
179
|
+
builder.getSpans(itemStart, itemEnd, CodeBlockSpan::class.java).toList()
|
|
180
|
+
).map { builder.getSpanStart(it) to builder.getSpanEnd(it) }
|
|
181
|
+
.sortedBy { it.first }
|
|
182
|
+
|
|
183
|
+
var currentPos = itemStart
|
|
184
|
+
|
|
185
|
+
for ((start, end) in excludedRanges) {
|
|
186
|
+
if (start > currentPos) {
|
|
187
|
+
applySpans(builder, currentPos, start, checkedTextColor, strikethrough)
|
|
188
|
+
}
|
|
189
|
+
currentPos = maxOf(currentPos, end)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (currentPos < itemEnd) {
|
|
193
|
+
applySpans(builder, currentPos, itemEnd, checkedTextColor, strikethrough)
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
private fun applySpans(
|
|
198
|
+
builder: SpannableStringBuilder,
|
|
199
|
+
start: Int,
|
|
200
|
+
end: Int,
|
|
201
|
+
color: Int,
|
|
202
|
+
strikethrough: Boolean,
|
|
203
|
+
) {
|
|
204
|
+
if (color != 0) {
|
|
205
|
+
builder.setSpan(ForegroundColorSpan(color), start, end, SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE)
|
|
206
|
+
}
|
|
207
|
+
if (strikethrough) {
|
|
208
|
+
builder.setSpan(StrikethroughSpan(), start, end, SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE)
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|