react-native-enriched 0.2.1 → 0.4.0
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/README.md +21 -16
- package/android/build.gradle +77 -72
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerDelegate.java +21 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerInterface.java +7 -0
- package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ComponentDescriptors.cpp +1 -1
- package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ComponentDescriptors.h +1 -1
- package/android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec/EventEmitters.cpp +276 -0
- package/android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec/EventEmitters.h +239 -0
- package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.cpp +10 -0
- package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.h +251 -0
- package/android/gradle.properties +5 -5
- package/android/lint.gradle +70 -0
- package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputViewPackage.kt → ReactNativeEnrichedPackage.kt} +4 -5
- package/android/src/main/java/com/swmansion/enriched/{utils → common}/AsyncDrawable.kt +50 -15
- package/android/src/main/java/com/swmansion/enriched/common/CheckboxDrawable.kt +81 -0
- package/android/src/main/java/com/swmansion/enriched/common/EnrichedConstants.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/common/EnrichedStyle.kt +57 -0
- package/android/src/main/java/com/swmansion/enriched/{spans/utils → common}/ForceRedrawSpan.kt +3 -2
- package/android/src/main/java/com/swmansion/enriched/common/MentionStyle.kt +7 -0
- package/android/src/main/java/com/swmansion/enriched/{utils → common}/ResourceManager.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{utils → common/parser}/EnrichedParser.java +228 -160
- package/android/src/main/java/com/swmansion/enriched/common/parser/EnrichedSpanFactory.kt +79 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedBlockQuoteSpan.kt +53 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedBoldSpan.kt +12 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedCheckboxListSpan.kt +91 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedCodeBlockSpan.kt +12 -14
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH1Span.kt +20 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH2Span.kt +20 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH3Span.kt +20 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH4Span.kt +21 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH5Span.kt +20 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH6Span.kt +20 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedImageSpan.kt +68 -51
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedInlineCodeSpan.kt +24 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedItalicSpan.kt +12 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedLinkSpan.kt +26 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedMentionSpan.kt +35 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedOrderedListSpan.kt +21 -29
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedStrikeThroughSpan.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedUnderlineSpan.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedUnorderedListSpan.kt +13 -17
- package/android/src/main/java/com/swmansion/enriched/common/spans/interfaces/EnrichedBlockSpan.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/interfaces/EnrichedHeadingSpan.kt +3 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/interfaces/EnrichedInlineSpan.kt +3 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/interfaces/EnrichedParagraphSpan.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/interfaces/EnrichedSpan.kt +3 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/interfaces/EnrichedZeroWidthSpaceSpan.kt +2 -3
- package/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputConnectionWrapper.kt +140 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputSpannableFactory.kt +83 -0
- package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputView.kt → textinput/EnrichedTextInputView.kt} +322 -157
- package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputViewLayoutManager.kt → textinput/EnrichedTextInputViewLayoutManager.kt} +4 -2
- package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputViewManager.kt → textinput/EnrichedTextInputViewManager.kt} +182 -66
- package/android/src/main/java/com/swmansion/enriched/{MeasurementStore.kt → textinput/MeasurementStore.kt} +75 -25
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/MentionHandler.kt +22 -12
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnChangeHtmlEvent.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnChangeSelectionEvent.kt +11 -10
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnChangeStateEvent.kt +21 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnChangeTextEvent.kt +30 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnInputBlurEvent.kt +25 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnInputFocusEvent.kt +25 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnInputKeyPressEvent.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnLinkDetectedEvent.kt +32 -0
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnMentionDetectedEvent.kt +11 -10
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnMentionEvent.kt +10 -9
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnPasteImagesEvent.kt +47 -0
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnRequestHtmlResultEvent.kt +2 -3
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputBlockQuoteSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputBoldSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputCheckboxListSpan.kt +15 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputCodeBlockSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH1Span.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH2Span.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH3Span.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH4Span.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH5Span.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH6Span.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputImageSpan.kt +36 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputInlineCodeSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputItalicSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputLinkSpan.kt +15 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputMentionSpan.kt +18 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputOrderedListSpan.kt +21 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputStrikeThroughSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputUnderlineSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputUnorderedListSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedSpans.kt +241 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/interfaces/EnrichedInputSpan.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/HtmlStyle.kt +129 -57
- package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/InlineStyles.kt +30 -13
- package/android/src/main/java/com/swmansion/enriched/textinput/styles/ListStyles.kt +263 -0
- package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/ParagraphStyles.kt +94 -34
- package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/ParametrizedStyles.kt +143 -67
- package/android/src/main/java/com/swmansion/enriched/textinput/utils/EnrichedEditableFactory.kt +17 -0
- package/android/src/main/java/com/swmansion/enriched/{utils → textinput/utils}/EnrichedSelection.kt +84 -54
- package/android/src/main/java/com/swmansion/enriched/textinput/utils/EnrichedSpanState.kt +304 -0
- package/android/src/main/java/com/swmansion/enriched/{utils/Utils.kt → textinput/utils/EnrichedSpannable.kt} +22 -31
- package/android/src/main/java/com/swmansion/enriched/textinput/utils/EnrichedSpannableStringBuilder.kt +16 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/utils/RichContentReceiver.kt +127 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/utils/Utils.kt +106 -0
- package/android/src/main/java/com/swmansion/enriched/{watchers → textinput/watchers}/EnrichedSpanWatcher.kt +56 -24
- package/android/src/main/java/com/swmansion/enriched/{watchers → textinput/watchers}/EnrichedTextWatcher.kt +37 -14
- package/android/src/main/new_arch/CMakeLists.txt +7 -1
- package/android/src/main/new_arch/ReactNativeEnrichedSpec.cpp +11 -0
- package/android/src/main/new_arch/ReactNativeEnrichedSpec.h +15 -0
- package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputMeasurementManager.h +1 -1
- package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputShadowNode.h +2 -2
- package/android/src/main/new_arch/react/renderer/components/ReactNativeEnrichedSpec/conversions.h +46 -0
- package/ios/EnrichedTextInputView.h +2 -1
- package/ios/EnrichedTextInputView.mm +603 -60
- package/ios/config/InputConfig.h +28 -0
- package/ios/config/InputConfig.mm +237 -8
- package/ios/extensions/ImageExtension.h +35 -0
- package/ios/extensions/ImageExtension.mm +156 -0
- package/ios/{utils → extensions}/LayoutManagerExtension.mm +115 -95
- package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ComponentDescriptors.cpp +1 -1
- package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ComponentDescriptors.h +1 -1
- package/ios/generated/ReactNativeEnrichedSpec/EventEmitters.cpp +276 -0
- package/ios/generated/ReactNativeEnrichedSpec/EventEmitters.h +239 -0
- package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.cpp +10 -0
- package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.h +251 -0
- package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/RCTComponentViewHelpers.h +95 -0
- package/ios/inputParser/InputParser.mm +218 -18
- package/ios/inputTextView/InputTextView.mm +118 -0
- package/ios/{attachments → interfaces}/ImageAttachment.h +1 -0
- package/ios/interfaces/ImageAttachment.mm +46 -0
- package/ios/interfaces/LinkRegexConfig.h +19 -0
- package/ios/interfaces/LinkRegexConfig.mm +37 -0
- package/ios/{utils → interfaces}/MentionStyleProps.mm +2 -2
- package/ios/{utils → interfaces}/StyleHeaders.h +22 -1
- package/ios/{utils → interfaces}/StyleTypeEnum.h +4 -0
- package/ios/internals/EnrichedTextInputViewState.cpp +6 -6
- package/ios/styles/BlockQuoteStyle.mm +5 -5
- package/ios/styles/BoldStyle.mm +21 -6
- package/ios/styles/CheckboxListStyle.mm +321 -0
- package/ios/styles/CodeBlockStyle.mm +5 -5
- package/ios/styles/H1Style.mm +3 -0
- package/ios/styles/H2Style.mm +3 -0
- package/ios/styles/H3Style.mm +3 -0
- package/ios/styles/H4Style.mm +20 -0
- package/ios/styles/H5Style.mm +20 -0
- package/ios/styles/H6Style.mm +20 -0
- package/ios/styles/HeadingStyleBase.mm +161 -72
- package/ios/styles/ImageStyle.mm +5 -5
- package/ios/styles/InlineCodeStyle.mm +30 -19
- package/ios/styles/ItalicStyle.mm +5 -5
- package/ios/styles/LinkStyle.mm +98 -40
- package/ios/styles/MentionStyle.mm +4 -4
- package/ios/styles/OrderedListStyle.mm +5 -5
- package/ios/styles/StrikethroughStyle.mm +5 -5
- package/ios/styles/UnderlineStyle.mm +5 -5
- package/ios/styles/UnorderedListStyle.mm +5 -5
- package/ios/utils/CheckboxHitTestUtils.h +10 -0
- package/ios/utils/CheckboxHitTestUtils.mm +123 -0
- package/ios/utils/ParagraphAttributesUtils.h +4 -0
- package/ios/utils/ParagraphAttributesUtils.mm +142 -45
- package/ios/utils/ParagraphsUtils.mm +4 -4
- package/ios/utils/TextBlockTapGestureRecognizer.h +17 -0
- package/ios/utils/TextBlockTapGestureRecognizer.mm +56 -0
- package/ios/utils/ZeroWidthSpaceUtils.mm +14 -3
- package/lib/module/EnrichedTextInput.js +57 -11
- package/lib/module/EnrichedTextInput.js.map +1 -1
- package/lib/module/{EnrichedTextInputNativeComponent.ts → spec/EnrichedTextInputNativeComponent.ts} +175 -18
- package/lib/module/types.js +4 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/{normalizeHtmlStyle.js → utils/normalizeHtmlStyle.js} +18 -0
- package/lib/module/utils/normalizeHtmlStyle.js.map +1 -0
- package/lib/module/utils/nullthrows.js +9 -0
- package/lib/module/utils/nullthrows.js.map +1 -0
- package/lib/module/utils/regexParser.js +46 -0
- package/lib/module/utils/regexParser.js.map +1 -0
- package/lib/typescript/src/EnrichedTextInput.d.ts +20 -51
- package/lib/typescript/src/EnrichedTextInput.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/{EnrichedTextInputNativeComponent.d.ts → spec/EnrichedTextInputNativeComponent.d.ts} +154 -18
- package/lib/typescript/src/spec/EnrichedTextInputNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +58 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils/normalizeHtmlStyle.d.ts +4 -0
- package/lib/typescript/src/utils/normalizeHtmlStyle.d.ts.map +1 -0
- package/lib/typescript/src/utils/nullthrows.d.ts +2 -0
- package/lib/typescript/src/utils/nullthrows.d.ts.map +1 -0
- package/lib/typescript/src/utils/regexParser.d.ts +3 -0
- package/lib/typescript/src/utils/regexParser.d.ts.map +1 -0
- package/package.json +13 -9
- package/src/EnrichedTextInput.tsx +88 -63
- package/src/index.tsx +5 -1
- package/src/{EnrichedTextInputNativeComponent.ts → spec/EnrichedTextInputNativeComponent.ts} +175 -18
- package/src/types.ts +59 -0
- package/src/{normalizeHtmlStyle.ts → utils/normalizeHtmlStyle.ts} +20 -5
- package/src/utils/nullthrows.ts +7 -0
- package/src/utils/regexParser.ts +56 -0
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.cpp +0 -128
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.h +0 -102
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeHtmlEvent.kt +0 -28
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeStateEvent.kt +0 -24
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeTextEvent.kt +0 -30
- package/android/src/main/java/com/swmansion/enriched/events/OnInputBlurEvent.kt +0 -27
- package/android/src/main/java/com/swmansion/enriched/events/OnInputFocusEvent.kt +0 -27
- package/android/src/main/java/com/swmansion/enriched/events/OnLinkDetectedEvent.kt +0 -30
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBlockQuoteSpan.kt +0 -44
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt +0 -16
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH1Span.kt +0 -23
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH2Span.kt +0 -23
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH3Span.kt +0 -23
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedInlineCodeSpan.kt +0 -27
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt +0 -15
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedLinkSpan.kt +0 -30
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedMentionSpan.kt +0 -42
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedSpans.kt +0 -136
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt +0 -14
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt +0 -14
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedBlockSpan.kt +0 -4
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedHeadingSpan.kt +0 -4
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedInlineSpan.kt +0 -4
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedParagraphSpan.kt +0 -4
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedSpan.kt +0 -8
- package/android/src/main/java/com/swmansion/enriched/styles/ListStyles.kt +0 -172
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSpanState.kt +0 -204
- package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.cpp +0 -22
- package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.h +0 -26
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/conversions.h +0 -26
- package/ios/attachments/ImageAttachment.mm +0 -34
- package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.cpp +0 -128
- package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.h +0 -102
- package/lib/module/normalizeHtmlStyle.js.map +0 -1
- package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts.map +0 -1
- package/lib/typescript/src/normalizeHtmlStyle.d.ts +0 -4
- package/lib/typescript/src/normalizeHtmlStyle.d.ts.map +0 -1
- /package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ShadowNodes.cpp +0 -0
- /package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ShadowNodes.h +0 -0
- /package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/States.cpp +0 -0
- /package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/States.h +0 -0
- /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputComponentDescriptor.h +0 -0
- /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputMeasurementManager.cpp +0 -0
- /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputShadowNode.cpp +0 -0
- /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputState.cpp +0 -0
- /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputState.h +0 -0
- /package/ios/{utils → extensions}/ColorExtension.h +0 -0
- /package/ios/{utils → extensions}/ColorExtension.mm +0 -0
- /package/ios/{utils → extensions}/FontExtension.h +0 -0
- /package/ios/{utils → extensions}/FontExtension.mm +0 -0
- /package/ios/{utils → extensions}/LayoutManagerExtension.h +0 -0
- /package/ios/{utils → extensions}/StringExtension.h +0 -0
- /package/ios/{utils → extensions}/StringExtension.mm +0 -0
- /package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ShadowNodes.cpp +0 -0
- /package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ShadowNodes.h +0 -0
- /package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/States.cpp +0 -0
- /package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/States.h +0 -0
- /package/ios/{utils → interfaces}/BaseStyleProtocol.h +0 -0
- /package/ios/{utils → interfaces}/ImageData.h +0 -0
- /package/ios/{utils → interfaces}/ImageData.mm +0 -0
- /package/ios/{utils → interfaces}/LinkData.h +0 -0
- /package/ios/{utils → interfaces}/LinkData.mm +0 -0
- /package/ios/{attachments → interfaces}/MediaAttachment.h +0 -0
- /package/ios/{attachments → interfaces}/MediaAttachment.mm +0 -0
- /package/ios/{utils → interfaces}/MentionParams.h +0 -0
- /package/ios/{utils → interfaces}/MentionParams.mm +0 -0
- /package/ios/{utils → interfaces}/MentionStyleProps.h +0 -0
- /package/ios/{utils → interfaces}/StylePair.h +0 -0
- /package/ios/{utils → interfaces}/StylePair.mm +0 -0
- /package/ios/{utils → interfaces}/TextDecorationLineEnum.h +0 -0
- /package/ios/{utils → interfaces}/TextDecorationLineEnum.mm +0 -0
package/android/src/main/java/com/swmansion/enriched/{utils → common/parser}/EnrichedParser.java
RENAMED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
package com.swmansion.enriched.
|
|
1
|
+
package com.swmansion.enriched.common.parser;
|
|
2
2
|
|
|
3
|
-
import android.graphics.drawable.Drawable;
|
|
4
3
|
import android.text.Editable;
|
|
5
4
|
import android.text.Layout;
|
|
6
5
|
import android.text.Spannable;
|
|
@@ -9,28 +8,33 @@ import android.text.Spanned;
|
|
|
9
8
|
import android.text.TextUtils;
|
|
10
9
|
import android.text.style.AlignmentSpan;
|
|
11
10
|
import android.text.style.ParagraphStyle;
|
|
12
|
-
|
|
13
|
-
import com.swmansion.enriched.spans.
|
|
14
|
-
import com.swmansion.enriched.spans.
|
|
15
|
-
import com.swmansion.enriched.spans.EnrichedCodeBlockSpan;
|
|
16
|
-
import com.swmansion.enriched.spans.EnrichedH1Span;
|
|
17
|
-
import com.swmansion.enriched.spans.EnrichedH2Span;
|
|
18
|
-
import com.swmansion.enriched.spans.EnrichedH3Span;
|
|
19
|
-
import com.swmansion.enriched.spans.
|
|
20
|
-
import com.swmansion.enriched.spans.
|
|
21
|
-
import com.swmansion.enriched.spans.
|
|
22
|
-
import com.swmansion.enriched.spans.
|
|
23
|
-
import com.swmansion.enriched.spans.
|
|
24
|
-
import com.swmansion.enriched.spans.
|
|
25
|
-
import com.swmansion.enriched.spans.
|
|
26
|
-
import com.swmansion.enriched.spans.
|
|
27
|
-
import com.swmansion.enriched.spans.
|
|
28
|
-
import com.swmansion.enriched.spans.
|
|
29
|
-
import com.swmansion.enriched.spans.
|
|
30
|
-
import com.swmansion.enriched.spans.
|
|
31
|
-
import com.swmansion.enriched.spans.interfaces.
|
|
32
|
-
import com.swmansion.enriched.
|
|
33
|
-
|
|
11
|
+
import com.swmansion.enriched.common.EnrichedConstants;
|
|
12
|
+
import com.swmansion.enriched.common.spans.EnrichedBoldSpan;
|
|
13
|
+
import com.swmansion.enriched.common.spans.EnrichedCheckboxListSpan;
|
|
14
|
+
import com.swmansion.enriched.common.spans.EnrichedCodeBlockSpan;
|
|
15
|
+
import com.swmansion.enriched.common.spans.EnrichedH1Span;
|
|
16
|
+
import com.swmansion.enriched.common.spans.EnrichedH2Span;
|
|
17
|
+
import com.swmansion.enriched.common.spans.EnrichedH3Span;
|
|
18
|
+
import com.swmansion.enriched.common.spans.EnrichedH4Span;
|
|
19
|
+
import com.swmansion.enriched.common.spans.EnrichedH5Span;
|
|
20
|
+
import com.swmansion.enriched.common.spans.EnrichedH6Span;
|
|
21
|
+
import com.swmansion.enriched.common.spans.EnrichedImageSpan;
|
|
22
|
+
import com.swmansion.enriched.common.spans.EnrichedInlineCodeSpan;
|
|
23
|
+
import com.swmansion.enriched.common.spans.EnrichedItalicSpan;
|
|
24
|
+
import com.swmansion.enriched.common.spans.EnrichedLinkSpan;
|
|
25
|
+
import com.swmansion.enriched.common.spans.EnrichedMentionSpan;
|
|
26
|
+
import com.swmansion.enriched.common.spans.EnrichedOrderedListSpan;
|
|
27
|
+
import com.swmansion.enriched.common.spans.EnrichedStrikeThroughSpan;
|
|
28
|
+
import com.swmansion.enriched.common.spans.EnrichedUnderlineSpan;
|
|
29
|
+
import com.swmansion.enriched.common.spans.EnrichedUnorderedListSpan;
|
|
30
|
+
import com.swmansion.enriched.common.spans.interfaces.EnrichedBlockSpan;
|
|
31
|
+
import com.swmansion.enriched.common.spans.interfaces.EnrichedInlineSpan;
|
|
32
|
+
import com.swmansion.enriched.common.spans.interfaces.EnrichedParagraphSpan;
|
|
33
|
+
import com.swmansion.enriched.common.spans.interfaces.EnrichedZeroWidthSpaceSpan;
|
|
34
|
+
import java.io.IOException;
|
|
35
|
+
import java.io.StringReader;
|
|
36
|
+
import java.util.HashMap;
|
|
37
|
+
import java.util.Map;
|
|
34
38
|
import org.ccil.cowan.tagsoup.HTMLSchema;
|
|
35
39
|
import org.ccil.cowan.tagsoup.Parser;
|
|
36
40
|
import org.xml.sax.Attributes;
|
|
@@ -42,50 +46,24 @@ import org.xml.sax.SAXNotRecognizedException;
|
|
|
42
46
|
import org.xml.sax.SAXNotSupportedException;
|
|
43
47
|
import org.xml.sax.XMLReader;
|
|
44
48
|
|
|
45
|
-
import java.io.IOException;
|
|
46
|
-
import java.io.StringReader;
|
|
47
|
-
import java.util.HashMap;
|
|
48
|
-
import java.util.Map;
|
|
49
|
-
|
|
50
49
|
/**
|
|
51
50
|
* Most of the code in this file is copied from the Android source code and adjusted to our needs.
|
|
52
|
-
* For the reference see <a
|
|
51
|
+
* For the reference see <a
|
|
52
|
+
* href="https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/text/Html.java">docs</a>
|
|
53
53
|
*/
|
|
54
54
|
public class EnrichedParser {
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
*/
|
|
58
|
-
public interface ImageGetter {
|
|
59
|
-
/**
|
|
60
|
-
* This method is called when the HTML parser encounters an
|
|
61
|
-
* <img> tag. The <code>source</code> argument is the
|
|
62
|
-
* string from the "src" attribute; the return value should be
|
|
63
|
-
* a Drawable representation of the image or <code>null</code>
|
|
64
|
-
* for a generic replacement image. Make sure you call
|
|
65
|
-
* setBounds() on your Drawable if it doesn't already have
|
|
66
|
-
* its bounds set.
|
|
67
|
-
*/
|
|
68
|
-
Drawable getDrawable(String source);
|
|
69
|
-
}
|
|
55
|
+
/** Retrieves images for HTML <img> tags. */
|
|
56
|
+
private EnrichedParser() {}
|
|
70
57
|
|
|
71
|
-
private EnrichedParser() { }
|
|
72
58
|
/**
|
|
73
|
-
* Lazy initialization holder for HTML parser. This class will
|
|
74
|
-
*
|
|
75
|
-
* necessary.
|
|
59
|
+
* Lazy initialization holder for HTML parser. This class will a) be preloaded by the zygote, or
|
|
60
|
+
* b) not loaded until absolutely necessary.
|
|
76
61
|
*/
|
|
77
62
|
private static class HtmlParser {
|
|
78
63
|
private static final HTMLSchema schema = new HTMLSchema();
|
|
79
64
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
* HTML will use the specified ImageGetter to request a representation of the image (use null
|
|
83
|
-
* if you don't want this) and the specified TagHandler to handle unknown tags (specify null if
|
|
84
|
-
* you don't want this).
|
|
85
|
-
*
|
|
86
|
-
* <p>This uses TagSoup to handle real HTML, including all of the brokenness found in the wild.
|
|
87
|
-
*/
|
|
88
|
-
public static Spanned fromHtml(String source, HtmlStyle style, ImageGetter imageGetter) {
|
|
65
|
+
|
|
66
|
+
public static <T> Spanned fromHtml(String source, T style, EnrichedSpanFactory<T> spanFactory) {
|
|
89
67
|
Parser parser = new Parser();
|
|
90
68
|
try {
|
|
91
69
|
parser.setProperty(Parser.schemaProperty, HtmlParser.schema);
|
|
@@ -93,16 +71,19 @@ public class EnrichedParser {
|
|
|
93
71
|
// Should not happen.
|
|
94
72
|
throw new RuntimeException(e);
|
|
95
73
|
}
|
|
96
|
-
HtmlToSpannedConverter converter =
|
|
74
|
+
HtmlToSpannedConverter converter =
|
|
75
|
+
new HtmlToSpannedConverter(source, style, parser, spanFactory);
|
|
97
76
|
return converter.convert();
|
|
98
77
|
}
|
|
78
|
+
|
|
99
79
|
public static String toHtml(Spanned text) {
|
|
100
80
|
StringBuilder out = new StringBuilder();
|
|
101
81
|
withinHtml(out, text);
|
|
102
82
|
String outString = out.toString();
|
|
103
83
|
// Codeblocks and blockquotes appends a newline character by default, so we have to remove it
|
|
104
84
|
String normalizedCodeBlock = outString.replaceAll("</codeblock>\\n<br>", "</codeblock>");
|
|
105
|
-
String normalizedBlockQuote =
|
|
85
|
+
String normalizedBlockQuote =
|
|
86
|
+
normalizedCodeBlock.replaceAll("</blockquote>\\n<br>", "</blockquote>");
|
|
106
87
|
return "<html>\n" + normalizedBlockQuote + "</html>";
|
|
107
88
|
}
|
|
108
89
|
|
|
@@ -113,24 +94,24 @@ public class EnrichedParser {
|
|
|
113
94
|
return "<html>\n<p></p>\n</html>";
|
|
114
95
|
}
|
|
115
96
|
|
|
116
|
-
/**
|
|
117
|
-
* Returns an HTML escaped representation of the given plain text.
|
|
118
|
-
*/
|
|
97
|
+
/** Returns an HTML escaped representation of the given plain text. */
|
|
119
98
|
public static String escapeHtml(CharSequence text) {
|
|
120
99
|
StringBuilder out = new StringBuilder();
|
|
121
100
|
withinStyle(out, text, 0, text.length());
|
|
122
101
|
return out.toString();
|
|
123
102
|
}
|
|
103
|
+
|
|
124
104
|
private static void withinHtml(StringBuilder out, Spanned text) {
|
|
125
105
|
withinDiv(out, text, 0, text.length());
|
|
126
106
|
}
|
|
107
|
+
|
|
127
108
|
private static void withinDiv(StringBuilder out, Spanned text, int start, int end) {
|
|
128
109
|
int next;
|
|
129
110
|
for (int i = start; i < end; i = next) {
|
|
130
111
|
next = text.nextSpanTransition(i, end, EnrichedBlockSpan.class);
|
|
131
112
|
EnrichedBlockSpan[] blocks = text.getSpans(i, next, EnrichedBlockSpan.class);
|
|
132
113
|
String tag = "unknown";
|
|
133
|
-
if (blocks.length > 0){
|
|
114
|
+
if (blocks.length > 0) {
|
|
134
115
|
tag = blocks[0] instanceof EnrichedCodeBlockSpan ? "codeblock" : "blockquote";
|
|
135
116
|
}
|
|
136
117
|
|
|
@@ -149,26 +130,38 @@ public class EnrichedParser {
|
|
|
149
130
|
}
|
|
150
131
|
}
|
|
151
132
|
}
|
|
133
|
+
|
|
152
134
|
private static String getBlockTag(EnrichedParagraphSpan[] spans) {
|
|
153
135
|
for (EnrichedParagraphSpan span : spans) {
|
|
154
136
|
if (span instanceof EnrichedUnorderedListSpan) {
|
|
155
137
|
return "ul";
|
|
156
138
|
} else if (span instanceof EnrichedOrderedListSpan) {
|
|
157
139
|
return "ol";
|
|
140
|
+
} else if (span instanceof EnrichedCheckboxListSpan) {
|
|
141
|
+
return "ul data-type=\"checkbox\"";
|
|
158
142
|
} else if (span instanceof EnrichedH1Span) {
|
|
159
143
|
return "h1";
|
|
160
144
|
} else if (span instanceof EnrichedH2Span) {
|
|
161
145
|
return "h2";
|
|
162
146
|
} else if (span instanceof EnrichedH3Span) {
|
|
163
147
|
return "h3";
|
|
148
|
+
} else if (span instanceof EnrichedH4Span) {
|
|
149
|
+
return "h4";
|
|
150
|
+
} else if (span instanceof EnrichedH5Span) {
|
|
151
|
+
return "h5";
|
|
152
|
+
} else if (span instanceof EnrichedH6Span) {
|
|
153
|
+
return "h6";
|
|
164
154
|
}
|
|
165
155
|
}
|
|
166
156
|
|
|
167
157
|
return "p";
|
|
168
158
|
}
|
|
159
|
+
|
|
169
160
|
private static void withinBlock(StringBuilder out, Spanned text, int start, int end) {
|
|
170
161
|
boolean isInUlList = false;
|
|
171
162
|
boolean isInOlList = false;
|
|
163
|
+
boolean isInCheckboxList = false;
|
|
164
|
+
|
|
172
165
|
int next;
|
|
173
166
|
for (int i = start; i <= end; i = next) {
|
|
174
167
|
next = TextUtils.indexOf(text, '\n', i, end);
|
|
@@ -184,13 +177,19 @@ public class EnrichedParser {
|
|
|
184
177
|
// Current paragraph is no longer a list item; close the previously opened list
|
|
185
178
|
isInOlList = false;
|
|
186
179
|
out.append("</ol>\n");
|
|
180
|
+
} else if (isInCheckboxList) {
|
|
181
|
+
// Current paragraph is no longer a list item; close the previously opened list
|
|
182
|
+
isInCheckboxList = false;
|
|
183
|
+
out.append("</ul>\n");
|
|
187
184
|
}
|
|
188
185
|
out.append("<br>\n");
|
|
189
186
|
} else {
|
|
190
|
-
EnrichedParagraphSpan[] paragraphStyles =
|
|
187
|
+
EnrichedParagraphSpan[] paragraphStyles =
|
|
188
|
+
text.getSpans(i, next, EnrichedParagraphSpan.class);
|
|
191
189
|
String tag = getBlockTag(paragraphStyles);
|
|
192
190
|
boolean isUlListItem = tag.equals("ul");
|
|
193
191
|
boolean isOlListItem = tag.equals("ol");
|
|
192
|
+
boolean isCheckboxListItem = tag.equals("ul data-type=\"checkbox\"");
|
|
194
193
|
|
|
195
194
|
if (isInUlList && !isUlListItem) {
|
|
196
195
|
// Current paragraph is no longer a list item; close the previously opened list
|
|
@@ -200,6 +199,10 @@ public class EnrichedParser {
|
|
|
200
199
|
// Current paragraph is no longer a list item; close the previously opened list
|
|
201
200
|
isInOlList = false;
|
|
202
201
|
out.append("</ol>\n");
|
|
202
|
+
} else if (isInCheckboxList && !isCheckboxListItem) {
|
|
203
|
+
// Current paragraph is no longer a list item; close the previously opened list
|
|
204
|
+
isInCheckboxList = false;
|
|
205
|
+
out.append("</ul>\n");
|
|
203
206
|
}
|
|
204
207
|
|
|
205
208
|
if (isUlListItem && !isInUlList) {
|
|
@@ -210,14 +213,27 @@ public class EnrichedParser {
|
|
|
210
213
|
// Current paragraph is the first item in a list
|
|
211
214
|
isInOlList = true;
|
|
212
215
|
out.append("<ol").append(">\n");
|
|
216
|
+
} else if (isCheckboxListItem && !isInCheckboxList) {
|
|
217
|
+
// Current paragraph is the first item in a list
|
|
218
|
+
isInCheckboxList = true;
|
|
219
|
+
out.append("<ul data-type=\"checkbox\">\n");
|
|
213
220
|
}
|
|
214
221
|
|
|
215
|
-
boolean isList = isUlListItem || isOlListItem;
|
|
222
|
+
boolean isList = isUlListItem || isOlListItem || isCheckboxListItem;
|
|
216
223
|
String tagType = isList ? "li" : tag;
|
|
217
|
-
out.append("<");
|
|
218
224
|
|
|
225
|
+
out.append("<");
|
|
219
226
|
out.append(tagType);
|
|
220
227
|
|
|
228
|
+
if (isCheckboxListItem) {
|
|
229
|
+
EnrichedCheckboxListSpan[] checkboxSpans =
|
|
230
|
+
text.getSpans(i, next, EnrichedCheckboxListSpan.class);
|
|
231
|
+
if (checkboxSpans.length > 0) {
|
|
232
|
+
boolean isChecked = checkboxSpans[0].isChecked();
|
|
233
|
+
if (isChecked) out.append(" checked");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
221
237
|
out.append(">");
|
|
222
238
|
withinParagraph(out, text, i, next);
|
|
223
239
|
out.append("</");
|
|
@@ -229,11 +245,15 @@ public class EnrichedParser {
|
|
|
229
245
|
} else if (next == end && isInOlList) {
|
|
230
246
|
isInOlList = false;
|
|
231
247
|
out.append("</ol>\n");
|
|
248
|
+
} else if (next == end && isInCheckboxList) {
|
|
249
|
+
isInCheckboxList = false;
|
|
250
|
+
out.append("</ul>\n");
|
|
232
251
|
}
|
|
233
252
|
}
|
|
234
253
|
next++;
|
|
235
254
|
}
|
|
236
255
|
}
|
|
256
|
+
|
|
237
257
|
private static void withinParagraph(StringBuilder out, Spanned text, int start, int end) {
|
|
238
258
|
int next;
|
|
239
259
|
for (int i = start; i < end; i = next) {
|
|
@@ -323,11 +343,11 @@ public class EnrichedParser {
|
|
|
323
343
|
}
|
|
324
344
|
}
|
|
325
345
|
}
|
|
326
|
-
|
|
327
|
-
|
|
346
|
+
|
|
347
|
+
private static void withinStyle(StringBuilder out, CharSequence text, int start, int end) {
|
|
328
348
|
for (int i = start; i < end; i++) {
|
|
329
349
|
char c = text.charAt(i);
|
|
330
|
-
if (c ==
|
|
350
|
+
if (c == EnrichedConstants.ZWS) {
|
|
331
351
|
// Do not output zero-width space characters.
|
|
332
352
|
continue;
|
|
333
353
|
} else if (c == '<') {
|
|
@@ -359,22 +379,25 @@ public class EnrichedParser {
|
|
|
359
379
|
}
|
|
360
380
|
}
|
|
361
381
|
}
|
|
362
|
-
|
|
363
|
-
|
|
382
|
+
|
|
383
|
+
class HtmlToSpannedConverter<T> implements ContentHandler {
|
|
384
|
+
private final EnrichedSpanFactory<T> mSpanFactory;
|
|
385
|
+
private final T mStyle;
|
|
364
386
|
private final String mSource;
|
|
365
387
|
private final XMLReader mReader;
|
|
366
388
|
private final SpannableStringBuilder mSpannableStringBuilder;
|
|
367
|
-
private final EnrichedParser.ImageGetter mImageGetter;
|
|
368
389
|
private static Integer currentOrderedListItemIndex = 0;
|
|
369
390
|
private static Boolean isInOrderedList = false;
|
|
391
|
+
private static Boolean isInCheckboxList = false;
|
|
370
392
|
private static Boolean isEmptyTag = false;
|
|
371
393
|
|
|
372
|
-
public HtmlToSpannedConverter(
|
|
394
|
+
public HtmlToSpannedConverter(
|
|
395
|
+
String source, T style, Parser parser, EnrichedSpanFactory<T> spanFactory) {
|
|
373
396
|
mStyle = style;
|
|
374
397
|
mSource = source;
|
|
375
398
|
mSpannableStringBuilder = new SpannableStringBuilder();
|
|
376
|
-
mImageGetter = imageGetter;
|
|
377
399
|
mReader = parser;
|
|
400
|
+
mSpanFactory = spanFactory;
|
|
378
401
|
}
|
|
379
402
|
|
|
380
403
|
public Spanned convert() {
|
|
@@ -389,14 +412,15 @@ class HtmlToSpannedConverter implements ContentHandler {
|
|
|
389
412
|
throw new RuntimeException(e);
|
|
390
413
|
}
|
|
391
414
|
// Fix flags and range for paragraph-type markup.
|
|
392
|
-
Object[] obj =
|
|
415
|
+
Object[] obj =
|
|
416
|
+
mSpannableStringBuilder.getSpans(0, mSpannableStringBuilder.length(), ParagraphStyle.class);
|
|
393
417
|
for (int i = 0; i < obj.length; i++) {
|
|
394
418
|
int start = mSpannableStringBuilder.getSpanStart(obj[i]);
|
|
395
419
|
int end = mSpannableStringBuilder.getSpanEnd(obj[i]);
|
|
396
420
|
// If the last line of the range is blank, back off by one.
|
|
397
421
|
if (end - 2 >= 0) {
|
|
398
|
-
if (mSpannableStringBuilder.charAt(end - 1) == '\n'
|
|
399
|
-
|
|
422
|
+
if (mSpannableStringBuilder.charAt(end - 1) == '\n'
|
|
423
|
+
&& mSpannableStringBuilder.charAt(end - 2) == '\n') {
|
|
400
424
|
end--;
|
|
401
425
|
}
|
|
402
426
|
}
|
|
@@ -404,25 +428,29 @@ class HtmlToSpannedConverter implements ContentHandler {
|
|
|
404
428
|
mSpannableStringBuilder.removeSpan(obj[i]);
|
|
405
429
|
} else {
|
|
406
430
|
// TODO: verify if Spannable.SPAN_EXCLUSIVE_EXCLUSIVE does not break anything.
|
|
407
|
-
// Previously it was SPAN_PARAGRAPH. I've changed that in order to fix ranges for list
|
|
431
|
+
// Previously it was SPAN_PARAGRAPH. I've changed that in order to fix ranges for list
|
|
432
|
+
// items.
|
|
408
433
|
mSpannableStringBuilder.setSpan(obj[i], start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
409
434
|
}
|
|
410
435
|
}
|
|
411
436
|
|
|
412
437
|
// Assign zero-width space character to the proper spans.
|
|
413
|
-
EnrichedZeroWidthSpaceSpan[] zeroWidthSpaceSpans =
|
|
438
|
+
EnrichedZeroWidthSpaceSpan[] zeroWidthSpaceSpans =
|
|
439
|
+
mSpannableStringBuilder.getSpans(
|
|
440
|
+
0, mSpannableStringBuilder.length(), EnrichedZeroWidthSpaceSpan.class);
|
|
414
441
|
for (EnrichedZeroWidthSpaceSpan zeroWidthSpaceSpan : zeroWidthSpaceSpans) {
|
|
415
442
|
int start = mSpannableStringBuilder.getSpanStart(zeroWidthSpaceSpan);
|
|
416
443
|
int end = mSpannableStringBuilder.getSpanEnd(zeroWidthSpaceSpan);
|
|
417
444
|
|
|
418
|
-
if (mSpannableStringBuilder.charAt(start) !=
|
|
445
|
+
if (mSpannableStringBuilder.charAt(start) != EnrichedConstants.ZWS) {
|
|
419
446
|
// Insert zero-width space character at the start if it's not already present.
|
|
420
|
-
mSpannableStringBuilder.insert(start,
|
|
447
|
+
mSpannableStringBuilder.insert(start, EnrichedConstants.ZWS_STRING);
|
|
421
448
|
end++; // Adjust end position due to insertion.
|
|
422
449
|
}
|
|
423
450
|
|
|
424
451
|
mSpannableStringBuilder.removeSpan(zeroWidthSpaceSpan);
|
|
425
|
-
mSpannableStringBuilder.setSpan(
|
|
452
|
+
mSpannableStringBuilder.setSpan(
|
|
453
|
+
zeroWidthSpaceSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
426
454
|
}
|
|
427
455
|
|
|
428
456
|
return mSpannableStringBuilder;
|
|
@@ -437,6 +465,8 @@ class HtmlToSpannedConverter implements ContentHandler {
|
|
|
437
465
|
startBlockElement(mSpannableStringBuilder);
|
|
438
466
|
} else if (tag.equalsIgnoreCase("ul")) {
|
|
439
467
|
isInOrderedList = false;
|
|
468
|
+
String dataType = attributes.getValue("", "data-type");
|
|
469
|
+
isInCheckboxList = "checkbox".equals(dataType);
|
|
440
470
|
startBlockElement(mSpannableStringBuilder);
|
|
441
471
|
} else if (tag.equalsIgnoreCase("ol")) {
|
|
442
472
|
isInOrderedList = true;
|
|
@@ -444,7 +474,7 @@ class HtmlToSpannedConverter implements ContentHandler {
|
|
|
444
474
|
startBlockElement(mSpannableStringBuilder);
|
|
445
475
|
} else if (tag.equalsIgnoreCase("li")) {
|
|
446
476
|
isEmptyTag = true;
|
|
447
|
-
startLi(mSpannableStringBuilder);
|
|
477
|
+
startLi(mSpannableStringBuilder, attributes);
|
|
448
478
|
} else if (tag.equalsIgnoreCase("b")) {
|
|
449
479
|
start(mSpannableStringBuilder, new Bold());
|
|
450
480
|
} else if (tag.equalsIgnoreCase("i")) {
|
|
@@ -469,8 +499,14 @@ class HtmlToSpannedConverter implements ContentHandler {
|
|
|
469
499
|
startHeading(mSpannableStringBuilder, 2);
|
|
470
500
|
} else if (tag.equalsIgnoreCase("h3")) {
|
|
471
501
|
startHeading(mSpannableStringBuilder, 3);
|
|
502
|
+
} else if (tag.equalsIgnoreCase("h4")) {
|
|
503
|
+
startHeading(mSpannableStringBuilder, 4);
|
|
504
|
+
} else if (tag.equalsIgnoreCase("h5")) {
|
|
505
|
+
startHeading(mSpannableStringBuilder, 5);
|
|
506
|
+
} else if (tag.equalsIgnoreCase("h6")) {
|
|
507
|
+
startHeading(mSpannableStringBuilder, 6);
|
|
472
508
|
} else if (tag.equalsIgnoreCase("img")) {
|
|
473
|
-
startImg(mSpannableStringBuilder, attributes,
|
|
509
|
+
startImg(mSpannableStringBuilder, attributes, mSpanFactory);
|
|
474
510
|
} else if (tag.equalsIgnoreCase("code")) {
|
|
475
511
|
start(mSpannableStringBuilder, new Code());
|
|
476
512
|
} else if (tag.equalsIgnoreCase("mention")) {
|
|
@@ -486,31 +522,40 @@ class HtmlToSpannedConverter implements ContentHandler {
|
|
|
486
522
|
} else if (tag.equalsIgnoreCase("ul")) {
|
|
487
523
|
endBlockElement(mSpannableStringBuilder);
|
|
488
524
|
} else if (tag.equalsIgnoreCase("li")) {
|
|
489
|
-
endLi(mSpannableStringBuilder, mStyle);
|
|
525
|
+
endLi(mSpannableStringBuilder, mStyle, mSpanFactory);
|
|
490
526
|
} else if (tag.equalsIgnoreCase("b")) {
|
|
491
|
-
end(mSpannableStringBuilder, Bold.class,
|
|
527
|
+
end(mSpannableStringBuilder, Bold.class, mSpanFactory.createBoldSpan(mStyle));
|
|
492
528
|
} else if (tag.equalsIgnoreCase("i")) {
|
|
493
|
-
end(mSpannableStringBuilder, Italic.class,
|
|
529
|
+
end(mSpannableStringBuilder, Italic.class, mSpanFactory.createItalicSpan(mStyle));
|
|
494
530
|
} else if (tag.equalsIgnoreCase("blockquote")) {
|
|
495
|
-
endBlockquote(mSpannableStringBuilder, mStyle);
|
|
531
|
+
endBlockquote(mSpannableStringBuilder, mStyle, mSpanFactory);
|
|
496
532
|
} else if (tag.equalsIgnoreCase("codeblock")) {
|
|
497
|
-
endCodeBlock(mSpannableStringBuilder, mStyle);
|
|
533
|
+
endCodeBlock(mSpannableStringBuilder, mStyle, mSpanFactory);
|
|
498
534
|
} else if (tag.equalsIgnoreCase("a")) {
|
|
499
|
-
endA(mSpannableStringBuilder, mStyle);
|
|
535
|
+
endA(mSpannableStringBuilder, mStyle, mSpanFactory);
|
|
500
536
|
} else if (tag.equalsIgnoreCase("u")) {
|
|
501
|
-
end(mSpannableStringBuilder, Underline.class,
|
|
537
|
+
end(mSpannableStringBuilder, Underline.class, mSpanFactory.createUnderlineSpan(mStyle));
|
|
502
538
|
} else if (tag.equalsIgnoreCase("s")) {
|
|
503
|
-
end(
|
|
539
|
+
end(
|
|
540
|
+
mSpannableStringBuilder,
|
|
541
|
+
Strikethrough.class,
|
|
542
|
+
mSpanFactory.createStrikeThroughSpan(mStyle));
|
|
504
543
|
} else if (tag.equalsIgnoreCase("h1")) {
|
|
505
|
-
endHeading(mSpannableStringBuilder, mStyle, 1);
|
|
544
|
+
endHeading(mSpannableStringBuilder, mStyle, mSpanFactory, 1);
|
|
506
545
|
} else if (tag.equalsIgnoreCase("h2")) {
|
|
507
|
-
endHeading(mSpannableStringBuilder, mStyle, 2);
|
|
546
|
+
endHeading(mSpannableStringBuilder, mStyle, mSpanFactory, 2);
|
|
508
547
|
} else if (tag.equalsIgnoreCase("h3")) {
|
|
509
|
-
endHeading(mSpannableStringBuilder, mStyle, 3);
|
|
548
|
+
endHeading(mSpannableStringBuilder, mStyle, mSpanFactory, 3);
|
|
549
|
+
} else if (tag.equalsIgnoreCase("h4")) {
|
|
550
|
+
endHeading(mSpannableStringBuilder, mStyle, mSpanFactory, 4);
|
|
551
|
+
} else if (tag.equalsIgnoreCase("h5")) {
|
|
552
|
+
endHeading(mSpannableStringBuilder, mStyle, mSpanFactory, 5);
|
|
553
|
+
} else if (tag.equalsIgnoreCase("h6")) {
|
|
554
|
+
endHeading(mSpannableStringBuilder, mStyle, mSpanFactory, 6);
|
|
510
555
|
} else if (tag.equalsIgnoreCase("code")) {
|
|
511
|
-
end(mSpannableStringBuilder, Code.class,
|
|
556
|
+
end(mSpannableStringBuilder, Code.class, mSpanFactory.createInlineCodeSpan(mStyle));
|
|
512
557
|
} else if (tag.equalsIgnoreCase("mention")) {
|
|
513
|
-
endMention(mSpannableStringBuilder, mStyle);
|
|
558
|
+
endMention(mSpannableStringBuilder, mStyle, mSpanFactory);
|
|
514
559
|
}
|
|
515
560
|
}
|
|
516
561
|
|
|
@@ -529,8 +574,8 @@ class HtmlToSpannedConverter implements ContentHandler {
|
|
|
529
574
|
}
|
|
530
575
|
|
|
531
576
|
private static void startBlockElement(Editable text) {
|
|
532
|
-
|
|
533
|
-
|
|
577
|
+
appendNewlines(text, 1);
|
|
578
|
+
start(text, new Newline(1));
|
|
534
579
|
}
|
|
535
580
|
|
|
536
581
|
private static void endBlockElement(Editable text) {
|
|
@@ -549,26 +594,31 @@ class HtmlToSpannedConverter implements ContentHandler {
|
|
|
549
594
|
text.append('\n');
|
|
550
595
|
}
|
|
551
596
|
|
|
552
|
-
private void startLi(Editable text) {
|
|
597
|
+
private void startLi(Editable text, Attributes attributes) {
|
|
553
598
|
startBlockElement(text);
|
|
554
599
|
|
|
555
600
|
if (isInOrderedList) {
|
|
556
601
|
currentOrderedListItemIndex++;
|
|
557
|
-
start(text, new List("
|
|
602
|
+
start(text, new List("ordered", currentOrderedListItemIndex, false));
|
|
603
|
+
} else if (isInCheckboxList) {
|
|
604
|
+
String isChecked = attributes.getValue("", "checked");
|
|
605
|
+
start(text, new List("checked", 0, "checked".equals(isChecked)));
|
|
558
606
|
} else {
|
|
559
|
-
start(text, new List("
|
|
607
|
+
start(text, new List("unordered", 0, false));
|
|
560
608
|
}
|
|
561
609
|
}
|
|
562
610
|
|
|
563
|
-
private static void endLi(Editable text,
|
|
611
|
+
private static <T> void endLi(Editable text, T style, EnrichedSpanFactory<T> spanFactory) {
|
|
564
612
|
endBlockElement(text);
|
|
565
613
|
|
|
566
614
|
List l = getLast(text, List.class);
|
|
567
615
|
if (l != null) {
|
|
568
|
-
if (l.mType.equals("
|
|
569
|
-
setParagraphSpanFromMark(text, l,
|
|
616
|
+
if (l.mType.equals("ordered")) {
|
|
617
|
+
setParagraphSpanFromMark(text, l, spanFactory.createOrderedListSpan(l.mIndex, style));
|
|
618
|
+
} else if (l.mType.equals("checked")) {
|
|
619
|
+
setParagraphSpanFromMark(text, l, spanFactory.createCheckboxListSpan(l.mChecked, style));
|
|
570
620
|
} else {
|
|
571
|
-
setParagraphSpanFromMark(text, l,
|
|
621
|
+
setParagraphSpanFromMark(text, l, spanFactory.createUnorderedListSpan(style));
|
|
572
622
|
}
|
|
573
623
|
}
|
|
574
624
|
|
|
@@ -580,10 +630,11 @@ class HtmlToSpannedConverter implements ContentHandler {
|
|
|
580
630
|
start(text, new Blockquote());
|
|
581
631
|
}
|
|
582
632
|
|
|
583
|
-
private static void endBlockquote(
|
|
633
|
+
private static <T> void endBlockquote(
|
|
634
|
+
Editable text, T style, EnrichedSpanFactory<T> spanFactory) {
|
|
584
635
|
endBlockElement(text);
|
|
585
636
|
Blockquote last = getLast(text, Blockquote.class);
|
|
586
|
-
setParagraphSpanFromMark(text, last,
|
|
637
|
+
setParagraphSpanFromMark(text, last, spanFactory.createBlockQuoteSpan(style));
|
|
587
638
|
}
|
|
588
639
|
|
|
589
640
|
private void startCodeBlock(Editable text) {
|
|
@@ -591,10 +642,10 @@ class HtmlToSpannedConverter implements ContentHandler {
|
|
|
591
642
|
start(text, new CodeBlock());
|
|
592
643
|
}
|
|
593
644
|
|
|
594
|
-
private static void endCodeBlock(Editable text,
|
|
645
|
+
private static <T> void endCodeBlock(Editable text, T style, EnrichedSpanFactory<T> spanFactory) {
|
|
595
646
|
endBlockElement(text);
|
|
596
647
|
CodeBlock last = getLast(text, CodeBlock.class);
|
|
597
|
-
setParagraphSpanFromMark(text, last,
|
|
648
|
+
setParagraphSpanFromMark(text, last, spanFactory.createCodeBlockSpan(style));
|
|
598
649
|
}
|
|
599
650
|
|
|
600
651
|
private void startHeading(Editable text, int level) {
|
|
@@ -610,26 +661,48 @@ class HtmlToSpannedConverter implements ContentHandler {
|
|
|
610
661
|
case 3:
|
|
611
662
|
start(text, new H3());
|
|
612
663
|
break;
|
|
664
|
+
case 4:
|
|
665
|
+
start(text, new H4());
|
|
666
|
+
break;
|
|
667
|
+
case 5:
|
|
668
|
+
start(text, new H5());
|
|
669
|
+
break;
|
|
670
|
+
case 6:
|
|
671
|
+
start(text, new H6());
|
|
672
|
+
break;
|
|
613
673
|
default:
|
|
614
674
|
throw new IllegalArgumentException("Unsupported heading level: " + level);
|
|
615
675
|
}
|
|
616
676
|
}
|
|
617
677
|
|
|
618
|
-
private static void endHeading(
|
|
678
|
+
private static <T> void endHeading(
|
|
679
|
+
Editable text, T style, EnrichedSpanFactory<T> spanFactory, int level) {
|
|
619
680
|
endBlockElement(text);
|
|
620
681
|
|
|
621
682
|
switch (level) {
|
|
622
683
|
case 1:
|
|
623
684
|
H1 lastH1 = getLast(text, H1.class);
|
|
624
|
-
setParagraphSpanFromMark(text, lastH1,
|
|
685
|
+
setParagraphSpanFromMark(text, lastH1, spanFactory.createH1Span(style));
|
|
625
686
|
break;
|
|
626
687
|
case 2:
|
|
627
688
|
H2 lastH2 = getLast(text, H2.class);
|
|
628
|
-
setParagraphSpanFromMark(text, lastH2,
|
|
689
|
+
setParagraphSpanFromMark(text, lastH2, spanFactory.createH2Span(style));
|
|
629
690
|
break;
|
|
630
691
|
case 3:
|
|
631
692
|
H3 lastH3 = getLast(text, H3.class);
|
|
632
|
-
setParagraphSpanFromMark(text, lastH3,
|
|
693
|
+
setParagraphSpanFromMark(text, lastH3, spanFactory.createH3Span(style));
|
|
694
|
+
break;
|
|
695
|
+
case 4:
|
|
696
|
+
H4 lastH4 = getLast(text, H4.class);
|
|
697
|
+
setParagraphSpanFromMark(text, lastH4, spanFactory.createH4Span(style));
|
|
698
|
+
break;
|
|
699
|
+
case 5:
|
|
700
|
+
H5 lastH5 = getLast(text, H5.class);
|
|
701
|
+
setParagraphSpanFromMark(text, lastH5, spanFactory.createH5Span(style));
|
|
702
|
+
break;
|
|
703
|
+
case 6:
|
|
704
|
+
H6 lastH6 = getLast(text, H6.class);
|
|
705
|
+
setParagraphSpanFromMark(text, lastH6, spanFactory.createH6Span(style));
|
|
633
706
|
break;
|
|
634
707
|
default:
|
|
635
708
|
throw new IllegalArgumentException("Unsupported heading level: " + level);
|
|
@@ -667,7 +740,7 @@ class HtmlToSpannedConverter implements ContentHandler {
|
|
|
667
740
|
|
|
668
741
|
// Block spans require at least one character to be applied.
|
|
669
742
|
if (isEmptyTag) {
|
|
670
|
-
text.append(
|
|
743
|
+
text.append(EnrichedConstants.ZWS);
|
|
671
744
|
len++;
|
|
672
745
|
}
|
|
673
746
|
|
|
@@ -695,15 +768,19 @@ class HtmlToSpannedConverter implements ContentHandler {
|
|
|
695
768
|
}
|
|
696
769
|
}
|
|
697
770
|
|
|
698
|
-
private static void startImg(
|
|
771
|
+
private static <T> void startImg(
|
|
772
|
+
Editable text, Attributes attributes, EnrichedSpanFactory<T> spanFactory) {
|
|
699
773
|
String src = attributes.getValue("", "src");
|
|
700
774
|
String width = attributes.getValue("", "width");
|
|
701
775
|
String height = attributes.getValue("", "height");
|
|
702
776
|
|
|
703
777
|
int len = text.length();
|
|
704
|
-
EnrichedImageSpan span = EnrichedImageSpan.Companion.createEnrichedImageSpan(src, Integer.parseInt(width), Integer.parseInt(height));
|
|
705
778
|
text.append("");
|
|
706
|
-
text.setSpan(
|
|
779
|
+
text.setSpan(
|
|
780
|
+
spanFactory.createImageSpan(src, Integer.parseInt(width), Integer.parseInt(height)),
|
|
781
|
+
len,
|
|
782
|
+
text.length(),
|
|
783
|
+
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
707
784
|
}
|
|
708
785
|
|
|
709
786
|
private static void startA(Editable text, Attributes attributes) {
|
|
@@ -711,11 +788,11 @@ class HtmlToSpannedConverter implements ContentHandler {
|
|
|
711
788
|
start(text, new Href(href));
|
|
712
789
|
}
|
|
713
790
|
|
|
714
|
-
private void endA(Editable text,
|
|
791
|
+
private static <T> void endA(Editable text, T style, EnrichedSpanFactory<T> spanFactory) {
|
|
715
792
|
Href h = getLast(text, Href.class);
|
|
716
793
|
if (h != null) {
|
|
717
794
|
if (h.mHref != null) {
|
|
718
|
-
setSpanFromMark(text, h,
|
|
795
|
+
setSpanFromMark(text, h, spanFactory.createLinkSpan(h.mHref, style));
|
|
719
796
|
}
|
|
720
797
|
}
|
|
721
798
|
}
|
|
@@ -736,29 +813,25 @@ class HtmlToSpannedConverter implements ContentHandler {
|
|
|
736
813
|
start(mention, new Mention(indicator, text, attributesMap));
|
|
737
814
|
}
|
|
738
815
|
|
|
739
|
-
private void endMention(Editable text,
|
|
816
|
+
private static <T> void endMention(Editable text, T style, EnrichedSpanFactory<T> spanFactory) {
|
|
740
817
|
Mention m = getLast(text, Mention.class);
|
|
741
818
|
|
|
742
819
|
if (m == null) return;
|
|
743
820
|
if (m.mText == null) return;
|
|
744
821
|
|
|
745
|
-
setSpanFromMark(
|
|
822
|
+
setSpanFromMark(
|
|
823
|
+
text, m, spanFactory.createMentionSpan(m.mText, m.mIndicator, m.mAttributes, style));
|
|
746
824
|
}
|
|
747
825
|
|
|
748
|
-
public void setDocumentLocator(Locator locator) {
|
|
749
|
-
}
|
|
826
|
+
public void setDocumentLocator(Locator locator) {}
|
|
750
827
|
|
|
751
|
-
public void startDocument() {
|
|
752
|
-
}
|
|
828
|
+
public void startDocument() {}
|
|
753
829
|
|
|
754
|
-
public void endDocument() {
|
|
755
|
-
}
|
|
830
|
+
public void endDocument() {}
|
|
756
831
|
|
|
757
|
-
public void startPrefixMapping(String prefix, String uri) {
|
|
758
|
-
}
|
|
832
|
+
public void startPrefixMapping(String prefix, String uri) {}
|
|
759
833
|
|
|
760
|
-
public void endPrefixMapping(String prefix) {
|
|
761
|
-
}
|
|
834
|
+
public void endPrefixMapping(String prefix) {}
|
|
762
835
|
|
|
763
836
|
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
|
764
837
|
handleStartTag(localName, attributes);
|
|
@@ -801,52 +874,47 @@ class HtmlToSpannedConverter implements ContentHandler {
|
|
|
801
874
|
mSpannableStringBuilder.append(sb);
|
|
802
875
|
}
|
|
803
876
|
|
|
804
|
-
public void ignorableWhitespace(char[] ch, int start, int length) {
|
|
805
|
-
}
|
|
877
|
+
public void ignorableWhitespace(char[] ch, int start, int length) {}
|
|
806
878
|
|
|
807
|
-
public void processingInstruction(String target, String data) {
|
|
808
|
-
}
|
|
879
|
+
public void processingInstruction(String target, String data) {}
|
|
809
880
|
|
|
810
|
-
public void skippedEntity(String name) {
|
|
811
|
-
}
|
|
881
|
+
public void skippedEntity(String name) {}
|
|
812
882
|
|
|
813
|
-
private static class H1 {
|
|
814
|
-
}
|
|
883
|
+
private static class H1 {}
|
|
815
884
|
|
|
816
|
-
private static class H2 {
|
|
817
|
-
}
|
|
885
|
+
private static class H2 {}
|
|
818
886
|
|
|
819
|
-
private static class H3 {
|
|
820
|
-
}
|
|
887
|
+
private static class H3 {}
|
|
821
888
|
|
|
822
|
-
private static class
|
|
823
|
-
}
|
|
889
|
+
private static class H4 {}
|
|
824
890
|
|
|
825
|
-
private static class
|
|
826
|
-
}
|
|
891
|
+
private static class H5 {}
|
|
827
892
|
|
|
828
|
-
private static class
|
|
829
|
-
}
|
|
893
|
+
private static class H6 {}
|
|
830
894
|
|
|
831
|
-
private static class
|
|
832
|
-
}
|
|
895
|
+
private static class Bold {}
|
|
833
896
|
|
|
834
|
-
private static class
|
|
835
|
-
}
|
|
897
|
+
private static class Italic {}
|
|
836
898
|
|
|
837
|
-
private static class
|
|
838
|
-
}
|
|
899
|
+
private static class Underline {}
|
|
839
900
|
|
|
840
|
-
private static class
|
|
841
|
-
|
|
901
|
+
private static class Code {}
|
|
902
|
+
|
|
903
|
+
private static class CodeBlock {}
|
|
904
|
+
|
|
905
|
+
private static class Strikethrough {}
|
|
906
|
+
|
|
907
|
+
private static class Blockquote {}
|
|
842
908
|
|
|
843
909
|
private static class List {
|
|
844
910
|
public int mIndex;
|
|
845
911
|
public String mType;
|
|
912
|
+
public boolean mChecked;
|
|
846
913
|
|
|
847
|
-
public List(String type, int index) {
|
|
914
|
+
public List(String type, int index, boolean checked) {
|
|
848
915
|
mType = type;
|
|
849
916
|
mIndex = index;
|
|
917
|
+
mChecked = checked;
|
|
850
918
|
}
|
|
851
919
|
}
|
|
852
920
|
|