react-native-enriched-markdown-scaffold 0.7.4-scaffold.9 → 1.0.2-scaffold.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -8
- package/ReactNativeEnrichedMarkdown.podspec +82 -73
- package/android/build.gradle +186 -1
- package/android/consumer-rules.pro +1 -1
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerDelegate.java +9 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerInterface.java +3 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextInputManagerDelegate.java +24 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextInputManagerInterface.java +8 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerDelegate.java +9 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerInterface.java +3 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.cpp +75 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.h +63 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.cpp +35 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.h +886 -23
- package/android/src/main/baseline-prof.txt +1 -1
- package/android/src/main/cpp/jni-adapter.cpp +74 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdown.kt +189 -13
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownInternalText.kt +17 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownManager.kt +50 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownText.kt +48 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownTextLayoutManager.kt +10 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownTextManager.kt +42 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/MeasurementStore.kt +82 -4
- package/android/src/main/java/com/swmansion/enriched/markdown/events/CopyPressEvent.kt +24 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/EnrichedMarkdownTextInputManager.kt +54 -4
- package/android/src/main/java/com/swmansion/enriched/markdown/input/EnrichedMarkdownTextInputView.kt +901 -462
- package/android/src/main/java/com/swmansion/enriched/markdown/input/MarkdownClipboard.kt +42 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/BlockEditCoordinator.kt +196 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/ClipboardCoordinator.kt +73 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/EditContext.kt +19 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/EditPipeline.kt +248 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/EditSession.kt +52 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/InputConnectionWrapper.kt +101 -7
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/LinkCoordinator.kt +69 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/MarkdownTextWatcher.kt +3 -3
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/MentionCoordinator.kt +118 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/events/OnChangeStateEvent.kt +26 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/events/OnContextMenuItemPressEvent.kt +26 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/events/OnInputKeyPressEvent.kt +24 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/events/OnPasteEvent.kt +24 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/formatting/BlockStore.kt +254 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/formatting/FormattingStore.kt +80 -87
- package/android/src/main/java/com/swmansion/enriched/markdown/input/formatting/InputFormatter.kt +109 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/input/formatting/InputParser.kt +116 -22
- package/android/src/main/java/com/swmansion/enriched/markdown/input/formatting/MarkdownSerializer.kt +167 -38
- package/android/src/main/java/com/swmansion/enriched/markdown/input/formatting/RangeEditAdjustment.kt +149 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/layout/InputEventEmitter.kt +66 -5
- package/android/src/main/java/com/swmansion/enriched/markdown/input/layout/InputMeasurementStore.kt +4 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/input/model/BlockRange.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/model/BlockType.kt +48 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/model/FormattingRange.kt +9 -4
- package/android/src/main/java/com/swmansion/enriched/markdown/input/model/InputFormatterStyle.kt +39 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/input/model/MathAtom.kt +20 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/model/MathChipStyle.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/input/model/MutableRangeBounds.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/spans/InputBulletSpan.kt +82 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/spans/InputHeadingSpan.kt +58 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/spans/InputListItemSpacingSpan.kt +37 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/spans/InputOrderedListMarkerSpan.kt +63 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/styles/BlockHandler.kt +54 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/styles/HeadingBlockHandler.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/styles/OrderedListBlockHandler.kt +38 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/styles/UnorderedListBlockHandler.kt +37 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/toolbar/InputContextMenu.kt +8 -26
- package/android/src/main/java/com/swmansion/enriched/markdown/parser/MarkdownASTNode.kt +1 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/parser/Parser.kt +1 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockStyleContext.kt +9 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockquoteRenderer.kt +100 -12
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/CodeBlockRenderer.kt +16 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/HeadingRenderer.kt +4 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/ListContextManager.kt +2 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/ListItemRenderer.kt +74 -18
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/ListRenderer.kt +43 -4
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/NodeRenderer.kt +9 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/SoftBreakRenderer.kt +16 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/SpanStyleCache.kt +30 -27
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/BaseListSpan.kt +24 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/BlockquoteSpan.kt +174 -24
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/CodeBackgroundSpan.kt +27 -3
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/CodeBlockSpan.kt +13 -16
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/CodeSpan.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/EmphasisSpan.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/ImageSpan.kt +182 -46
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/ListItemSpacingSpan.kt +33 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/ListMarkerAnchorSpan.kt +38 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/OrderedListSpan.kt +2 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/StrongSpan.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/TaskListSpan.kt +3 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/UnorderedListSpan.kt +3 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/BlockquoteStyle.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/CodeBlockStyle.kt +26 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/ImageStyle.kt +7 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/ListStyle.kt +4 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/StyleConfig.kt +13 -4
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/TableStyle.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/CodeBlockHighlighter.kt +90 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/CodeBlockNode.kt +57 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/FeatureFlags.kt +1 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/MarkdownSegment.kt +9 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/MarkdownViewManagerUtils.kt +37 -7
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/ReadableMapExtensions.kt +3 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/RenderedSegment.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/SegmentSignature.kt +1 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/StreamingMarkdownFilter.kt +83 -5
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/serialization/MarkdownASTSerializer.kt +4 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/input/MarkdownStyleParser.kt +74 -44
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/input/PasteTextUtils.kt +20 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/ImageCache.kt +26 -3
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/ImageDownloader.kt +22 -9
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/LocalImageLoader.kt +161 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/extensions/TextPaintExtensions.kt +23 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/interaction/CheckboxTouchHelper.kt +7 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/interaction/TaskListTapUtils.kt +41 -21
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/span/BlockSpacing.kt +15 -8
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/LinkLongPressMovementMethod.kt +58 -27
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/SelectionActionMode.kt +49 -15
- package/android/src/main/java/com/swmansion/enriched/markdown/views/BlockMenuOptions.kt +45 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/views/CodeBlockContainerView.kt +396 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/views/ContextMenuPopup.kt +9 -6
- package/android/src/main/java/com/swmansion/enriched/markdown/views/CopyGlyph.kt +101 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/views/TableContainerView.kt +36 -9
- package/android/src/main/jni/CMakeLists.txt +53 -0
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/MarkdownContainerShadowNode.cpp +10 -0
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/MarkdownContainerShadowNode.h +11 -2
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/MarkdownTextShadowNode.cpp +10 -0
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/MarkdownTextShadowNode.h +12 -2
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/MarkdownTextState.cpp +9 -0
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/MarkdownTextState.h +24 -0
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/conversions.h +16 -0
- package/android/src/math/java/com/swmansion/enriched/markdown/input/math/MathChipControllerImpl.kt +21 -4
- package/android/src/math/java/com/swmansion/enriched/markdown/renderer/MathInlineRenderer.kt +7 -2
- package/android/src/math/java/com/swmansion/enriched/markdown/spans/MathChipSpan.kt +1 -1
- package/android/src/math/java/com/swmansion/enriched/markdown/views/MathContainerView.kt +6 -4
- package/cpp/highlight/CodeBlockHighlighter.cpp +284 -0
- package/cpp/highlight/CodeBlockHighlighter.hpp +66 -0
- package/cpp/highlight/CodeBlockLanguages.cpp +138 -0
- package/cpp/highlight/CodeBlockLanguages.hpp +25 -0
- package/cpp/highlight/HighlightGrammars.hpp +28 -0
- package/cpp/highlight/code_highlight_podspec.rb +211 -0
- package/cpp/highlight/gen-registry.mjs +155 -0
- package/cpp/highlight/grammar-versions.json +159 -0
- package/cpp/highlight/vendor/generated/generated_queries.h +1665 -0
- package/cpp/highlight/vendor/generated/generated_registry.cpp +59 -0
- package/cpp/parser/MD4CParser.cpp +173 -61
- package/cpp/parser/MD4CParser.hpp +1 -0
- package/cpp/parser/MarkdownASTNode.hpp +2 -1
- package/cpp/wasm/ASTSerializer.cpp +2 -0
- package/cpp/wasm/build.sh +1 -0
- package/cpp/wasm/md4c_wasm.cpp +3 -1
- package/docs/ACCESSIBILITY.md +14 -2
- package/docs/API_REFERENCE.md +234 -12
- package/docs/BREAKING_CHANGES.md +129 -0
- package/docs/CODE_HIGHLIGHT.md +133 -0
- package/docs/COPY_OPTIONS.md +47 -3
- package/docs/ELEMENTS_STRUCTURE.md +52 -4
- package/docs/IMAGE_CACHING.md +30 -0
- package/docs/INPUT.md +108 -11
- package/docs/LATEX_MATH.md +87 -45
- package/docs/MACOS.md +1 -1
- package/docs/MARKDOWN_STREAMING.md +27 -1
- package/docs/NATIVE_ASSETS.md +127 -0
- package/docs/RTL.md +1 -1
- package/docs/STYLES.md +46 -6
- package/docs/TESTING.md +112 -0
- package/docs/TEXT.md +16 -6
- package/docs/WEB.md +3 -1
- package/ios/EnrichedMarkdown.h +7 -0
- package/ios/EnrichedMarkdown.mm +284 -75
- package/ios/EnrichedMarkdownText.h +7 -0
- package/ios/EnrichedMarkdownText.mm +101 -73
- package/ios/attachments/ENRMImageAttachment.h +9 -0
- package/ios/attachments/ENRMImageAttachment.m +143 -40
- package/ios/attachments/ENRMMathInlineAttachment.h +2 -0
- package/ios/attachments/ENRMMathInlineAttachment.m +48 -81
- package/ios/attachments/ENRMMathInlineAttachmentShared.h +2 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/EventEmitters.cpp +75 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/EventEmitters.h +63 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.cpp +35 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.h +886 -23
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/RCTComponentViewHelpers.h +131 -0
- package/ios/input/ENRMAutoLinkDetector.h +2 -1
- package/ios/input/ENRMAutoLinkDetector.mm +79 -41
- package/ios/input/ENRMBlockEditCoordinator.h +71 -0
- package/ios/input/ENRMBlockEditCoordinator.mm +195 -0
- package/ios/input/ENRMBlockRange.h +28 -0
- package/ios/input/ENRMBlockRange.mm +30 -0
- package/ios/input/ENRMBlockStore.h +56 -0
- package/ios/input/ENRMBlockStore.mm +275 -0
- package/ios/input/ENRMClipboardCoordinator.h +45 -0
- package/ios/input/ENRMClipboardCoordinator.mm +120 -0
- package/ios/input/ENRMDetectorPipeline.h +2 -1
- package/ios/input/ENRMEditPipeline.h +76 -0
- package/ios/input/ENRMEditPipeline.mm +228 -0
- package/ios/input/ENRMEditSession.h +36 -0
- package/ios/input/ENRMEditSession.mm +63 -0
- package/ios/input/ENRMFormattingStore.h +17 -0
- package/ios/input/ENRMFormattingStore.mm +95 -105
- package/ios/input/ENRMInputBlockType.h +91 -0
- package/ios/input/ENRMInputBlockType.mm +5 -0
- package/ios/input/ENRMInputDecorationDrawer.h +18 -0
- package/ios/input/ENRMInputEventEmitter.h +56 -0
- package/ios/input/ENRMInputEventEmitter.mm +308 -0
- package/ios/input/ENRMInputFormatter.h +29 -69
- package/ios/input/ENRMInputFormatter.mm +216 -124
- package/ios/input/ENRMInputFormatterStyle.h +99 -0
- package/ios/input/ENRMInputFormatterStyle.mm +188 -0
- package/ios/input/ENRMInputLayoutManager.h +9 -0
- package/ios/input/ENRMInputLayoutManager.mm +30 -0
- package/ios/input/ENRMInputListMarkerDrawer.h +32 -0
- package/ios/input/ENRMInputListMarkerDrawer.mm +426 -0
- package/ios/input/ENRMInputParser.h +5 -6
- package/ios/input/ENRMInputParser.mm +461 -178
- package/ios/input/ENRMInputRemend.mm +2 -2
- package/ios/input/ENRMInputStyleStateBuilder.h +40 -0
- package/ios/input/ENRMInputStyleStateBuilder.mm +60 -0
- package/ios/input/ENRMInputTextView.mm +103 -8
- package/ios/input/ENRMInputTypingAttributesController.h +42 -0
- package/ios/input/ENRMInputTypingAttributesController.mm +203 -0
- package/ios/input/ENRMLinkCoordinator.h +41 -0
- package/ios/input/ENRMLinkCoordinator.mm +89 -0
- package/ios/input/ENRMMarkdownSerializer.h +29 -5
- package/ios/input/ENRMMarkdownSerializer.mm +170 -48
- package/ios/input/ENRMMathAtom.h +26 -0
- package/ios/input/ENRMMathAtom.mm +12 -0
- package/ios/input/ENRMMentionCoordinator.h +45 -0
- package/ios/input/ENRMMentionCoordinator.mm +167 -0
- package/ios/input/ENRMRangeEditAdjustment.h +38 -0
- package/ios/input/ENRMRangeEditAdjustment.mm +91 -0
- package/ios/input/ENRMRangeStoreUtils.h +39 -0
- package/ios/input/EnrichedMarkdownTextInput+ContextMenu.mm +6 -6
- package/ios/input/EnrichedMarkdownTextInput+Internal.h +11 -3
- package/ios/input/EnrichedMarkdownTextInput.h +7 -1
- package/ios/input/EnrichedMarkdownTextInput.mm +1089 -1023
- package/ios/input/InputStylePropsUtils.h +109 -68
- package/ios/input/internals/EnrichedMarkdownTextInputShadowNode.mm +2 -1
- package/ios/input/styles/ENRMBlockHandler.h +46 -0
- package/ios/input/styles/ENRMHeadingBlockHandler.h +15 -0
- package/ios/input/styles/ENRMHeadingBlockHandler.mm +38 -0
- package/ios/input/styles/ENRMOrderedListBlockHandler.h +14 -0
- package/ios/input/styles/ENRMOrderedListBlockHandler.mm +48 -0
- package/ios/input/styles/ENRMUnorderedListBlockHandler.h +15 -0
- package/ios/input/styles/ENRMUnorderedListBlockHandler.mm +51 -0
- package/ios/internals/ENRMViewFreeMeasurement.h +331 -0
- package/ios/internals/EnrichedMarkdownShadowNode.h +1 -3
- package/ios/internals/EnrichedMarkdownShadowNode.mm +16 -20
- package/ios/internals/EnrichedMarkdownTextShadowNode.h +1 -3
- package/ios/internals/EnrichedMarkdownTextShadowNode.mm +15 -20
- package/ios/internals/MeasurementCache.h +33 -7
- package/ios/internals/ShadowMeasurementUtils.h +63 -58
- package/ios/math/ENRMMathChipController.h +74 -0
- package/ios/math/ENRMMathChipController.mm +476 -0
- package/ios/math/ENRMRaTeXBridge.swift +4 -1
- package/ios/parser/ENRMMarkdownParser.h +1 -8
- package/ios/parser/ENRMMarkdownParser.mm +2 -11
- package/ios/parser/MarkdownASTNode.h +2 -1
- package/ios/parser/MarkdownParserBridge.mm +4 -0
- package/ios/renderer/AttributedRenderer.m +20 -2
- package/ios/renderer/BaseRenderer.h +17 -2
- package/ios/renderer/BaseRenderer.m +30 -0
- package/ios/renderer/BlockquoteRenderer.h +1 -1
- package/ios/renderer/BlockquoteRenderer.m +144 -35
- package/ios/renderer/CodeBlockRenderer.h +1 -1
- package/ios/renderer/CodeBlockRenderer.m +27 -23
- package/ios/renderer/CodeRenderer.h +1 -1
- package/ios/renderer/CodeRenderer.m +3 -1
- package/ios/renderer/ENRMImageRenderer.h +1 -1
- package/ios/renderer/ENRMImageRenderer.m +5 -1
- package/ios/renderer/ENRMMathInlineRenderer.h +1 -1
- package/ios/renderer/ENRMMathInlineRenderer.m +5 -1
- package/ios/renderer/ENRMSpoilerRenderer.h +1 -1
- package/ios/renderer/ENRMSpoilerRenderer.m +3 -1
- package/ios/renderer/EmphasisRenderer.h +1 -1
- package/ios/renderer/EmphasisRenderer.m +3 -1
- package/ios/renderer/HeadingRenderer.h +1 -1
- package/ios/renderer/HeadingRenderer.m +13 -6
- package/ios/renderer/HighlightRenderer.h +1 -1
- package/ios/renderer/HighlightRenderer.m +3 -1
- package/ios/renderer/LinkRenderer.h +1 -1
- package/ios/renderer/LinkRenderer.m +3 -1
- package/ios/renderer/ListItemRenderer.h +13 -1
- package/ios/renderer/ListItemRenderer.m +102 -44
- package/ios/renderer/ListRenderer.h +2 -2
- package/ios/renderer/ListRenderer.m +63 -25
- package/ios/renderer/ParagraphRenderer.h +1 -1
- package/ios/renderer/ParagraphRenderer.m +16 -8
- package/ios/renderer/RenderContext.h +10 -0
- package/ios/renderer/RenderContext.m +44 -0
- package/ios/renderer/RendererFactory.m +14 -0
- package/ios/renderer/StrikethroughRenderer.h +1 -1
- package/ios/renderer/StrikethroughRenderer.m +3 -1
- package/ios/renderer/StrongRenderer.h +1 -1
- package/ios/renderer/StrongRenderer.m +3 -1
- package/ios/renderer/SubscriptRenderer.h +1 -1
- package/ios/renderer/SubscriptRenderer.m +3 -1
- package/ios/renderer/SuperscriptRenderer.h +1 -1
- package/ios/renderer/SuperscriptRenderer.m +3 -1
- package/ios/renderer/TextRenderer.h +2 -2
- package/ios/renderer/TextRenderer.m +3 -1
- package/ios/renderer/ThematicBreakRenderer.h +1 -1
- package/ios/renderer/ThematicBreakRenderer.m +3 -1
- package/ios/renderer/UnderlineRenderer.h +1 -1
- package/ios/renderer/UnderlineRenderer.m +3 -1
- package/ios/styles/StyleConfig.h +22 -0
- package/ios/styles/StyleConfig.mm +132 -0
- package/ios/utils/BlockquoteBorder.h +6 -0
- package/ios/utils/BlockquoteBorder.m +249 -52
- package/ios/utils/CodeBlockBackground.m +16 -2
- package/ios/utils/ENRMAtomicSize.h +65 -0
- package/ios/utils/ENRMBlockMenu.h +57 -0
- package/ios/utils/ENRMCodeBlockContent.h +37 -0
- package/ios/utils/ENRMCodeBlockContent.mm +79 -0
- package/ios/utils/ENRMCodeBlockHighlighter.h +37 -0
- package/ios/utils/ENRMCodeBlockHighlighter.mm +51 -0
- package/ios/utils/ENRMFeatureFlags.h +7 -0
- package/ios/utils/ENRMImageDownloader.h +11 -1
- package/ios/utils/ENRMImageDownloader.m +60 -16
- package/ios/utils/ENRMLocalImageLoader.h +31 -0
- package/ios/utils/ENRMLocalImageLoader.m +68 -0
- package/ios/utils/ENRMMathFallback.h +26 -0
- package/ios/utils/ENRMMathFallback.m +18 -0
- package/ios/utils/ENRMTextViewSetup.h +35 -17
- package/ios/utils/EditMenuUtils.h +22 -5
- package/ios/utils/EditMenuUtils.m +53 -9
- package/ios/utils/ImageRequestHeaderUtils.h +35 -0
- package/ios/utils/LastElementUtils.h +1 -0
- package/ios/utils/ListMarkerDrawer.m +29 -42
- package/ios/utils/MarkdownASTSerializer.m +4 -0
- package/ios/utils/ParagraphStyleUtils.h +5 -0
- package/ios/utils/ParagraphStyleUtils.m +77 -17
- package/ios/utils/RenderedMarkdownSegment.h +13 -1
- package/ios/utils/RenderedMarkdownSegment.m +20 -0
- package/ios/utils/SegmentRenderer.m +17 -4
- package/ios/utils/StreamingMarkdownFilter.h +11 -1
- package/ios/utils/StreamingMarkdownFilter.m +98 -2
- package/ios/utils/StylePropsUtils.h +63 -0
- package/ios/utils/TaskListTapUtils.m +24 -0
- package/ios/views/ENRMCodeBlockContainerView.h +53 -0
- package/ios/views/ENRMCodeBlockContainerView.m +559 -0
- package/ios/views/ENRMMathContainerView.h +16 -0
- package/ios/views/ENRMMathContainerView.m +74 -19
- package/ios/views/TableContainerView.h +22 -0
- package/ios/views/TableContainerView.m +261 -175
- package/jest.d.ts +1 -0
- package/jest.js +5 -0
- package/lib/module/EnrichedMarkdownNativeComponent.ts +73 -0
- package/lib/module/EnrichedMarkdownTextInput.js +84 -5
- package/lib/module/EnrichedMarkdownTextInput.js.map +1 -1
- package/lib/module/EnrichedMarkdownTextInputNativeComponent.ts +78 -5
- package/lib/module/EnrichedMarkdownTextNativeComponent.ts +74 -0
- package/lib/module/headingDefaults.js +34 -0
- package/lib/module/headingDefaults.js.map +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/jest/index.js +191 -0
- package/lib/module/jest/index.js.map +1 -0
- package/lib/module/native/EnrichedMarkdownText.js +37 -5
- package/lib/module/native/EnrichedMarkdownText.js.map +1 -1
- package/lib/module/normalizeMarkdownStyle.js +81 -19
- package/lib/module/normalizeMarkdownStyle.js.map +1 -1
- package/lib/module/normalizeMarkdownStyle.web.js +56 -18
- package/lib/module/normalizeMarkdownStyle.web.js.map +1 -1
- package/lib/module/normalizeMarkdownTextInputStyle.js +62 -15
- package/lib/module/normalizeMarkdownTextInputStyle.js.map +1 -1
- package/lib/module/normalizeMenuItem.js +1 -1
- package/lib/module/utils/textInputState.js +26 -0
- package/lib/module/utils/textInputState.js.map +1 -0
- package/lib/module/web/EnrichedMarkdownText.js +9 -5
- package/lib/module/web/EnrichedMarkdownText.js.map +1 -1
- package/lib/module/web/parseMarkdown.js +4 -3
- package/lib/module/web/parseMarkdown.js.map +1 -1
- package/lib/module/web/renderers/InlineRenderers.js +6 -0
- package/lib/module/web/renderers/InlineRenderers.js.map +1 -1
- package/lib/module/web/renderers/ListRenderers.js +7 -2
- package/lib/module/web/renderers/ListRenderers.js.map +1 -1
- package/lib/module/web/renderers/index.js +7 -4
- package/lib/module/web/renderers/index.js.map +1 -1
- package/lib/module/web/styles.js +83 -6
- package/lib/module/web/styles.js.map +1 -1
- package/lib/module/web/utils.js +1 -0
- package/lib/module/web/utils.js.map +1 -1
- package/lib/module/web/wasm/md4c.js +0 -0
- package/lib/module/web/wasm/md4c.js.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts +66 -0
- package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownTextInput.d.ts +94 -9
- package/lib/typescript/src/EnrichedMarkdownTextInput.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownTextInputNativeComponent.d.ts +69 -5
- package/lib/typescript/src/EnrichedMarkdownTextInputNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts +66 -0
- package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/headingDefaults.d.ts +9 -0
- package/lib/typescript/src/headingDefaults.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/index.web.d.ts +1 -1
- package/lib/typescript/src/index.web.d.ts.map +1 -1
- package/lib/typescript/src/jest/index.d.ts +6 -0
- package/lib/typescript/src/jest/index.d.ts.map +1 -0
- package/lib/typescript/src/native/EnrichedMarkdownText.d.ts +3 -3
- package/lib/typescript/src/native/EnrichedMarkdownText.d.ts.map +1 -1
- package/lib/typescript/src/normalizeMarkdownStyle.d.ts.map +1 -1
- package/lib/typescript/src/normalizeMarkdownStyle.web.d.ts.map +1 -1
- package/lib/typescript/src/normalizeMarkdownTextInputStyle.d.ts +19 -5
- package/lib/typescript/src/normalizeMarkdownTextInputStyle.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownStyle.d.ts +72 -0
- package/lib/typescript/src/types/MarkdownStyle.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownStyleInternal.d.ts +27 -0
- package/lib/typescript/src/types/MarkdownStyleInternal.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownTextProps.d.ts +104 -9
- package/lib/typescript/src/types/MarkdownTextProps.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownTextProps.web.d.ts +19 -0
- package/lib/typescript/src/types/MarkdownTextProps.web.d.ts.map +1 -1
- package/lib/typescript/src/types/events.d.ts +19 -0
- package/lib/typescript/src/types/events.d.ts.map +1 -1
- package/lib/typescript/src/utils/textInputState.d.ts +24 -0
- package/lib/typescript/src/utils/textInputState.d.ts.map +1 -0
- package/lib/typescript/src/web/EnrichedMarkdownText.d.ts +1 -1
- package/lib/typescript/src/web/EnrichedMarkdownText.d.ts.map +1 -1
- package/lib/typescript/src/web/parseMarkdown.d.ts +1 -1
- package/lib/typescript/src/web/parseMarkdown.d.ts.map +1 -1
- package/lib/typescript/src/web/renderers/InlineRenderers.d.ts.map +1 -1
- package/lib/typescript/src/web/renderers/ListRenderers.d.ts.map +1 -1
- package/lib/typescript/src/web/renderers/index.d.ts +2 -1
- package/lib/typescript/src/web/renderers/index.d.ts.map +1 -1
- package/lib/typescript/src/web/styles.d.ts +2 -1
- package/lib/typescript/src/web/styles.d.ts.map +1 -1
- package/lib/typescript/src/web/types.d.ts +6 -2
- package/lib/typescript/src/web/types.d.ts.map +1 -1
- package/lib/typescript/src/web/utils.d.ts.map +1 -1
- package/package.json +36 -9
- package/postinstall.mjs +131 -0
- package/ratex-version.json +21 -0
- package/src/EnrichedMarkdownNativeComponent.ts +73 -0
- package/src/EnrichedMarkdownTextInput.tsx +159 -8
- package/src/EnrichedMarkdownTextInputNativeComponent.ts +78 -5
- package/src/EnrichedMarkdownTextNativeComponent.ts +74 -0
- package/src/headingDefaults.ts +21 -0
- package/src/index.tsx +9 -0
- package/src/index.web.tsx +1 -0
- package/src/jest/index.tsx +215 -0
- package/src/native/EnrichedMarkdownText.tsx +53 -2
- package/src/normalizeMarkdownStyle.ts +102 -16
- package/src/normalizeMarkdownStyle.web.ts +63 -15
- package/src/normalizeMarkdownTextInputStyle.ts +110 -35
- package/src/normalizeMenuItem.ts +1 -1
- package/src/types/MarkdownStyle.ts +74 -0
- package/src/types/MarkdownStyleInternal.ts +39 -0
- package/src/types/MarkdownTextProps.ts +101 -9
- package/src/types/MarkdownTextProps.web.ts +19 -0
- package/src/types/events.ts +21 -0
- package/src/utils/textInputState.ts +35 -0
- package/src/web/EnrichedMarkdownText.tsx +16 -2
- package/src/web/parseMarkdown.ts +6 -2
- package/src/web/renderers/InlineRenderers.tsx +5 -0
- package/src/web/renderers/ListRenderers.tsx +14 -2
- package/src/web/renderers/index.tsx +6 -2
- package/src/web/styles.ts +89 -5
- package/src/web/types.ts +6 -1
- package/src/web/utils.ts +1 -0
- package/src/web/wasm/md4c.js +0 -0
- package/vendor-grammars.mjs +511 -0
- package/vendor-ratex.mjs +173 -0
- package/app.plugin.js +0 -2
- package/plugin/build/withAndroidMath.js +0 -19
- package/plugin/build/withIosMath.js +0 -28
- package/plugin/build/withReactNativeEnrichedMarkdown.js +0 -11
- package/plugin/src/withAndroidMath.ts +0 -24
- package/plugin/src/withIosMath.ts +0 -35
- package/plugin/src/withReactNativeEnrichedMarkdown.ts +0 -17
- package/plugin/tsconfig.build.json +0 -16
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#include "CodeBlockLanguages.hpp"
|
|
2
|
+
|
|
3
|
+
#include <algorithm>
|
|
4
|
+
#include <array>
|
|
5
|
+
#include <cctype>
|
|
6
|
+
#include <cstring>
|
|
7
|
+
|
|
8
|
+
namespace Markdown {
|
|
9
|
+
|
|
10
|
+
namespace {
|
|
11
|
+
|
|
12
|
+
struct LanguageName {
|
|
13
|
+
const char *key;
|
|
14
|
+
const char *name;
|
|
15
|
+
// Canonical tree-sitter grammar id (vendored directory name), or "" when no
|
|
16
|
+
// grammar covers this fence language.
|
|
17
|
+
const char *grammar;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Sorted by key; both lookups below binary-search this table.
|
|
21
|
+
constexpr std::array<LanguageName, 42> kLanguageNames{{
|
|
22
|
+
{"bash", "Bash", "bash"},
|
|
23
|
+
{"c", "C", "c"},
|
|
24
|
+
{"cc", "C++", "cpp"},
|
|
25
|
+
{"cpp", "C++", "cpp"},
|
|
26
|
+
{"cs", "C#", "c-sharp"},
|
|
27
|
+
{"csharp", "C#", "c-sharp"},
|
|
28
|
+
{"css", "CSS", "css"},
|
|
29
|
+
{"cxx", "C++", "cpp"},
|
|
30
|
+
{"dockerfile", "Dockerfile", ""},
|
|
31
|
+
{"go", "Go", "go"},
|
|
32
|
+
{"golang", "Go", "go"},
|
|
33
|
+
{"graphql", "GraphQL", ""},
|
|
34
|
+
{"html", "HTML", "html"},
|
|
35
|
+
{"java", "Java", "java"},
|
|
36
|
+
{"javascript", "JavaScript", "javascript"},
|
|
37
|
+
{"js", "JavaScript", "javascript"},
|
|
38
|
+
{"json", "JSON", "json"},
|
|
39
|
+
{"jsx", "JSX", "javascript"},
|
|
40
|
+
{"markdown", "Markdown", "markdown"},
|
|
41
|
+
{"md", "Markdown", "markdown"},
|
|
42
|
+
{"objc", "Objective-C", ""},
|
|
43
|
+
{"objectivec", "Objective-C", ""},
|
|
44
|
+
{"php", "PHP", "php"},
|
|
45
|
+
{"py", "Python", "python"},
|
|
46
|
+
{"python", "Python", "python"},
|
|
47
|
+
{"rb", "Ruby", "ruby"},
|
|
48
|
+
{"rs", "Rust", "rust"},
|
|
49
|
+
{"ruby", "Ruby", "ruby"},
|
|
50
|
+
{"rust", "Rust", "rust"},
|
|
51
|
+
{"scss", "SCSS", ""},
|
|
52
|
+
{"sh", "Shell", "bash"},
|
|
53
|
+
{"shell", "Shell", "bash"},
|
|
54
|
+
{"sql", "SQL", ""},
|
|
55
|
+
{"swift", "Swift", "swift"},
|
|
56
|
+
{"toml", "TOML", ""},
|
|
57
|
+
{"ts", "TypeScript", "typescript"},
|
|
58
|
+
{"tsx", "TSX", "tsx"},
|
|
59
|
+
{"typescript", "TypeScript", "typescript"},
|
|
60
|
+
{"xml", "XML", ""},
|
|
61
|
+
{"yaml", "YAML", "yaml"},
|
|
62
|
+
{"yml", "YAML", "yaml"},
|
|
63
|
+
{"zsh", "Zsh", "bash"},
|
|
64
|
+
}};
|
|
65
|
+
|
|
66
|
+
// findLanguage binary-searches kLanguageNames, so the table must be strictly
|
|
67
|
+
// ascending by key under C strcmp order. Enforce it at compile time: a
|
|
68
|
+
// misordered entry (e.g. "ruby" before "rs") would otherwise silently fail the
|
|
69
|
+
// lookup and leave that language unhighlighted.
|
|
70
|
+
constexpr bool keyLess(const char *a, const char *b) {
|
|
71
|
+
for (std::size_t i = 0;; ++i) {
|
|
72
|
+
unsigned char ca = static_cast<unsigned char>(a[i]);
|
|
73
|
+
unsigned char cb = static_cast<unsigned char>(b[i]);
|
|
74
|
+
if (ca != cb) {
|
|
75
|
+
return ca < cb;
|
|
76
|
+
}
|
|
77
|
+
if (ca == '\0') {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
constexpr bool languageTableIsSorted() {
|
|
84
|
+
for (std::size_t i = 1; i < kLanguageNames.size(); ++i) {
|
|
85
|
+
if (!keyLess(kLanguageNames[i - 1].key, kLanguageNames[i].key)) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static_assert(languageTableIsSorted(), "kLanguageNames must be sorted by key for binary search");
|
|
93
|
+
|
|
94
|
+
// Lowercases language and binary-searches the table. Returns nullptr on miss.
|
|
95
|
+
const LanguageName *findLanguage(const std::string &language, std::string &lowerOut) {
|
|
96
|
+
lowerOut = language;
|
|
97
|
+
for (char &c : lowerOut) {
|
|
98
|
+
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
auto it =
|
|
102
|
+
std::lower_bound(kLanguageNames.begin(), kLanguageNames.end(), lowerOut.c_str(),
|
|
103
|
+
[](const LanguageName &entry, const char *key) { return std::strcmp(entry.key, key) < 0; });
|
|
104
|
+
if (it != kLanguageNames.end() && lowerOut == it->key) {
|
|
105
|
+
return &(*it);
|
|
106
|
+
}
|
|
107
|
+
return nullptr;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
} // namespace
|
|
111
|
+
|
|
112
|
+
std::string displayNameForLanguage(const std::string &language) {
|
|
113
|
+
if (language.empty()) {
|
|
114
|
+
return "";
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
std::string lower;
|
|
118
|
+
if (const LanguageName *entry = findLanguage(language, lower)) {
|
|
119
|
+
return entry->name;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
lower[0] = static_cast<char>(std::toupper(static_cast<unsigned char>(lower[0])));
|
|
123
|
+
return lower;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
std::string canonicalGrammarId(const std::string &language) {
|
|
127
|
+
if (language.empty()) {
|
|
128
|
+
return "";
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
std::string lower;
|
|
132
|
+
if (const LanguageName *entry = findLanguage(language, lower)) {
|
|
133
|
+
return entry->grammar;
|
|
134
|
+
}
|
|
135
|
+
return "";
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
} // namespace Markdown
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <string>
|
|
4
|
+
|
|
5
|
+
// Display names for code block fence languages, shared by every platform and
|
|
6
|
+
// both markdown flavors so a fence like ```python is labeled identically
|
|
7
|
+
// everywhere. Unlike the highlighting seam this is always compiled; it does
|
|
8
|
+
// not depend on ENRICHED_MARKDOWN_CODE_HIGHLIGHT.
|
|
9
|
+
|
|
10
|
+
namespace Markdown {
|
|
11
|
+
|
|
12
|
+
// Maps a fence info string (for example "python", "js") to a human readable
|
|
13
|
+
// display name ("Python", "JavaScript"). Unknown languages fall back to the
|
|
14
|
+
// lowercased input with the first ASCII letter capitalized. Empty input
|
|
15
|
+
// returns an empty string.
|
|
16
|
+
std::string displayNameForLanguage(const std::string& language);
|
|
17
|
+
|
|
18
|
+
// Maps a fence info string to the canonical tree-sitter grammar id that can
|
|
19
|
+
// highlight it (for example "js" and "jsx" both map to "javascript"), or an
|
|
20
|
+
// empty string when no grammar covers the language. The id is the vendored
|
|
21
|
+
// grammar directory name; whether that grammar is actually compiled into the
|
|
22
|
+
// build is answered separately by findGrammar.
|
|
23
|
+
std::string canonicalGrammarId(const std::string& language);
|
|
24
|
+
|
|
25
|
+
} // namespace Markdown
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
// Registry of the tree-sitter grammars compiled into this build. The table and
|
|
4
|
+
// the findGrammar definition live in generated_registry.cpp, emitted by
|
|
5
|
+
// vendor/gen-registry.mjs for exactly the selected language subset, so this
|
|
6
|
+
// header never references symbols for grammars that were not compiled.
|
|
7
|
+
//
|
|
8
|
+
// Only meaningful when ENRICHED_MARKDOWN_CODE_HIGHLIGHT is defined; without the
|
|
9
|
+
// flag neither this header nor generated_registry.cpp is compiled.
|
|
10
|
+
|
|
11
|
+
struct TSLanguage;
|
|
12
|
+
|
|
13
|
+
namespace Markdown {
|
|
14
|
+
|
|
15
|
+
struct GrammarEntry {
|
|
16
|
+
// Canonical grammar id, matching canonicalGrammarId() in CodeBlockLanguages.
|
|
17
|
+
const char *canonicalId;
|
|
18
|
+
// tree-sitter language constructor (extern "C" tree_sitter_<id>).
|
|
19
|
+
const TSLanguage *(*language)(void);
|
|
20
|
+
// The grammar's highlights.scm, inheritance already inlined, as a C string.
|
|
21
|
+
const char *highlightsQuery;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Returns the entry for canonicalId, or nullptr when no grammar for it was
|
|
25
|
+
// compiled into this build (unselected language) or canonicalId is empty.
|
|
26
|
+
const GrammarEntry *findGrammar(const char *canonicalId);
|
|
27
|
+
|
|
28
|
+
} // namespace Markdown
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# Shared tree-sitter code-highlighting wiring for both podspecs
|
|
2
|
+
# (EnrichedMarkdownCore in the monorepo, ReactNativeEnrichedMarkdown when
|
|
3
|
+
# published without the core pod). Podspecs are imperative Ruby that own their
|
|
4
|
+
# own source_files/defines/header paths, so unlike Android there is no build
|
|
5
|
+
# ownership problem: this computes exactly what to add.
|
|
6
|
+
#
|
|
7
|
+
# Only lib.c (the runtime) and each selected grammar's parser.c/scanner.c are
|
|
8
|
+
# compiled; every other vendored .c/.h is include-only and resolves through
|
|
9
|
+
# quoted relative includes, so the shared HEADER_SEARCH_PATHS never carries a
|
|
10
|
+
# grammar dir or tree-sitter/src (which would collide grammar parser.h files).
|
|
11
|
+
#
|
|
12
|
+
# The default grammar set is NOT hardcoded here: it is derived from the single
|
|
13
|
+
# source of truth, vendor/grammar-versions.json (every grammar with default:true),
|
|
14
|
+
# so the compiled sources always match the registry that gen-registry generates
|
|
15
|
+
# from the same manifest. The Android build derives it the same way.
|
|
16
|
+
|
|
17
|
+
require 'json'
|
|
18
|
+
|
|
19
|
+
module EnrichedMarkdownConfig
|
|
20
|
+
@warnings_emitted = {}
|
|
21
|
+
|
|
22
|
+
def self.warn_once(key, message)
|
|
23
|
+
return if @warnings_emitted[key]
|
|
24
|
+
@warnings_emitted[key] = true
|
|
25
|
+
Pod::UI.warn message
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# The consumer app's package.json "enriched-markdown" block is the build-time
|
|
29
|
+
# source of truth for feature toggles (mirrors the Android build.gradle and
|
|
30
|
+
# react-native-worklets). It is read from the Podfile's installation root --
|
|
31
|
+
# "<app>/package.json", one level above the "<app>/ios" dir CocoaPods installs
|
|
32
|
+
# into -- so in a monorepo it resolves to the app being built, not the workspace
|
|
33
|
+
# root. Per-app config therefore works; the download side (postinstall) is a
|
|
34
|
+
# separate, install-time decision. ENV vars remain a deprecated fallback.
|
|
35
|
+
#
|
|
36
|
+
# A cheap accessor over the memoized package.json (see consumer_package_json), so both
|
|
37
|
+
# this file (code highlighting) and the main podspec (math) can read it without re-parsing.
|
|
38
|
+
def self.consumer_config
|
|
39
|
+
config = consumer_package_json['enriched-markdown']
|
|
40
|
+
config.is_a?(Hash) ? config : {}
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# A filesystem-safe identifier for the app being built, derived from its package.json
|
|
44
|
+
# "name" (falling back to the app directory name). It keys the per-app generated
|
|
45
|
+
# code-highlight registry (generated-<slug>) so that, in a hoisted monorepo, two apps
|
|
46
|
+
# with different custom language sets each get their own registry instead of clobbering
|
|
47
|
+
# a single shared one.
|
|
48
|
+
def self.consumer_app_slug
|
|
49
|
+
name = consumer_package_json['name'].to_s
|
|
50
|
+
name = File.basename(File.dirname(Pod::Config.instance.installation_root.to_s)) if name.empty?
|
|
51
|
+
slug = name.gsub(%r{[^A-Za-z0-9._-]+}, '-').gsub(/\A-+|-+\z/, '')
|
|
52
|
+
slug.empty? ? 'app' : slug
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.consumer_package_json
|
|
56
|
+
return @consumer_package_json if defined?(@consumer_package_json)
|
|
57
|
+
@consumer_package_json = load_consumer_package_json
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def self.load_consumer_package_json
|
|
61
|
+
path = File.join(Pod::Config.instance.installation_root.to_s, '..', 'package.json')
|
|
62
|
+
return {} unless File.exist?(path)
|
|
63
|
+
JSON.parse(File.read(path))
|
|
64
|
+
rescue StandardError => e
|
|
65
|
+
Pod::UI.warn "[ReactNativeEnrichedMarkdown] could not read the app package.json " \
|
|
66
|
+
"(#{e.message}); using defaults."
|
|
67
|
+
{}
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
module EnrichedMarkdownCodeHighlight
|
|
72
|
+
# Locate grammar-versions.json in both layouts, mirroring how gen-registry.mjs
|
|
73
|
+
# is resolved below: "<podspec_dir>/../../vendor" in the monorepo, and the copy
|
|
74
|
+
# dropped into "<podspec_dir>/cpp/highlight" by prepare-npm-publish.sh when
|
|
75
|
+
# published.
|
|
76
|
+
def self.manifest_path(podspec_dir)
|
|
77
|
+
[
|
|
78
|
+
File.join(podspec_dir, '../../vendor/grammar-versions.json'),
|
|
79
|
+
File.join(podspec_dir, 'cpp/highlight/grammar-versions.json'),
|
|
80
|
+
].find { |p| File.exist?(p) }
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# The default language set: every grammar flagged default:true in the manifest.
|
|
84
|
+
def self.default_languages(podspec_dir)
|
|
85
|
+
manifest = manifest_path(podspec_dir)
|
|
86
|
+
raise '[code-highlight] grammar-versions.json not found; cannot resolve the ' \
|
|
87
|
+
'default language set. Build from the monorepo or a published tarball.' unless manifest
|
|
88
|
+
grammars = JSON.parse(File.read(manifest))['grammars'] || {}
|
|
89
|
+
grammars.select { |_id, spec| spec['default'] }.keys
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# podspec_dir is the directory of the including podspec; cpp is reached at
|
|
93
|
+
# "<podspec_dir>/cpp" (a symlink in the monorepo, real files when published).
|
|
94
|
+
def self.config(podspec_dir)
|
|
95
|
+
config = EnrichedMarkdownConfig.consumer_config
|
|
96
|
+
env_enable = ENV['ENRICHED_MARKDOWN_ENABLE_CODE_HIGHLIGHT']
|
|
97
|
+
|
|
98
|
+
# Enable flag: package.json > ENV (deprecated) > default on. `explicit` tracks
|
|
99
|
+
# whether the consumer actively opted in (vs the implicit default), which decides
|
|
100
|
+
# the missing-asset behavior below.
|
|
101
|
+
if config.key?('enableCodeHighlight')
|
|
102
|
+
requested = config['enableCodeHighlight'] != false
|
|
103
|
+
explicit = requested
|
|
104
|
+
if env_enable
|
|
105
|
+
EnrichedMarkdownConfig.warn_once(:code_highlight_env, '[ReactNativeEnrichedMarkdown] DEPRECATED: ENV[\'ENRICHED_MARKDOWN_ENABLE_CODE_HIGHLIGHT\'] ' \
|
|
106
|
+
'is ignored when "enriched-markdown".enableCodeHighlight is set in your package.json.')
|
|
107
|
+
end
|
|
108
|
+
elsif env_enable
|
|
109
|
+
EnrichedMarkdownConfig.warn_once(:code_highlight_env, '[ReactNativeEnrichedMarkdown] DEPRECATED: ENV[\'ENRICHED_MARKDOWN_ENABLE_CODE_HIGHLIGHT\'] ' \
|
|
110
|
+
'will be removed in a future version. Configure via "enriched-markdown".enableCodeHighlight in your package.json instead.')
|
|
111
|
+
requested = env_enable != '0'
|
|
112
|
+
explicit = requested
|
|
113
|
+
else
|
|
114
|
+
requested = true
|
|
115
|
+
explicit = false
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
return disabled unless requested
|
|
119
|
+
|
|
120
|
+
# The grammars/.stamp marker is written only after every grammar source is fully
|
|
121
|
+
# vendored at postinstall. If the consumer explicitly enabled highlighting but the
|
|
122
|
+
# grammars are absent (opted out of the download, or a partial/failed one), fail
|
|
123
|
+
# loud with the fix. If highlighting is merely on by default, degrade to the no-op
|
|
124
|
+
# stub so a missing download never breaks an otherwise-unconfigured build.
|
|
125
|
+
unless File.exist?(File.join(podspec_dir, 'cpp/highlight/vendor/grammars/.stamp'))
|
|
126
|
+
if explicit
|
|
127
|
+
raise '[ReactNativeEnrichedMarkdown] code highlighting is enabled but the tree-sitter ' \
|
|
128
|
+
'grammars are not installed. Reinstall to fetch them: `npm rebuild react-native-enriched-markdown-scaffold`. ' \
|
|
129
|
+
'To disable, set "enriched-markdown".enableCodeHighlight = false in your app package.json. ' \
|
|
130
|
+
'Troubleshooting: https://github.com/software-mansion/enriched-markdown/blob/main/docs/NATIVE_ASSETS.md'
|
|
131
|
+
end
|
|
132
|
+
return disabled
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
defaults = default_languages(podspec_dir)
|
|
136
|
+
# Languages: package.json > ENV (deprecated) > manifest defaults. An explicit empty
|
|
137
|
+
# array disables all languages (return disabled below); only the default/ENV paths
|
|
138
|
+
# fall back to the manifest set.
|
|
139
|
+
if config['codeHighlightLanguages'].is_a?(Array)
|
|
140
|
+
langs = config['codeHighlightLanguages'].map { |l| l.to_s.strip }.reject(&:empty?)
|
|
141
|
+
elsif (env_langs = ENV['ENRICHED_MARKDOWN_CODE_HIGHLIGHT_LANGUAGES']) && !env_langs.empty?
|
|
142
|
+
EnrichedMarkdownConfig.warn_once(:code_highlight_languages_env, '[ReactNativeEnrichedMarkdown] DEPRECATED: ENV[\'ENRICHED_MARKDOWN_CODE_HIGHLIGHT_LANGUAGES\'] ' \
|
|
143
|
+
'will be removed in a future version. Configure via "enriched-markdown".codeHighlightLanguages in your package.json instead.')
|
|
144
|
+
langs = env_langs.split(',').map(&:strip).reject(&:empty?)
|
|
145
|
+
langs = defaults.dup if langs.empty?
|
|
146
|
+
else
|
|
147
|
+
langs = defaults.dup
|
|
148
|
+
end
|
|
149
|
+
return disabled if langs.empty?
|
|
150
|
+
|
|
151
|
+
vendor = File.join(podspec_dir, 'cpp/highlight/vendor')
|
|
152
|
+
# A custom language set regenerates its registry into a per-app dir
|
|
153
|
+
# (generated-<app-slug>), never the committed default-set registry in vendor/generated.
|
|
154
|
+
# Keying by app (not by "generated-custom") means two apps in a hoisted monorepo with
|
|
155
|
+
# different custom sets each get their own registry instead of clobbering a single
|
|
156
|
+
# shared one -- which would leave the other app linking a mismatched grammar list.
|
|
157
|
+
custom = langs.sort != defaults.sort
|
|
158
|
+
generated_rel = custom ? "cpp/highlight/vendor/generated-#{EnrichedMarkdownConfig.consumer_app_slug}" : 'cpp/highlight/vendor/generated'
|
|
159
|
+
generated = File.join(podspec_dir, generated_rel)
|
|
160
|
+
ensure_registry(podspec_dir, vendor, generated, langs, custom)
|
|
161
|
+
|
|
162
|
+
sources = [
|
|
163
|
+
'cpp/highlight/vendor/tree-sitter/src/lib.c',
|
|
164
|
+
"#{generated_rel}/generated_registry.cpp",
|
|
165
|
+
]
|
|
166
|
+
langs.each do |lang|
|
|
167
|
+
sources << "cpp/highlight/vendor/grammars/#{lang}/parser.c"
|
|
168
|
+
if File.exist?(File.join(vendor, "grammars/#{lang}/scanner.c"))
|
|
169
|
+
sources << "cpp/highlight/vendor/grammars/#{lang}/scanner.c"
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
{
|
|
174
|
+
enabled: true,
|
|
175
|
+
source_files: sources,
|
|
176
|
+
defines: ' ENRICHED_MARKDOWN_CODE_HIGHLIGHT=1',
|
|
177
|
+
header_paths: [
|
|
178
|
+
'cpp/highlight/vendor/tree-sitter/include',
|
|
179
|
+
generated_rel,
|
|
180
|
+
],
|
|
181
|
+
}
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def self.disabled
|
|
185
|
+
{ enabled: false, source_files: [], defines: '', header_paths: [] }
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# The committed default-set registry ships in-tree, so the default case needs no
|
|
189
|
+
# codegen. A custom set (or a missing default registry) regenerates into `generated`
|
|
190
|
+
# from the vendored .scm files.
|
|
191
|
+
def self.ensure_registry(podspec_dir, vendor, generated, langs, custom)
|
|
192
|
+
return if !custom && File.exist?(File.join(generated, 'generated_registry.cpp'))
|
|
193
|
+
|
|
194
|
+
script = [
|
|
195
|
+
File.join(podspec_dir, '../../vendor/gen-registry.mjs'),
|
|
196
|
+
File.join(podspec_dir, 'cpp/highlight/gen-registry.mjs'),
|
|
197
|
+
].find { |p| File.exist?(p) }
|
|
198
|
+
raise '[code-highlight] ENRICHED_MARKDOWN_CODE_HIGHLIGHT_LANGUAGES is customized but ' \
|
|
199
|
+
'vendor/gen-registry.mjs was not found. Use the default set or build from the monorepo.' unless script
|
|
200
|
+
|
|
201
|
+
# Canonicalize before handing the path to node: in the monorepo the package is
|
|
202
|
+
# a workspace symlink, so the "../.." above resolves correctly for File.exist?
|
|
203
|
+
# (which follows the symlink physically) but node would normalize ".." lexically
|
|
204
|
+
# from the symlink location and miss the file. Android already does this via
|
|
205
|
+
# File#canonicalPath.
|
|
206
|
+
script = File.realpath(script)
|
|
207
|
+
|
|
208
|
+
ok = system('node', script, '--vendor-dir', vendor, '--languages', langs.join(','), '--out', generated)
|
|
209
|
+
raise '[code-highlight] gen-registry.mjs failed' unless ok
|
|
210
|
+
end
|
|
211
|
+
end
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Build-time (and offline): emits the grammar registry for a selected language
|
|
3
|
+
// subset from the in-tree vendored files. No network, reads only --vendor-dir.
|
|
4
|
+
// Invoked by the Android CMake configure step and the iOS podspec, and by
|
|
5
|
+
// vendor-grammars.mjs to refresh the committed default set.
|
|
6
|
+
//
|
|
7
|
+
// node vendor/gen-registry.mjs --vendor-dir <dir> --languages a,b,c --out <dir>
|
|
8
|
+
//
|
|
9
|
+
// Writes <out>/generated_queries.h and <out>/generated_registry.cpp referencing
|
|
10
|
+
// only the selected grammars, so the link step stays valid no matter how many
|
|
11
|
+
// grammars are vendored. `; inherits:` directives are resolved by inlining the
|
|
12
|
+
// parent grammar's highlights (parents come first, child overrides).
|
|
13
|
+
|
|
14
|
+
import fs from 'node:fs';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
|
|
18
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
|
|
20
|
+
const LOG_PREFIX = '[react-native-enriched-markdown-scaffold]';
|
|
21
|
+
const log = (message) => console.log(`${LOG_PREFIX} ${message}`);
|
|
22
|
+
const warn = (message) => console.warn(`${LOG_PREFIX} ${message}`);
|
|
23
|
+
const fail = (message) => {
|
|
24
|
+
console.error(`${LOG_PREFIX} ${message}`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function parseArgs(argv) {
|
|
29
|
+
const args = { vendorDir: null, languages: [], out: null, manifest: path.join(here, 'grammar-versions.json') };
|
|
30
|
+
for (let i = 0; i < argv.length; i++) {
|
|
31
|
+
const a = argv[i];
|
|
32
|
+
if (a === '--vendor-dir') args.vendorDir = argv[++i];
|
|
33
|
+
else if (a === '--languages') args.languages = argv[++i].split(',').map((s) => s.trim()).filter(Boolean);
|
|
34
|
+
else if (a === '--out') args.out = argv[++i];
|
|
35
|
+
else if (a === '--manifest') args.manifest = argv[++i];
|
|
36
|
+
}
|
|
37
|
+
if (!args.vendorDir || !args.out) {
|
|
38
|
+
fail('usage: --vendor-dir <dir> --languages a,b --out <dir>');
|
|
39
|
+
}
|
|
40
|
+
return args;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function identifier(id) {
|
|
44
|
+
return id.replace(/[^A-Za-z0-9]/g, '_');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function grammarFunction(id, manifest) {
|
|
48
|
+
const spec = manifest.grammars?.[id];
|
|
49
|
+
return spec?.function ?? `tree_sitter_${identifier(id)}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function highlightsPath(vendorDir, id) {
|
|
53
|
+
return path.join(vendorDir, 'grammars', id, 'highlights.scm');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const INHERITS_RE = /^[ \t]*;+[ \t]*inherits[ \t]*:[ \t]*([^\n]+)$/m;
|
|
57
|
+
|
|
58
|
+
// Reads a grammar's highlights.scm and inlines any `; inherits:` parents that
|
|
59
|
+
// are also vendored. Cycle-guarded; a missing parent is skipped with a warning.
|
|
60
|
+
function resolveHighlights(vendorDir, id, seen = new Set()) {
|
|
61
|
+
const file = highlightsPath(vendorDir, id);
|
|
62
|
+
if (!fs.existsSync(file)) {
|
|
63
|
+
fail(`missing vendored highlights for '${id}': ${file}`);
|
|
64
|
+
}
|
|
65
|
+
if (seen.has(id)) return '';
|
|
66
|
+
seen.add(id);
|
|
67
|
+
|
|
68
|
+
const raw = fs.readFileSync(file, 'utf8');
|
|
69
|
+
const match = raw.match(INHERITS_RE);
|
|
70
|
+
let inherited = '';
|
|
71
|
+
if (match) {
|
|
72
|
+
for (const parent of match[1].split(',').map((s) => s.trim()).filter(Boolean)) {
|
|
73
|
+
if (fs.existsSync(highlightsPath(vendorDir, parent))) {
|
|
74
|
+
inherited += resolveHighlights(vendorDir, parent, seen) + '\n';
|
|
75
|
+
} else {
|
|
76
|
+
warn(`${id} inherits '${parent}' which is not vendored; skipping inheritance`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const body = raw.replace(INHERITS_RE, '');
|
|
81
|
+
return inherited + body;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function toCStringLines(text) {
|
|
85
|
+
const lines = text.split('\n');
|
|
86
|
+
return lines
|
|
87
|
+
.map((line, i) => {
|
|
88
|
+
// Escape backslashes, quotes, and every '?' so sequences like "??=" in a
|
|
89
|
+
// query never form a C trigraph.
|
|
90
|
+
const escaped = line.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\?/g, '\\?');
|
|
91
|
+
const newline = i < lines.length - 1 ? '\\n' : '';
|
|
92
|
+
return ` "${escaped}${newline}"`;
|
|
93
|
+
})
|
|
94
|
+
.join('\n');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function main() {
|
|
98
|
+
const args = parseArgs(process.argv.slice(2));
|
|
99
|
+
const manifest = JSON.parse(fs.readFileSync(args.manifest, 'utf8'));
|
|
100
|
+
fs.mkdirSync(args.out, { recursive: true });
|
|
101
|
+
|
|
102
|
+
const entries = args.languages.map((id) => ({
|
|
103
|
+
id,
|
|
104
|
+
ident: identifier(id),
|
|
105
|
+
fn: grammarFunction(id, manifest),
|
|
106
|
+
query: resolveHighlights(args.vendorDir, id),
|
|
107
|
+
}));
|
|
108
|
+
|
|
109
|
+
const queriesHeader =
|
|
110
|
+
'#pragma once\n' +
|
|
111
|
+
'// Generated by vendor/gen-registry.mjs. Do not edit.\n\n' +
|
|
112
|
+
'namespace Markdown {\n\n' +
|
|
113
|
+
entries
|
|
114
|
+
.map((e) => `static const char kHighlightsQuery_${e.ident}[] =\n${toCStringLines(e.query)};\n`)
|
|
115
|
+
.join('\n') +
|
|
116
|
+
'\n} // namespace Markdown\n';
|
|
117
|
+
|
|
118
|
+
const header =
|
|
119
|
+
'// Generated by vendor/gen-registry.mjs. Do not edit.\n\n' +
|
|
120
|
+
'#include "HighlightGrammars.hpp"\n' +
|
|
121
|
+
'#include "generated_queries.h"\n\n' +
|
|
122
|
+
'#include <cstring>\n\n';
|
|
123
|
+
|
|
124
|
+
let registryCpp;
|
|
125
|
+
if (entries.length === 0) {
|
|
126
|
+
registryCpp =
|
|
127
|
+
header +
|
|
128
|
+
'namespace Markdown {\n\n' +
|
|
129
|
+
'const GrammarEntry *findGrammar(const char * /*canonicalId*/) {\n return nullptr;\n}\n\n' +
|
|
130
|
+
'} // namespace Markdown\n';
|
|
131
|
+
} else {
|
|
132
|
+
registryCpp =
|
|
133
|
+
header +
|
|
134
|
+
'extern "C" {\n' +
|
|
135
|
+
entries.map((e) => `const TSLanguage *${e.fn}(void);`).join('\n') +
|
|
136
|
+
'\n}\n\n' +
|
|
137
|
+
'namespace Markdown {\nnamespace {\n\n' +
|
|
138
|
+
'constexpr GrammarEntry kGrammars[] = {\n' +
|
|
139
|
+
entries.map((e) => ` {"${e.id}", ${e.fn}, kHighlightsQuery_${e.ident}},`).join('\n') +
|
|
140
|
+
'\n};\n\n' +
|
|
141
|
+
'} // namespace\n\n' +
|
|
142
|
+
'const GrammarEntry *findGrammar(const char *canonicalId) {\n' +
|
|
143
|
+
' if (canonicalId == nullptr) {\n return nullptr;\n }\n' +
|
|
144
|
+
' for (const GrammarEntry &entry : kGrammars) {\n' +
|
|
145
|
+
' if (std::strcmp(entry.canonicalId, canonicalId) == 0) {\n return &entry;\n }\n }\n' +
|
|
146
|
+
' return nullptr;\n}\n\n' +
|
|
147
|
+
'} // namespace Markdown\n';
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
fs.writeFileSync(path.join(args.out, 'generated_queries.h'), queriesHeader);
|
|
151
|
+
fs.writeFileSync(path.join(args.out, 'generated_registry.cpp'), registryCpp);
|
|
152
|
+
log(`wrote ${entries.length} grammar(s) to ${args.out}`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
main();
|