react-native-enriched-markdown-scaffold 1.0.2-scaffold.9 → 1.2.0-scaffold.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReactNativeEnrichedMarkdown.podspec +31 -10
- package/android/build.gradle +49 -12
- package/android/consumer-rules.pro +3 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerDelegate.java +18 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerInterface.java +6 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextInputManagerDelegate.java +3 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextInputManagerInterface.java +1 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerDelegate.java +18 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerInterface.java +6 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.cpp +62 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.h +44 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.cpp +67 -2
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.h +929 -178
- package/android/src/main/baseline-prof.txt +21 -22
- package/android/src/main/cpp/jni-adapter.cpp +17 -5
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdown.kt +729 -768
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownInternalText.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownManager.kt +72 -3
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownText.kt +222 -8
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownTextManager.kt +65 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/MeasurementStore.kt +191 -26
- package/android/src/main/java/com/swmansion/enriched/markdown/accessibility/AccessibleMarkdownTextView.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/accessibility/MarkdownAccessibilityHelper.kt +54 -6
- package/android/src/main/java/com/swmansion/enriched/markdown/events/CodeBlockPressEvent.kt +24 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/events/ImagePressEvent.kt +25 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/events/LatexErrorEvent.kt +29 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/EnrichedMarkdownTextInputManager.kt +21 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/EnrichedMarkdownTextInputView.kt +101 -9
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/EditPipeline.kt +48 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/InputConnectionWrapper.kt +7 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/MarkdownShortcutMatcher.kt +64 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/formatting/InputRemend.kt +44 -6
- package/android/src/main/java/com/swmansion/enriched/markdown/input/layout/InputEventEmitter.kt +9 -8
- package/android/src/main/java/com/swmansion/enriched/markdown/math/LatexErrorReporter.kt +9 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/parser/MarkdownASTNode.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/parser/Parser.kt +5 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlankLineRenderer.kt +38 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockStyleContext.kt +2 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockquoteRenderer.kt +3 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockquoteTextRenderer.kt +55 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/CodeBlockRenderer.kt +8 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/HighlightRenderer.kt +10 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/NodeRenderer.kt +31 -3
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/ParagraphRenderer.kt +17 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/Renderer.kt +40 -21
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/AdmonitionIcons.kt +62 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{views → segments}/BlockSegmentView.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/BlockquoteContainerView.kt +401 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{views → segments}/CodeBlockContainerView.kt +55 -16
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/ContainerNodeView.kt +164 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{utils/common → segments}/MarkdownSegment.kt +21 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/RenderedSegment.kt +137 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentHeightMeasurer.kt +139 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{utils/common → segments}/SegmentReconciler.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/{utils/common → segments}/SegmentSignature.kt +3 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentViewCreators.kt +262 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentViewFactory.kt +29 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{views → segments}/TableContainerView.kt +100 -36
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/CodeBackgroundSpan.kt +18 -17
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/CodeBlockSpan.kt +3 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/HighlightSpan.kt +60 -6
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/ImageSpan.kt +15 -5
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/InlineBackgroundGeometry.kt +42 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/InlineChipPainter.kt +4 -27
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/LineHeightSpan.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/LinkSpan.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/spoiler/SpoilerDrawUtils.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/BlockquoteStyle.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/LinkVariantEntry.kt +2 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/StyleConfig.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/VideoStyle.kt +31 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/BorderStyleUtils.kt +86 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/EllipsizeUtils.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/EnrichedMarkdownAncestorUtils.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/FeatureFlags.kt +1 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/MarkdownViewManagerUtils.kt +36 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/ReadableMapExtensions.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/serialization/MarkdownASTSerializer.kt +227 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/input/PasteTextUtils.kt +34 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/conversion/HTMLGenerator.kt +50 -28
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/conversion/MarkdownExtractor.kt +16 -21
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/extensions/SpannableExtensions.kt +4 -3
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/span/BlockSpacing.kt +3 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/span/SpanFlags.kt +13 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/CodeBlockPressHost.kt +15 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/ImagePressHost.kt +19 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/LinkEvents.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/LinkLongPressMovementMethod.kt +87 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/TextViewSetup.kt +79 -0
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/conversions.h +2 -0
- package/android/src/math/java/com/swmansion/enriched/markdown/renderer/MathInlineRenderer.kt +9 -3
- package/android/src/math/java/com/swmansion/enriched/markdown/{views → segments}/MathContainerView.kt +86 -29
- package/android/src/math/java/com/swmansion/enriched/markdown/spans/MathInlineSpan.kt +33 -7
- package/android/src/video/java/com/swmansion/enriched/markdown/segments/VideoContainerView.kt +115 -0
- package/cpp/md4c/md4c.c +343 -236
- package/cpp/md4c/md4c.h +28 -11
- package/cpp/parser/MD4CParser.cpp +266 -4
- package/cpp/parser/MD4CParser.hpp +6 -2
- package/cpp/parser/MarkdownASTNode.hpp +4 -1
- package/cpp/wasm/ASTSerializer.cpp +6 -0
- package/cpp/wasm/md4c_wasm.cpp +5 -1
- package/docs/API_REFERENCE.md +199 -12
- package/docs/BREAKING_CHANGES.md +75 -0
- package/docs/CODE_HIGHLIGHT.md +4 -0
- package/docs/COPY_OPTIONS.md +52 -9
- package/docs/ELEMENTS_STRUCTURE.md +48 -1
- package/docs/INPUT.md +60 -3
- package/docs/LATEX_MATH.md +30 -0
- package/docs/MACOS.md +1 -1
- package/docs/MENTIONS.md +2 -2
- package/docs/STYLES.md +27 -0
- package/docs/TEXT.md +8 -0
- package/docs/WEB.md +44 -10
- package/ios/EnrichedMarkdown.mm +285 -43
- package/ios/EnrichedMarkdownText.mm +185 -23
- package/ios/attachments/ENRMImageAttachment.h +17 -2
- package/ios/attachments/ENRMImageAttachment.m +26 -28
- package/ios/attachments/ENRMMathInlineAttachment+macOS.m +10 -2
- package/ios/attachments/ENRMMathInlineAttachment.h +3 -1
- package/ios/attachments/ENRMMathInlineAttachment.m +17 -1
- package/ios/attachments/ENRMMathInlineAttachmentShared.h +3 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/EventEmitters.cpp +62 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/EventEmitters.h +44 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.cpp +67 -2
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.h +929 -178
- package/ios/input/ENRMInputFormatter.mm +68 -12
- package/ios/input/ENRMInputFormatterStyle.mm +9 -2
- package/ios/input/ENRMInputParser.mm +18 -0
- package/ios/input/ENRMInputRemend.mm +40 -3
- package/ios/input/ENRMMarkdownShortcutMatcher.h +39 -0
- package/ios/input/ENRMMarkdownShortcutMatcher.mm +66 -0
- package/ios/input/EnrichedMarkdownTextInput.mm +129 -1
- package/ios/internals/ENRMViewFreeMeasurement.h +45 -6
- package/ios/internals/MeasurementCache.h +20 -4
- package/ios/internals/ShadowMeasurementUtils.h +2 -0
- package/ios/math/ENRMLatexErrorCoordinator.h +27 -0
- package/ios/math/ENRMLatexErrorCoordinator.mm +75 -0
- package/ios/math/ENRMLatexErrorReporting.h +13 -0
- package/ios/math/ENRMRaTeXBridge.swift +46 -3
- package/ios/parser/ENRMMarkdownParser.h +3 -0
- package/ios/parser/ENRMMarkdownParser.mm +11 -2
- package/ios/parser/MarkdownASTNode.h +8 -1
- package/ios/parser/MarkdownASTNode.m +20 -0
- package/ios/parser/MarkdownParserBridge.mm +13 -2
- package/ios/renderer/AttributedRenderer.h +13 -1
- package/ios/renderer/AttributedRenderer.m +24 -13
- package/ios/renderer/BaselineShiftTextAttributes.h +4 -0
- package/ios/renderer/BaselineShiftTextAttributes.m +4 -0
- package/ios/renderer/BlankLineRenderer.h +4 -0
- package/ios/renderer/BlankLineRenderer.m +51 -0
- package/ios/renderer/BlockquoteRenderer.m +1 -0
- package/ios/renderer/CodeBlockRenderer.m +8 -0
- package/ios/renderer/CodeRenderer.m +5 -2
- package/ios/renderer/ENRMBlockquoteTextRenderer.h +25 -0
- package/ios/renderer/ENRMBlockquoteTextRenderer.m +48 -0
- package/ios/renderer/ENRMImageRenderer.m +1 -1
- package/ios/renderer/ENRMMathInlineRenderer.m +9 -1
- package/ios/renderer/HeadingRenderer.m +1 -0
- package/ios/renderer/HighlightRenderer.m +6 -0
- package/ios/renderer/LinkRenderer.m +1 -1
- package/ios/renderer/ListItemRenderer.m +51 -2
- package/ios/renderer/ParagraphRenderer.m +10 -3
- package/ios/renderer/RenderContext.h +16 -0
- package/ios/renderer/RenderContext.m +16 -0
- package/ios/renderer/RendererFactory.m +6 -0
- package/ios/renderer/SubscriptRenderer.m +1 -0
- package/ios/renderer/SuperscriptRenderer.m +1 -0
- package/ios/segments/ENRMAdmonitionIcons.h +31 -0
- package/ios/segments/ENRMAdmonitionIcons.m +93 -0
- package/ios/segments/ENRMBlockquoteContainerView.h +90 -0
- package/ios/segments/ENRMBlockquoteContainerView.mm +551 -0
- package/ios/{views → segments}/ENRMCodeBlockContainerView.h +9 -4
- package/ios/{views → segments}/ENRMCodeBlockContainerView.m +147 -36
- package/ios/segments/ENRMContainerNodeView.h +52 -0
- package/ios/segments/ENRMContainerNodeView.mm +201 -0
- package/ios/segments/ENRMDynamicBlockProps.h +32 -0
- package/ios/segments/ENRMDynamicBlockProps.m +15 -0
- package/ios/{views → segments}/ENRMMathContainerView.h +13 -5
- package/ios/{views → segments}/ENRMMathContainerView.m +60 -9
- package/ios/segments/ENRMSVGPath.h +21 -0
- package/ios/segments/ENRMSVGPath.m +409 -0
- package/ios/segments/ENRMSegmentHeightMeasurer.h +33 -0
- package/ios/segments/ENRMSegmentHeightMeasurer.mm +94 -0
- package/ios/segments/ENRMVideoContainerView.h +40 -0
- package/ios/segments/ENRMVideoContainerView.m +421 -0
- package/ios/{utils → segments}/RenderedMarkdownSegment.h +19 -2
- package/ios/{utils → segments}/RenderedMarkdownSegment.m +42 -1
- package/ios/segments/SegmentRenderer.h +26 -0
- package/ios/{utils → segments}/SegmentRenderer.m +46 -9
- package/ios/{views → segments}/TableContainerView.h +5 -4
- package/ios/{views → segments}/TableContainerView.m +96 -12
- package/ios/styles/StyleConfig.h +17 -0
- package/ios/styles/StyleConfig.mm +90 -0
- package/ios/utils/ENRMCodeBlockContent.mm +13 -0
- package/ios/utils/ENRMFeatureFlags.h +6 -0
- package/ios/utils/ENRMTextRenderer.h +8 -0
- package/ios/utils/ENRMTextRenderer.m +26 -10
- package/ios/utils/ENRMUIKit.h +1 -0
- package/ios/utils/FontUtils.h +2 -1
- package/ios/utils/FontUtils.m +22 -6
- package/ios/utils/LinkTapUtils.h +17 -2
- package/ios/utils/LinkTapUtils.m +44 -2
- package/ios/utils/ListMarkerDrawer.m +25 -1
- package/ios/utils/MarkdownASTSerializer.h +7 -0
- package/ios/utils/MarkdownASTSerializer.m +243 -0
- package/ios/utils/MarkdownAccessibilityElementBuilder.m +9 -67
- package/ios/utils/MarkdownExtractor.m +6 -3
- package/ios/utils/ParagraphStyleUtils.h +25 -1
- package/ios/utils/ParagraphStyleUtils.m +51 -7
- package/ios/utils/StylePropsUtils.h +60 -1
- package/ios/utils/TextViewLayoutManager.mm +57 -0
- package/lib/module/EnrichedMarkdownNativeComponent.ts +110 -4
- package/lib/module/EnrichedMarkdownTextInput.js +60 -2
- package/lib/module/EnrichedMarkdownTextInput.js.map +1 -1
- package/lib/module/EnrichedMarkdownTextInputNativeComponent.ts +12 -0
- package/lib/module/EnrichedMarkdownTextNativeComponent.ts +115 -4
- package/lib/module/admonitionDefaults.js +34 -0
- package/lib/module/admonitionDefaults.js.map +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/jest/index.js +84 -4
- package/lib/module/jest/index.js.map +1 -1
- package/lib/module/native/EnrichedMarkdownText.js +58 -5
- package/lib/module/native/EnrichedMarkdownText.js.map +1 -1
- package/lib/module/normalizeMarkdownShortcuts.js +31 -0
- package/lib/module/normalizeMarkdownShortcuts.js.map +1 -0
- package/lib/module/normalizeMarkdownStyle.js +15 -1
- package/lib/module/normalizeMarkdownStyle.js.map +1 -1
- package/lib/module/normalizeMarkdownStyle.web.js +15 -1
- package/lib/module/normalizeMarkdownStyle.web.js.map +1 -1
- package/lib/module/styleUtils.js +15 -3
- package/lib/module/styleUtils.js.map +1 -1
- package/lib/module/utils/textInputState.js +4 -3
- package/lib/module/utils/textInputState.js.map +1 -1
- package/lib/module/utils/usePressability.js +28 -0
- package/lib/module/utils/usePressability.js.map +1 -0
- package/lib/module/web/EnrichedMarkdownText.js +19 -6
- package/lib/module/web/EnrichedMarkdownText.js.map +1 -1
- package/lib/module/web/globalStyles.js +7 -1
- package/lib/module/web/globalStyles.js.map +1 -1
- package/lib/module/web/nativeProps.js +70 -0
- package/lib/module/web/nativeProps.js.map +1 -0
- package/lib/module/web/parseMarkdown.js +5 -3
- package/lib/module/web/parseMarkdown.js.map +1 -1
- package/lib/module/web/renderers/BlockRenderers.js +164 -8
- package/lib/module/web/renderers/BlockRenderers.js.map +1 -1
- package/lib/module/web/renderers/admonitionIcons.js +34 -0
- package/lib/module/web/renderers/admonitionIcons.js.map +1 -0
- package/lib/module/web/styles.js +30 -8
- package/lib/module/web/styles.js.map +1 -1
- package/lib/module/web/wasm/md4c.js +0 -0
- package/lib/module/web/wasm/md4c.js.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts +103 -3
- package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownTextInput.d.ts +27 -3
- package/lib/typescript/src/EnrichedMarkdownTextInput.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownTextInputNativeComponent.d.ts +11 -0
- package/lib/typescript/src/EnrichedMarkdownTextInputNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts +108 -3
- package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/admonitionDefaults.d.ts +10 -0
- package/lib/typescript/src/admonitionDefaults.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/index.web.d.ts +1 -1
- package/lib/typescript/src/index.web.d.ts.map +1 -1
- package/lib/typescript/src/jest/index.d.ts +2 -2
- package/lib/typescript/src/jest/index.d.ts.map +1 -1
- package/lib/typescript/src/native/EnrichedMarkdownText.d.ts +3 -3
- package/lib/typescript/src/native/EnrichedMarkdownText.d.ts.map +1 -1
- package/lib/typescript/src/normalizeMarkdownShortcuts.d.ts +7 -0
- package/lib/typescript/src/normalizeMarkdownShortcuts.d.ts.map +1 -0
- package/lib/typescript/src/normalizeMarkdownStyle.d.ts.map +1 -1
- package/lib/typescript/src/normalizeMarkdownStyle.web.d.ts.map +1 -1
- package/lib/typescript/src/styleUtils.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownStyle.d.ts +59 -1
- package/lib/typescript/src/types/MarkdownStyle.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownStyleInternal.d.ts +21 -0
- package/lib/typescript/src/types/MarkdownStyleInternal.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownTextProps.d.ts +93 -8
- package/lib/typescript/src/types/MarkdownTextProps.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownTextProps.web.d.ts +25 -1
- package/lib/typescript/src/types/MarkdownTextProps.web.d.ts.map +1 -1
- package/lib/typescript/src/types/events.d.ts +33 -5
- package/lib/typescript/src/types/events.d.ts.map +1 -1
- package/lib/typescript/src/utils/textInputState.d.ts +5 -3
- package/lib/typescript/src/utils/textInputState.d.ts.map +1 -1
- package/lib/typescript/src/utils/usePressability.d.ts +24 -0
- package/lib/typescript/src/utils/usePressability.d.ts.map +1 -0
- package/lib/typescript/src/web/EnrichedMarkdownText.d.ts +1 -1
- package/lib/typescript/src/web/EnrichedMarkdownText.d.ts.map +1 -1
- package/lib/typescript/src/web/globalStyles.d.ts +1 -0
- package/lib/typescript/src/web/globalStyles.d.ts.map +1 -1
- package/lib/typescript/src/web/nativeProps.d.ts +34 -0
- package/lib/typescript/src/web/nativeProps.d.ts.map +1 -0
- package/lib/typescript/src/web/parseMarkdown.d.ts +1 -1
- package/lib/typescript/src/web/parseMarkdown.d.ts.map +1 -1
- package/lib/typescript/src/web/renderers/BlockRenderers.d.ts.map +1 -1
- package/lib/typescript/src/web/renderers/admonitionIcons.d.ts +5 -0
- package/lib/typescript/src/web/renderers/admonitionIcons.d.ts.map +1 -0
- package/lib/typescript/src/web/styles.d.ts +1 -0
- package/lib/typescript/src/web/styles.d.ts.map +1 -1
- package/lib/typescript/src/web/types.d.ts +8 -2
- package/lib/typescript/src/web/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/postinstall.mjs +7 -0
- package/src/EnrichedMarkdownNativeComponent.ts +110 -4
- package/src/EnrichedMarkdownTextInput.tsx +101 -4
- package/src/EnrichedMarkdownTextInputNativeComponent.ts +12 -0
- package/src/EnrichedMarkdownTextNativeComponent.ts +115 -4
- package/src/admonitionDefaults.ts +58 -0
- package/src/index.tsx +5 -0
- package/src/index.web.tsx +3 -0
- package/src/jest/index.tsx +138 -5
- package/src/native/EnrichedMarkdownText.tsx +55 -3
- package/src/normalizeMarkdownShortcuts.ts +38 -0
- package/src/normalizeMarkdownStyle.ts +17 -0
- package/src/normalizeMarkdownStyle.web.ts +17 -0
- package/src/styleUtils.ts +17 -6
- package/src/types/MarkdownStyle.ts +62 -1
- package/src/types/MarkdownStyleInternal.ts +24 -0
- package/src/types/MarkdownTextProps.ts +95 -7
- package/src/types/MarkdownTextProps.web.ts +26 -0
- package/src/types/events.ts +36 -5
- package/src/utils/textInputState.ts +5 -3
- package/src/utils/usePressability.ts +34 -0
- package/src/web/EnrichedMarkdownText.tsx +36 -3
- package/src/web/globalStyles.ts +10 -0
- package/src/web/nativeProps.ts +78 -0
- package/src/web/parseMarkdown.ts +10 -2
- package/src/web/renderers/BlockRenderers.tsx +175 -6
- package/src/web/renderers/admonitionIcons.ts +37 -0
- package/src/web/styles.ts +28 -3
- package/src/web/types.ts +12 -1
- package/src/web/wasm/md4c.js +0 -0
- package/vendor-ratex.mjs +86 -17
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/DocumentRenderer.kt +0 -16
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/RenderedSegment.kt +0 -88
- package/ios/utils/SegmentRenderer.h +0 -24
- /package/ios/{views → segments}/ENRMTableGridView.h +0 -0
- /package/ios/{views → segments}/ENRMTableGridView.m +0 -0
- /package/ios/{views → segments}/ENRMTableIOSGridView.h +0 -0
- /package/ios/{views → segments}/ENRMTableIOSGridView.m +0 -0
- /package/ios/{utils → segments}/SegmentReconciler.h +0 -0
- /package/ios/{utils → segments}/SegmentReconciler.m +0 -0
- /package/ios/{utils → segments}/SegmentViewRegistry.h +0 -0
- /package/ios/{utils → segments}/SegmentViewRegistry.m +0 -0
package/cpp/md4c/md4c.h
CHANGED
|
@@ -117,7 +117,12 @@ typedef enum MD_BLOCKTYPE {
|
|
|
117
117
|
/* Adminition extension.
|
|
118
118
|
* Detail MD_BLOCK_ADMONITION_DETAIL.
|
|
119
119
|
* Note: Recognized only when MD_FLAG_ADMONITIONS is enabled. */
|
|
120
|
-
MD_BLOCK_ADMONITION
|
|
120
|
+
MD_BLOCK_ADMONITION,
|
|
121
|
+
|
|
122
|
+
/* A run of blank lines separating two blocks. Has no contents.
|
|
123
|
+
* Detail: Structure MD_BLOCK_BLANK_DETAIL.
|
|
124
|
+
* Note: Emitted only when MD_FLAG_PRESERVEBLANKLINES is enabled. */
|
|
125
|
+
MD_BLOCK_BLANK
|
|
121
126
|
} MD_BLOCKTYPE;
|
|
122
127
|
|
|
123
128
|
/* Span represents an in-line piece of a document which should be rendered with
|
|
@@ -145,6 +150,11 @@ typedef enum MD_SPANTYPE {
|
|
|
145
150
|
/* <code>...</code> */
|
|
146
151
|
MD_SPAN_CODE,
|
|
147
152
|
|
|
153
|
+
/* <ins>...</ins>
|
|
154
|
+
* Syntax: ++insert++
|
|
155
|
+
* Note: Recognized only when MD_FLAG_INSERT is enabled. */
|
|
156
|
+
MD_SPAN_INS,
|
|
157
|
+
|
|
148
158
|
/* <del>...</del>
|
|
149
159
|
* Note: Recognized only when MD_FLAG_STRIKETHROUGH is enabled.
|
|
150
160
|
*/
|
|
@@ -359,6 +369,11 @@ typedef struct MD_BLOCK_FOOTNOTE_DEF_DETAIL {
|
|
|
359
369
|
MD_ATTRIBUTE label; /* Raw label text */
|
|
360
370
|
} MD_BLOCK_FOOTNOTE_DEF_DETAIL;
|
|
361
371
|
|
|
372
|
+
/* Detailed info for MD_BLOCK_BLANK. */
|
|
373
|
+
typedef struct MD_BLOCK_BLANK_DETAIL {
|
|
374
|
+
unsigned line_count; /* Count of blank lines forming the block separation */
|
|
375
|
+
} MD_BLOCK_BLANK_DETAIL;
|
|
376
|
+
|
|
362
377
|
/* Flags specifying extensions/deviations from CommonMark specification.
|
|
363
378
|
*
|
|
364
379
|
* By default (when MD_PARSER::flags == 0), we follow CommonMark specification.
|
|
@@ -376,16 +391,18 @@ typedef struct MD_BLOCK_FOOTNOTE_DEF_DETAIL {
|
|
|
376
391
|
#define MD_FLAG_PERMISSIVEWWWAUTOLINKS \
|
|
377
392
|
0x400 /* Enable WWW autolinks (even without any scheme prefix, if they begin with 'www.') */
|
|
378
393
|
#define MD_FLAG_TASKLISTS 0x800 /* Enable task list extension. */
|
|
379
|
-
#define MD_FLAG_LATEXMATHSPANS 0x1000
|
|
380
|
-
#define MD_FLAG_WIKILINKS 0x2000
|
|
381
|
-
#define MD_FLAG_UNDERLINE 0x4000
|
|
382
|
-
#define MD_FLAG_HARD_SOFT_BREAKS 0x8000
|
|
383
|
-
#define MD_FLAG_SPOILERS 0x10000
|
|
384
|
-
#define MD_FLAG_SUPERSCRIPTS 0x20000
|
|
385
|
-
#define MD_FLAG_SUBSCRIPTS 0x40000
|
|
386
|
-
#define MD_FLAG_ADMONITIONS 0x80000
|
|
387
|
-
#define MD_FLAG_FOOTNOTES 0x100000
|
|
388
|
-
#define MD_FLAG_HIGHLIGHT 0x200000
|
|
394
|
+
#define MD_FLAG_LATEXMATHSPANS 0x1000 /* Enable $ and $$ containing LaTeX equations. */
|
|
395
|
+
#define MD_FLAG_WIKILINKS 0x2000 /* Enable wiki links extension. */
|
|
396
|
+
#define MD_FLAG_UNDERLINE 0x4000 /* Enable underline extension (and disables '_' for normal emphasis). */
|
|
397
|
+
#define MD_FLAG_HARD_SOFT_BREAKS 0x8000 /* Force all soft breaks to act as hard breaks. */
|
|
398
|
+
#define MD_FLAG_SPOILERS 0x10000 /* Enable ||hidden text|| spoiler spans. */
|
|
399
|
+
#define MD_FLAG_SUPERSCRIPTS 0x20000 /* Enable ^superscript^ spans. */
|
|
400
|
+
#define MD_FLAG_SUBSCRIPTS 0x40000 /* Enable ~subscript~ spans. */
|
|
401
|
+
#define MD_FLAG_ADMONITIONS 0x80000 /* Enable admonitions extension. */
|
|
402
|
+
#define MD_FLAG_FOOTNOTES 0x100000 /* Enable [^label] footnote references. */
|
|
403
|
+
#define MD_FLAG_HIGHLIGHT 0x200000 /* Enable ==highlight== spans. */
|
|
404
|
+
#define MD_FLAG_PRESERVEBLANKLINES 0x400000 /* Report blank line runs as MD_BLOCK_BLANK. */
|
|
405
|
+
#define MD_FLAG_INSERT 0x800000 /* Enable insert extension. */
|
|
389
406
|
|
|
390
407
|
#define MD_FLAG_PERMISSIVEAUTOLINKS \
|
|
391
408
|
(MD_FLAG_PERMISSIVEEMAILAUTOLINKS | MD_FLAG_PERMISSIVEURLAUTOLINKS | MD_FLAG_PERMISSIVEWWWAUTOLINKS)
|
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
#include "MD4CParser.hpp"
|
|
2
2
|
#include "../md4c/md4c.h"
|
|
3
|
+
#include <cctype>
|
|
3
4
|
#include <cstring>
|
|
4
5
|
#include <vector>
|
|
5
6
|
|
|
6
7
|
namespace Markdown {
|
|
7
8
|
|
|
9
|
+
namespace {
|
|
10
|
+
struct HtmlTag {
|
|
11
|
+
std::string name;
|
|
12
|
+
std::unordered_map<std::string, std::string> attributes;
|
|
13
|
+
};
|
|
14
|
+
HtmlTag parseHtmlOpenTag(const std::string &html);
|
|
15
|
+
std::shared_ptr<MarkdownASTNode> tryPromoteHtmlBlock(const std::string &html);
|
|
16
|
+
} // namespace
|
|
17
|
+
|
|
8
18
|
class MD4CParser::Impl {
|
|
9
19
|
public:
|
|
10
20
|
std::shared_ptr<MarkdownASTNode> root;
|
|
11
21
|
std::vector<std::shared_ptr<MarkdownASTNode>> nodeStack;
|
|
12
22
|
std::string currentText;
|
|
13
23
|
const char *inputText = nullptr;
|
|
24
|
+
bool inHtmlBlock = false;
|
|
25
|
+
std::string htmlBlockContent;
|
|
14
26
|
|
|
15
27
|
static const std::string ATTR_LEVEL;
|
|
16
28
|
static const std::string ATTR_URL;
|
|
@@ -20,6 +32,8 @@ public:
|
|
|
20
32
|
static const std::string ATTR_IS_TASK;
|
|
21
33
|
static const std::string ATTR_TASK_CHECKED;
|
|
22
34
|
static const std::string ATTR_START;
|
|
35
|
+
static const std::string ATTR_BLANK_LINE_COUNT;
|
|
36
|
+
static const std::string ATTR_ADMONITION_TYPE;
|
|
23
37
|
|
|
24
38
|
void reset(size_t estimatedDepth) {
|
|
25
39
|
root = std::make_shared<MarkdownASTNode>(NodeType::Document);
|
|
@@ -31,6 +45,8 @@ public:
|
|
|
31
45
|
nodeStack.push_back(root);
|
|
32
46
|
currentText.clear();
|
|
33
47
|
currentText.reserve(256);
|
|
48
|
+
inHtmlBlock = false;
|
|
49
|
+
htmlBlockContent.clear();
|
|
34
50
|
}
|
|
35
51
|
|
|
36
52
|
void flushText() {
|
|
@@ -109,6 +125,19 @@ public:
|
|
|
109
125
|
break;
|
|
110
126
|
}
|
|
111
127
|
|
|
128
|
+
case MD_BLOCK_ADMONITION: {
|
|
129
|
+
auto node = std::make_shared<MarkdownASTNode>(NodeType::Admonition);
|
|
130
|
+
if (detail) {
|
|
131
|
+
auto *adm = static_cast<MD_BLOCK_ADMONITION_DETAIL *>(detail);
|
|
132
|
+
std::string admonitionType = impl->getAttributeText(&adm->type);
|
|
133
|
+
if (!admonitionType.empty()) {
|
|
134
|
+
node->setAttribute(ATTR_ADMONITION_TYPE, admonitionType);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
impl->pushNode(node);
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
|
|
112
141
|
case MD_BLOCK_UL: {
|
|
113
142
|
impl->pushNode(std::make_shared<MarkdownASTNode>(NodeType::UnorderedList));
|
|
114
143
|
break;
|
|
@@ -163,6 +192,16 @@ public:
|
|
|
163
192
|
break;
|
|
164
193
|
}
|
|
165
194
|
|
|
195
|
+
case MD_BLOCK_BLANK: {
|
|
196
|
+
auto node = std::make_shared<MarkdownASTNode>(NodeType::BlankLine);
|
|
197
|
+
if (detail) {
|
|
198
|
+
auto *blankDetail = static_cast<MD_BLOCK_BLANK_DETAIL *>(detail);
|
|
199
|
+
node->setAttribute(ATTR_BLANK_LINE_COUNT, std::to_string(blankDetail->line_count));
|
|
200
|
+
}
|
|
201
|
+
impl->pushNode(node);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
|
|
166
205
|
case MD_BLOCK_TABLE: {
|
|
167
206
|
auto node = std::make_shared<MarkdownASTNode>(NodeType::Table);
|
|
168
207
|
if (detail) {
|
|
@@ -217,6 +256,12 @@ public:
|
|
|
217
256
|
break;
|
|
218
257
|
}
|
|
219
258
|
|
|
259
|
+
case MD_BLOCK_HTML: {
|
|
260
|
+
impl->inHtmlBlock = true;
|
|
261
|
+
impl->htmlBlockContent.clear();
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
|
|
220
265
|
default:
|
|
221
266
|
// Other block types not yet implemented
|
|
222
267
|
break;
|
|
@@ -231,6 +276,16 @@ public:
|
|
|
231
276
|
return 1;
|
|
232
277
|
auto *impl = static_cast<Impl *>(userdata);
|
|
233
278
|
|
|
279
|
+
if (type == MD_BLOCK_HTML) {
|
|
280
|
+
impl->inHtmlBlock = false;
|
|
281
|
+
auto node = tryPromoteHtmlBlock(impl->htmlBlockContent);
|
|
282
|
+
impl->htmlBlockContent.clear();
|
|
283
|
+
if (node && !impl->nodeStack.empty()) {
|
|
284
|
+
impl->nodeStack.back()->addChild(std::move(node));
|
|
285
|
+
}
|
|
286
|
+
return 0;
|
|
287
|
+
}
|
|
288
|
+
|
|
234
289
|
if (type != MD_BLOCK_DOC && !impl->nodeStack.empty()) {
|
|
235
290
|
impl->popNode();
|
|
236
291
|
}
|
|
@@ -364,6 +419,13 @@ public:
|
|
|
364
419
|
return 0;
|
|
365
420
|
}
|
|
366
421
|
|
|
422
|
+
if (type == MD_TEXT_HTML) {
|
|
423
|
+
if (impl->inHtmlBlock) {
|
|
424
|
+
impl->htmlBlockContent.append(text, size);
|
|
425
|
+
}
|
|
426
|
+
return 0;
|
|
427
|
+
}
|
|
428
|
+
|
|
367
429
|
// Handle text content (normal text, code text, LaTeX math, etc.)
|
|
368
430
|
if (type == MD_TEXT_NORMAL || type == MD_TEXT_CODE || type == MD_TEXT_LATEXMATH) {
|
|
369
431
|
impl->currentText.append(text, size);
|
|
@@ -375,6 +437,107 @@ public:
|
|
|
375
437
|
|
|
376
438
|
namespace {
|
|
377
439
|
|
|
440
|
+
HtmlTag parseHtmlOpenTag(const std::string &html) {
|
|
441
|
+
HtmlTag tag;
|
|
442
|
+
size_t pos = 0;
|
|
443
|
+
|
|
444
|
+
while (pos < html.size() && std::isspace(static_cast<unsigned char>(html[pos])))
|
|
445
|
+
++pos;
|
|
446
|
+
if (pos >= html.size() || html[pos] != '<')
|
|
447
|
+
return tag;
|
|
448
|
+
++pos;
|
|
449
|
+
|
|
450
|
+
if (pos < html.size() && html[pos] == '/')
|
|
451
|
+
return tag;
|
|
452
|
+
|
|
453
|
+
while (pos < html.size() && std::isspace(static_cast<unsigned char>(html[pos])))
|
|
454
|
+
++pos;
|
|
455
|
+
|
|
456
|
+
size_t nameStart = pos;
|
|
457
|
+
while (pos < html.size() && !std::isspace(static_cast<unsigned char>(html[pos])) && html[pos] != '>' &&
|
|
458
|
+
html[pos] != '/') {
|
|
459
|
+
++pos;
|
|
460
|
+
}
|
|
461
|
+
if (pos == nameStart)
|
|
462
|
+
return tag;
|
|
463
|
+
tag.name.reserve(pos - nameStart);
|
|
464
|
+
for (size_t i = nameStart; i < pos; ++i)
|
|
465
|
+
tag.name += static_cast<char>(std::tolower(static_cast<unsigned char>(html[i])));
|
|
466
|
+
|
|
467
|
+
while (pos < html.size()) {
|
|
468
|
+
while (pos < html.size() && std::isspace(static_cast<unsigned char>(html[pos])))
|
|
469
|
+
++pos;
|
|
470
|
+
if (pos >= html.size() || html[pos] == '>' || html[pos] == '/')
|
|
471
|
+
break;
|
|
472
|
+
|
|
473
|
+
size_t attrStart = pos;
|
|
474
|
+
while (pos < html.size() && html[pos] != '=' && !std::isspace(static_cast<unsigned char>(html[pos])) &&
|
|
475
|
+
html[pos] != '>' && html[pos] != '/') {
|
|
476
|
+
++pos;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
if (pos == attrStart) {
|
|
480
|
+
++pos;
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
std::string attrName;
|
|
485
|
+
attrName.reserve(pos - attrStart);
|
|
486
|
+
for (size_t i = attrStart; i < pos; ++i)
|
|
487
|
+
attrName += static_cast<char>(std::tolower(static_cast<unsigned char>(html[i])));
|
|
488
|
+
|
|
489
|
+
while (pos < html.size() && std::isspace(static_cast<unsigned char>(html[pos])))
|
|
490
|
+
++pos;
|
|
491
|
+
|
|
492
|
+
if (pos < html.size() && html[pos] == '=') {
|
|
493
|
+
++pos;
|
|
494
|
+
while (pos < html.size() && std::isspace(static_cast<unsigned char>(html[pos])))
|
|
495
|
+
++pos;
|
|
496
|
+
|
|
497
|
+
std::string attrValue;
|
|
498
|
+
if (pos < html.size() && (html[pos] == '"' || html[pos] == '\'')) {
|
|
499
|
+
char quote = html[pos++];
|
|
500
|
+
size_t valueStart = pos;
|
|
501
|
+
while (pos < html.size() && html[pos] != quote)
|
|
502
|
+
++pos;
|
|
503
|
+
attrValue = html.substr(valueStart, pos - valueStart);
|
|
504
|
+
if (pos < html.size())
|
|
505
|
+
++pos;
|
|
506
|
+
} else {
|
|
507
|
+
size_t valueStart = pos;
|
|
508
|
+
while (pos < html.size() && !std::isspace(static_cast<unsigned char>(html[pos])) && html[pos] != '>' &&
|
|
509
|
+
html[pos] != '/') {
|
|
510
|
+
++pos;
|
|
511
|
+
}
|
|
512
|
+
attrValue = html.substr(valueStart, pos - valueStart);
|
|
513
|
+
}
|
|
514
|
+
tag.attributes[attrName] = attrValue;
|
|
515
|
+
} else {
|
|
516
|
+
tag.attributes[attrName] = "";
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
return tag;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
std::shared_ptr<MarkdownASTNode> tryPromoteHtmlBlock(const std::string &html) {
|
|
524
|
+
auto tag = parseHtmlOpenTag(html);
|
|
525
|
+
if (tag.name.empty())
|
|
526
|
+
return nullptr;
|
|
527
|
+
|
|
528
|
+
if (tag.name == "video") {
|
|
529
|
+
auto srcIt = tag.attributes.find("src");
|
|
530
|
+
if (srcIt == tag.attributes.end() || srcIt->second.empty()) {
|
|
531
|
+
return nullptr;
|
|
532
|
+
}
|
|
533
|
+
auto node = std::make_shared<MarkdownASTNode>(NodeType::Video);
|
|
534
|
+
node->setAttribute("url", srcIt->second);
|
|
535
|
+
return node;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
return nullptr;
|
|
539
|
+
}
|
|
540
|
+
|
|
378
541
|
using NodeList = std::vector<std::shared_ptr<MarkdownASTNode>>;
|
|
379
542
|
|
|
380
543
|
bool isDisplayMathNode(const MarkdownASTNode &node) {
|
|
@@ -386,12 +549,31 @@ bool isSeparatorNode(const MarkdownASTNode &node) {
|
|
|
386
549
|
(node.type == NodeType::Text && node.content.find_first_not_of(" \t\n\r") == std::string::npos);
|
|
387
550
|
}
|
|
388
551
|
|
|
552
|
+
// The display math a paragraph child stands for: the node itself, or the one display-math
|
|
553
|
+
// node a `==$$x$$==` highlight wraps. The highlight cannot survive promotion as a span
|
|
554
|
+
// (a block is not inline text), so the caller carries it over as the `highlight` attribute.
|
|
555
|
+
std::shared_ptr<MarkdownASTNode> displayMathOf(const std::shared_ptr<MarkdownASTNode> &node) {
|
|
556
|
+
if (isDisplayMathNode(*node))
|
|
557
|
+
return node;
|
|
558
|
+
if (node->type != NodeType::Highlight)
|
|
559
|
+
return nullptr;
|
|
560
|
+
std::shared_ptr<MarkdownASTNode> math;
|
|
561
|
+
for (const auto &child : node->children) {
|
|
562
|
+
if (isSeparatorNode(*child))
|
|
563
|
+
continue;
|
|
564
|
+
if (math || !isDisplayMathNode(*child))
|
|
565
|
+
return nullptr;
|
|
566
|
+
math = child;
|
|
567
|
+
}
|
|
568
|
+
return math;
|
|
569
|
+
}
|
|
570
|
+
|
|
389
571
|
// A display-math node is "isolated" — i.e. block-level — when at least one of its
|
|
390
572
|
// neighbours is a boundary: the paragraph edge, or a separator (LineBreak / blank
|
|
391
573
|
// text). Display math flanked by real text on BOTH sides (e.g. `a $$x$$ b`) is
|
|
392
574
|
// genuinely inline and is left in place.
|
|
393
575
|
bool isIsolatedDisplayMath(const std::vector<std::shared_ptr<MarkdownASTNode>> &children, size_t i) {
|
|
394
|
-
if (!
|
|
576
|
+
if (!displayMathOf(children[i]))
|
|
395
577
|
return false;
|
|
396
578
|
bool leftBoundary = (i == 0) || isSeparatorNode(*children[i - 1]);
|
|
397
579
|
bool rightBoundary = (i + 1 >= children.size()) || isSeparatorNode(*children[i + 1]);
|
|
@@ -446,7 +628,10 @@ splitParagraphAroundDisplayMath(const std::vector<std::shared_ptr<MarkdownASTNod
|
|
|
446
628
|
for (size_t i = 0; i < children.size(); ++i) {
|
|
447
629
|
if (isIsolatedDisplayMath(children, i)) {
|
|
448
630
|
flushInlineRun();
|
|
449
|
-
|
|
631
|
+
auto math = displayMathOf(children[i]);
|
|
632
|
+
if (math != children[i])
|
|
633
|
+
math->setAttribute("highlight", "true");
|
|
634
|
+
result.push_back(math);
|
|
450
635
|
} else {
|
|
451
636
|
inlineRun.push_back(children[i]);
|
|
452
637
|
}
|
|
@@ -486,11 +671,13 @@ bool isBlockNode(const MarkdownASTNode &node) {
|
|
|
486
671
|
case NodeType::Paragraph:
|
|
487
672
|
case NodeType::Heading:
|
|
488
673
|
case NodeType::Blockquote:
|
|
674
|
+
case NodeType::Admonition:
|
|
489
675
|
case NodeType::UnorderedList:
|
|
490
676
|
case NodeType::OrderedList:
|
|
491
677
|
case NodeType::ListItem:
|
|
492
678
|
case NodeType::CodeBlock:
|
|
493
679
|
case NodeType::ThematicBreak:
|
|
680
|
+
case NodeType::BlankLine:
|
|
494
681
|
case NodeType::LatexMathDisplay:
|
|
495
682
|
case NodeType::Table:
|
|
496
683
|
case NodeType::TableHead:
|
|
@@ -498,6 +685,7 @@ bool isBlockNode(const MarkdownASTNode &node) {
|
|
|
498
685
|
case NodeType::TableRow:
|
|
499
686
|
case NodeType::TableHeaderCell:
|
|
500
687
|
case NodeType::TableCell:
|
|
688
|
+
case NodeType::Video:
|
|
501
689
|
return true;
|
|
502
690
|
default:
|
|
503
691
|
return false;
|
|
@@ -565,13 +753,75 @@ void wrapListItemInlineRuns(MarkdownASTNode &node) {
|
|
|
565
753
|
node.children = std::move(newChildren);
|
|
566
754
|
}
|
|
567
755
|
|
|
756
|
+
bool isVideoOnlyListItem(const MarkdownASTNode &item) {
|
|
757
|
+
return item.type == NodeType::ListItem && item.children.size() == 1 && item.children[0]->type == NodeType::Video;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
void promoteVideosFromListItems(MarkdownASTNode &node) {
|
|
761
|
+
for (auto &child : node.children) {
|
|
762
|
+
if (child->type == NodeType::Blockquote || child->type == NodeType::Admonition) {
|
|
763
|
+
promoteVideosFromListItems(*child);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
auto &children = node.children;
|
|
768
|
+
for (size_t i = 0; i < children.size();) {
|
|
769
|
+
auto &list = children[i];
|
|
770
|
+
if (list->type != NodeType::UnorderedList && list->type != NodeType::OrderedList) {
|
|
771
|
+
++i;
|
|
772
|
+
continue;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
bool hasVideoItem = false;
|
|
776
|
+
for (auto &item : list->children) {
|
|
777
|
+
if (isVideoOnlyListItem(*item)) {
|
|
778
|
+
hasVideoItem = true;
|
|
779
|
+
break;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
if (!hasVideoItem) {
|
|
783
|
+
++i;
|
|
784
|
+
continue;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
std::vector<std::shared_ptr<MarkdownASTNode>> replacement;
|
|
788
|
+
std::vector<std::shared_ptr<MarkdownASTNode>> currentItems;
|
|
789
|
+
NodeType listType = list->type;
|
|
790
|
+
|
|
791
|
+
for (auto &item : list->children) {
|
|
792
|
+
if (isVideoOnlyListItem(*item)) {
|
|
793
|
+
if (!currentItems.empty()) {
|
|
794
|
+
auto sublist = std::make_shared<MarkdownASTNode>(listType);
|
|
795
|
+
sublist->children = std::move(currentItems);
|
|
796
|
+
currentItems.clear();
|
|
797
|
+
replacement.push_back(std::move(sublist));
|
|
798
|
+
}
|
|
799
|
+
replacement.push_back(item->children[0]);
|
|
800
|
+
} else {
|
|
801
|
+
currentItems.push_back(std::move(item));
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
if (!currentItems.empty()) {
|
|
806
|
+
auto sublist = std::make_shared<MarkdownASTNode>(listType);
|
|
807
|
+
sublist->children = std::move(currentItems);
|
|
808
|
+
replacement.push_back(std::move(sublist));
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
auto position = children.erase(children.begin() + static_cast<NodeList::difference_type>(i));
|
|
812
|
+
children.insert(position, replacement.begin(), replacement.end());
|
|
813
|
+
i += replacement.size();
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
|
|
568
817
|
} // anonymous namespace
|
|
569
818
|
|
|
570
819
|
MD4CParser::MD4CParser() : impl_(std::make_unique<Impl>()) {}
|
|
571
820
|
|
|
572
821
|
MD4CParser::~MD4CParser() = default;
|
|
573
822
|
|
|
574
|
-
std::shared_ptr<MarkdownASTNode> MD4CParser::parse(const std::string &markdown, const Md4cFlags &md4cFlags
|
|
823
|
+
std::shared_ptr<MarkdownASTNode> MD4CParser::parse(const std::string &markdown, const Md4cFlags &md4cFlags,
|
|
824
|
+
bool isGFM) {
|
|
575
825
|
if (markdown.empty()) {
|
|
576
826
|
return std::make_shared<MarkdownASTNode>(NodeType::Document);
|
|
577
827
|
}
|
|
@@ -589,7 +839,10 @@ std::shared_ptr<MarkdownASTNode> MD4CParser::parse(const std::string &markdown,
|
|
|
589
839
|
impl_->reset(estimatedDepth);
|
|
590
840
|
impl_->inputText = markdown.c_str();
|
|
591
841
|
|
|
592
|
-
unsigned flags =
|
|
842
|
+
unsigned flags = MD_FLAG_NOHTMLSPANS | MD_FLAG_SPOILERS;
|
|
843
|
+
if (isGFM) {
|
|
844
|
+
flags |= MD_FLAG_TABLES | MD_FLAG_STRIKETHROUGH | MD_FLAG_TASKLISTS;
|
|
845
|
+
}
|
|
593
846
|
if (md4cFlags.permissiveAutolinks) {
|
|
594
847
|
flags |= MD_FLAG_PERMISSIVEAUTOLINKS;
|
|
595
848
|
}
|
|
@@ -611,6 +864,12 @@ std::shared_ptr<MarkdownASTNode> MD4CParser::parse(const std::string &markdown,
|
|
|
611
864
|
if (md4cFlags.hardSoftBreaks) {
|
|
612
865
|
flags |= MD_FLAG_HARD_SOFT_BREAKS;
|
|
613
866
|
}
|
|
867
|
+
if (md4cFlags.preserveBlankLines) {
|
|
868
|
+
flags |= MD_FLAG_PRESERVEBLANKLINES;
|
|
869
|
+
}
|
|
870
|
+
if (md4cFlags.admonitions) {
|
|
871
|
+
flags |= MD_FLAG_ADMONITIONS;
|
|
872
|
+
}
|
|
614
873
|
|
|
615
874
|
// Configure MD4C parser with callbacks
|
|
616
875
|
MD_PARSER parser = {
|
|
@@ -633,6 +892,7 @@ std::shared_ptr<MarkdownASTNode> MD4CParser::parse(const std::string &markdown,
|
|
|
633
892
|
if (impl_->root) {
|
|
634
893
|
promoteDisplayMathFromParagraphs(*impl_->root);
|
|
635
894
|
wrapListItemInlineRuns(*impl_->root);
|
|
895
|
+
promoteVideosFromListItems(*impl_->root);
|
|
636
896
|
}
|
|
637
897
|
|
|
638
898
|
return impl_->root ? impl_->root : std::make_shared<MarkdownASTNode>(NodeType::Document);
|
|
@@ -647,5 +907,7 @@ const std::string MD4CParser::Impl::ATTR_LANGUAGE = "language";
|
|
|
647
907
|
const std::string MD4CParser::Impl::ATTR_IS_TASK = "isTask";
|
|
648
908
|
const std::string MD4CParser::Impl::ATTR_TASK_CHECKED = "taskChecked";
|
|
649
909
|
const std::string MD4CParser::Impl::ATTR_START = "start";
|
|
910
|
+
const std::string MD4CParser::Impl::ATTR_BLANK_LINE_COUNT = "count";
|
|
911
|
+
const std::string MD4CParser::Impl::ATTR_ADMONITION_TYPE = "admonitionType";
|
|
650
912
|
|
|
651
913
|
} // namespace Markdown
|
|
@@ -14,6 +14,8 @@ struct Md4cFlags {
|
|
|
14
14
|
bool highlight = false;
|
|
15
15
|
bool permissiveAutolinks = true;
|
|
16
16
|
bool hardSoftBreaks = false;
|
|
17
|
+
bool preserveBlankLines = false;
|
|
18
|
+
bool admonitions = true;
|
|
17
19
|
};
|
|
18
20
|
|
|
19
21
|
class MD4CParser {
|
|
@@ -22,7 +24,10 @@ public:
|
|
|
22
24
|
~MD4CParser();
|
|
23
25
|
|
|
24
26
|
// Parse markdown string and return AST root node
|
|
25
|
-
std::shared_ptr<MarkdownASTNode> parse(
|
|
27
|
+
std::shared_ptr<MarkdownASTNode> parse(
|
|
28
|
+
const std::string& markdown,
|
|
29
|
+
const Md4cFlags& flags = Md4cFlags{},
|
|
30
|
+
bool isGFM = true);
|
|
26
31
|
|
|
27
32
|
private:
|
|
28
33
|
class Impl;
|
|
@@ -30,4 +35,3 @@ private:
|
|
|
30
35
|
};
|
|
31
36
|
|
|
32
37
|
} // namespace Markdown
|
|
33
|
-
|
|
@@ -68,6 +68,12 @@ static const char *nodeTypeToString(NodeType type) {
|
|
|
68
68
|
return "Subscript";
|
|
69
69
|
case NodeType::Highlight:
|
|
70
70
|
return "Highlight";
|
|
71
|
+
case NodeType::BlankLine:
|
|
72
|
+
return "BlankLine";
|
|
73
|
+
case NodeType::Admonition:
|
|
74
|
+
return "Admonition";
|
|
75
|
+
case NodeType::Video:
|
|
76
|
+
return "Video";
|
|
71
77
|
default:
|
|
72
78
|
assert(false && "unhandled NodeType in nodeTypeToString");
|
|
73
79
|
return "";
|
package/cpp/wasm/md4c_wasm.cpp
CHANGED
|
@@ -19,10 +19,12 @@ extern "C" {
|
|
|
19
19
|
* @param subscript 1 → enable ~subscript~ spans; 0 → disable.
|
|
20
20
|
* @param highlight 1 → enable ==highlight== spans; 0 → disable.
|
|
21
21
|
* @param hardSoftBreaks 1 → treat soft breaks as hard breaks; 0 → collapse to space.
|
|
22
|
+
* @param preserveBlankLines 1 → report runs of blank lines as BlankLine nodes; 0 → collapse them.
|
|
23
|
+
* @param admonitions 1 → enable GitHub-style admonitions/alerts; 0 → disable.
|
|
22
24
|
* @return Null-terminated UTF-8 JSON string, valid until the next call.
|
|
23
25
|
*/
|
|
24
26
|
const char *parseMarkdown(const char *markdown, int underline, int latexMath, int superscript, int subscript,
|
|
25
|
-
int highlight, int hardSoftBreaks) {
|
|
27
|
+
int highlight, int hardSoftBreaks, int preserveBlankLines, int admonitions) {
|
|
26
28
|
if (!markdown) {
|
|
27
29
|
g_resultBuffer = "{\"type\":\"Document\"}";
|
|
28
30
|
return g_resultBuffer.c_str();
|
|
@@ -35,6 +37,8 @@ const char *parseMarkdown(const char *markdown, int underline, int latexMath, in
|
|
|
35
37
|
flags.subscript = (subscript != 0);
|
|
36
38
|
flags.highlight = (highlight != 0);
|
|
37
39
|
flags.hardSoftBreaks = (hardSoftBreaks != 0);
|
|
40
|
+
flags.preserveBlankLines = (preserveBlankLines != 0);
|
|
41
|
+
flags.admonitions = (admonitions != 0);
|
|
38
42
|
|
|
39
43
|
Markdown::MD4CParser parser;
|
|
40
44
|
auto root = parser.parse(std::string(markdown), flags);
|