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.
Files changed (346) hide show
  1. package/ReactNativeEnrichedMarkdown.podspec +31 -10
  2. package/android/build.gradle +49 -12
  3. package/android/consumer-rules.pro +3 -0
  4. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerDelegate.java +18 -0
  5. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerInterface.java +6 -0
  6. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextInputManagerDelegate.java +3 -0
  7. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextInputManagerInterface.java +1 -0
  8. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerDelegate.java +18 -0
  9. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerInterface.java +6 -0
  10. package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.cpp +62 -0
  11. package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.h +44 -0
  12. package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.cpp +67 -2
  13. package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.h +929 -178
  14. package/android/src/main/baseline-prof.txt +21 -22
  15. package/android/src/main/cpp/jni-adapter.cpp +17 -5
  16. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdown.kt +729 -768
  17. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownInternalText.kt +1 -1
  18. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownManager.kt +72 -3
  19. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownText.kt +222 -8
  20. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownTextManager.kt +65 -1
  21. package/android/src/main/java/com/swmansion/enriched/markdown/MeasurementStore.kt +191 -26
  22. package/android/src/main/java/com/swmansion/enriched/markdown/accessibility/AccessibleMarkdownTextView.kt +10 -0
  23. package/android/src/main/java/com/swmansion/enriched/markdown/accessibility/MarkdownAccessibilityHelper.kt +54 -6
  24. package/android/src/main/java/com/swmansion/enriched/markdown/events/CodeBlockPressEvent.kt +24 -0
  25. package/android/src/main/java/com/swmansion/enriched/markdown/events/ImagePressEvent.kt +25 -0
  26. package/android/src/main/java/com/swmansion/enriched/markdown/events/LatexErrorEvent.kt +29 -0
  27. package/android/src/main/java/com/swmansion/enriched/markdown/input/EnrichedMarkdownTextInputManager.kt +21 -0
  28. package/android/src/main/java/com/swmansion/enriched/markdown/input/EnrichedMarkdownTextInputView.kt +101 -9
  29. package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/EditPipeline.kt +48 -0
  30. package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/InputConnectionWrapper.kt +7 -0
  31. package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/MarkdownShortcutMatcher.kt +64 -0
  32. package/android/src/main/java/com/swmansion/enriched/markdown/input/formatting/InputRemend.kt +44 -6
  33. package/android/src/main/java/com/swmansion/enriched/markdown/input/layout/InputEventEmitter.kt +9 -8
  34. package/android/src/main/java/com/swmansion/enriched/markdown/math/LatexErrorReporter.kt +9 -0
  35. package/android/src/main/java/com/swmansion/enriched/markdown/parser/MarkdownASTNode.kt +6 -0
  36. package/android/src/main/java/com/swmansion/enriched/markdown/parser/Parser.kt +5 -1
  37. package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlankLineRenderer.kt +38 -0
  38. package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockStyleContext.kt +2 -2
  39. package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockquoteRenderer.kt +3 -2
  40. package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockquoteTextRenderer.kt +55 -0
  41. package/android/src/main/java/com/swmansion/enriched/markdown/renderer/CodeBlockRenderer.kt +8 -1
  42. package/android/src/main/java/com/swmansion/enriched/markdown/renderer/HighlightRenderer.kt +10 -1
  43. package/android/src/main/java/com/swmansion/enriched/markdown/renderer/NodeRenderer.kt +31 -3
  44. package/android/src/main/java/com/swmansion/enriched/markdown/renderer/ParagraphRenderer.kt +17 -2
  45. package/android/src/main/java/com/swmansion/enriched/markdown/renderer/Renderer.kt +40 -21
  46. package/android/src/main/java/com/swmansion/enriched/markdown/segments/AdmonitionIcons.kt +62 -0
  47. package/android/src/main/java/com/swmansion/enriched/markdown/{views → segments}/BlockSegmentView.kt +1 -1
  48. package/android/src/main/java/com/swmansion/enriched/markdown/segments/BlockquoteContainerView.kt +401 -0
  49. package/android/src/main/java/com/swmansion/enriched/markdown/{views → segments}/CodeBlockContainerView.kt +55 -16
  50. package/android/src/main/java/com/swmansion/enriched/markdown/segments/ContainerNodeView.kt +164 -0
  51. package/android/src/main/java/com/swmansion/enriched/markdown/{utils/common → segments}/MarkdownSegment.kt +21 -1
  52. package/android/src/main/java/com/swmansion/enriched/markdown/segments/RenderedSegment.kt +137 -0
  53. package/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentHeightMeasurer.kt +139 -0
  54. package/android/src/main/java/com/swmansion/enriched/markdown/{utils/common → segments}/SegmentReconciler.kt +1 -1
  55. package/android/src/main/java/com/swmansion/enriched/markdown/{utils/common → segments}/SegmentSignature.kt +3 -1
  56. package/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentViewCreators.kt +262 -0
  57. package/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentViewFactory.kt +29 -0
  58. package/android/src/main/java/com/swmansion/enriched/markdown/{views → segments}/TableContainerView.kt +100 -36
  59. package/android/src/main/java/com/swmansion/enriched/markdown/spans/CodeBackgroundSpan.kt +18 -17
  60. package/android/src/main/java/com/swmansion/enriched/markdown/spans/CodeBlockSpan.kt +3 -0
  61. package/android/src/main/java/com/swmansion/enriched/markdown/spans/HighlightSpan.kt +60 -6
  62. package/android/src/main/java/com/swmansion/enriched/markdown/spans/ImageSpan.kt +15 -5
  63. package/android/src/main/java/com/swmansion/enriched/markdown/spans/InlineBackgroundGeometry.kt +42 -0
  64. package/android/src/main/java/com/swmansion/enriched/markdown/spans/InlineChipPainter.kt +4 -27
  65. package/android/src/main/java/com/swmansion/enriched/markdown/spans/LineHeightSpan.kt +10 -0
  66. package/android/src/main/java/com/swmansion/enriched/markdown/spans/LinkSpan.kt +1 -1
  67. package/android/src/main/java/com/swmansion/enriched/markdown/spoiler/SpoilerDrawUtils.kt +11 -0
  68. package/android/src/main/java/com/swmansion/enriched/markdown/styles/BlockquoteStyle.kt +27 -0
  69. package/android/src/main/java/com/swmansion/enriched/markdown/styles/LinkVariantEntry.kt +2 -0
  70. package/android/src/main/java/com/swmansion/enriched/markdown/styles/StyleConfig.kt +10 -0
  71. package/android/src/main/java/com/swmansion/enriched/markdown/styles/VideoStyle.kt +31 -0
  72. package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/BorderStyleUtils.kt +86 -0
  73. package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/EllipsizeUtils.kt +27 -0
  74. package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/EnrichedMarkdownAncestorUtils.kt +10 -0
  75. package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/FeatureFlags.kt +1 -0
  76. package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/MarkdownViewManagerUtils.kt +36 -0
  77. package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/ReadableMapExtensions.kt +5 -0
  78. package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/serialization/MarkdownASTSerializer.kt +227 -0
  79. package/android/src/main/java/com/swmansion/enriched/markdown/utils/input/PasteTextUtils.kt +34 -2
  80. package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/conversion/HTMLGenerator.kt +50 -28
  81. package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/conversion/MarkdownExtractor.kt +16 -21
  82. package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/extensions/SpannableExtensions.kt +4 -3
  83. package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/span/BlockSpacing.kt +3 -2
  84. package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/span/SpanFlags.kt +13 -0
  85. package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/CodeBlockPressHost.kt +15 -0
  86. package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/ImagePressHost.kt +19 -0
  87. package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/LinkEvents.kt +11 -0
  88. package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/LinkLongPressMovementMethod.kt +87 -2
  89. package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/TextViewSetup.kt +79 -0
  90. package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/conversions.h +2 -0
  91. package/android/src/math/java/com/swmansion/enriched/markdown/renderer/MathInlineRenderer.kt +9 -3
  92. package/android/src/math/java/com/swmansion/enriched/markdown/{views → segments}/MathContainerView.kt +86 -29
  93. package/android/src/math/java/com/swmansion/enriched/markdown/spans/MathInlineSpan.kt +33 -7
  94. package/android/src/video/java/com/swmansion/enriched/markdown/segments/VideoContainerView.kt +115 -0
  95. package/cpp/md4c/md4c.c +343 -236
  96. package/cpp/md4c/md4c.h +28 -11
  97. package/cpp/parser/MD4CParser.cpp +266 -4
  98. package/cpp/parser/MD4CParser.hpp +6 -2
  99. package/cpp/parser/MarkdownASTNode.hpp +4 -1
  100. package/cpp/wasm/ASTSerializer.cpp +6 -0
  101. package/cpp/wasm/md4c_wasm.cpp +5 -1
  102. package/docs/API_REFERENCE.md +199 -12
  103. package/docs/BREAKING_CHANGES.md +75 -0
  104. package/docs/CODE_HIGHLIGHT.md +4 -0
  105. package/docs/COPY_OPTIONS.md +52 -9
  106. package/docs/ELEMENTS_STRUCTURE.md +48 -1
  107. package/docs/INPUT.md +60 -3
  108. package/docs/LATEX_MATH.md +30 -0
  109. package/docs/MACOS.md +1 -1
  110. package/docs/MENTIONS.md +2 -2
  111. package/docs/STYLES.md +27 -0
  112. package/docs/TEXT.md +8 -0
  113. package/docs/WEB.md +44 -10
  114. package/ios/EnrichedMarkdown.mm +285 -43
  115. package/ios/EnrichedMarkdownText.mm +185 -23
  116. package/ios/attachments/ENRMImageAttachment.h +17 -2
  117. package/ios/attachments/ENRMImageAttachment.m +26 -28
  118. package/ios/attachments/ENRMMathInlineAttachment+macOS.m +10 -2
  119. package/ios/attachments/ENRMMathInlineAttachment.h +3 -1
  120. package/ios/attachments/ENRMMathInlineAttachment.m +17 -1
  121. package/ios/attachments/ENRMMathInlineAttachmentShared.h +3 -0
  122. package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/EventEmitters.cpp +62 -0
  123. package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/EventEmitters.h +44 -0
  124. package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.cpp +67 -2
  125. package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.h +929 -178
  126. package/ios/input/ENRMInputFormatter.mm +68 -12
  127. package/ios/input/ENRMInputFormatterStyle.mm +9 -2
  128. package/ios/input/ENRMInputParser.mm +18 -0
  129. package/ios/input/ENRMInputRemend.mm +40 -3
  130. package/ios/input/ENRMMarkdownShortcutMatcher.h +39 -0
  131. package/ios/input/ENRMMarkdownShortcutMatcher.mm +66 -0
  132. package/ios/input/EnrichedMarkdownTextInput.mm +129 -1
  133. package/ios/internals/ENRMViewFreeMeasurement.h +45 -6
  134. package/ios/internals/MeasurementCache.h +20 -4
  135. package/ios/internals/ShadowMeasurementUtils.h +2 -0
  136. package/ios/math/ENRMLatexErrorCoordinator.h +27 -0
  137. package/ios/math/ENRMLatexErrorCoordinator.mm +75 -0
  138. package/ios/math/ENRMLatexErrorReporting.h +13 -0
  139. package/ios/math/ENRMRaTeXBridge.swift +46 -3
  140. package/ios/parser/ENRMMarkdownParser.h +3 -0
  141. package/ios/parser/ENRMMarkdownParser.mm +11 -2
  142. package/ios/parser/MarkdownASTNode.h +8 -1
  143. package/ios/parser/MarkdownASTNode.m +20 -0
  144. package/ios/parser/MarkdownParserBridge.mm +13 -2
  145. package/ios/renderer/AttributedRenderer.h +13 -1
  146. package/ios/renderer/AttributedRenderer.m +24 -13
  147. package/ios/renderer/BaselineShiftTextAttributes.h +4 -0
  148. package/ios/renderer/BaselineShiftTextAttributes.m +4 -0
  149. package/ios/renderer/BlankLineRenderer.h +4 -0
  150. package/ios/renderer/BlankLineRenderer.m +51 -0
  151. package/ios/renderer/BlockquoteRenderer.m +1 -0
  152. package/ios/renderer/CodeBlockRenderer.m +8 -0
  153. package/ios/renderer/CodeRenderer.m +5 -2
  154. package/ios/renderer/ENRMBlockquoteTextRenderer.h +25 -0
  155. package/ios/renderer/ENRMBlockquoteTextRenderer.m +48 -0
  156. package/ios/renderer/ENRMImageRenderer.m +1 -1
  157. package/ios/renderer/ENRMMathInlineRenderer.m +9 -1
  158. package/ios/renderer/HeadingRenderer.m +1 -0
  159. package/ios/renderer/HighlightRenderer.m +6 -0
  160. package/ios/renderer/LinkRenderer.m +1 -1
  161. package/ios/renderer/ListItemRenderer.m +51 -2
  162. package/ios/renderer/ParagraphRenderer.m +10 -3
  163. package/ios/renderer/RenderContext.h +16 -0
  164. package/ios/renderer/RenderContext.m +16 -0
  165. package/ios/renderer/RendererFactory.m +6 -0
  166. package/ios/renderer/SubscriptRenderer.m +1 -0
  167. package/ios/renderer/SuperscriptRenderer.m +1 -0
  168. package/ios/segments/ENRMAdmonitionIcons.h +31 -0
  169. package/ios/segments/ENRMAdmonitionIcons.m +93 -0
  170. package/ios/segments/ENRMBlockquoteContainerView.h +90 -0
  171. package/ios/segments/ENRMBlockquoteContainerView.mm +551 -0
  172. package/ios/{views → segments}/ENRMCodeBlockContainerView.h +9 -4
  173. package/ios/{views → segments}/ENRMCodeBlockContainerView.m +147 -36
  174. package/ios/segments/ENRMContainerNodeView.h +52 -0
  175. package/ios/segments/ENRMContainerNodeView.mm +201 -0
  176. package/ios/segments/ENRMDynamicBlockProps.h +32 -0
  177. package/ios/segments/ENRMDynamicBlockProps.m +15 -0
  178. package/ios/{views → segments}/ENRMMathContainerView.h +13 -5
  179. package/ios/{views → segments}/ENRMMathContainerView.m +60 -9
  180. package/ios/segments/ENRMSVGPath.h +21 -0
  181. package/ios/segments/ENRMSVGPath.m +409 -0
  182. package/ios/segments/ENRMSegmentHeightMeasurer.h +33 -0
  183. package/ios/segments/ENRMSegmentHeightMeasurer.mm +94 -0
  184. package/ios/segments/ENRMVideoContainerView.h +40 -0
  185. package/ios/segments/ENRMVideoContainerView.m +421 -0
  186. package/ios/{utils → segments}/RenderedMarkdownSegment.h +19 -2
  187. package/ios/{utils → segments}/RenderedMarkdownSegment.m +42 -1
  188. package/ios/segments/SegmentRenderer.h +26 -0
  189. package/ios/{utils → segments}/SegmentRenderer.m +46 -9
  190. package/ios/{views → segments}/TableContainerView.h +5 -4
  191. package/ios/{views → segments}/TableContainerView.m +96 -12
  192. package/ios/styles/StyleConfig.h +17 -0
  193. package/ios/styles/StyleConfig.mm +90 -0
  194. package/ios/utils/ENRMCodeBlockContent.mm +13 -0
  195. package/ios/utils/ENRMFeatureFlags.h +6 -0
  196. package/ios/utils/ENRMTextRenderer.h +8 -0
  197. package/ios/utils/ENRMTextRenderer.m +26 -10
  198. package/ios/utils/ENRMUIKit.h +1 -0
  199. package/ios/utils/FontUtils.h +2 -1
  200. package/ios/utils/FontUtils.m +22 -6
  201. package/ios/utils/LinkTapUtils.h +17 -2
  202. package/ios/utils/LinkTapUtils.m +44 -2
  203. package/ios/utils/ListMarkerDrawer.m +25 -1
  204. package/ios/utils/MarkdownASTSerializer.h +7 -0
  205. package/ios/utils/MarkdownASTSerializer.m +243 -0
  206. package/ios/utils/MarkdownAccessibilityElementBuilder.m +9 -67
  207. package/ios/utils/MarkdownExtractor.m +6 -3
  208. package/ios/utils/ParagraphStyleUtils.h +25 -1
  209. package/ios/utils/ParagraphStyleUtils.m +51 -7
  210. package/ios/utils/StylePropsUtils.h +60 -1
  211. package/ios/utils/TextViewLayoutManager.mm +57 -0
  212. package/lib/module/EnrichedMarkdownNativeComponent.ts +110 -4
  213. package/lib/module/EnrichedMarkdownTextInput.js +60 -2
  214. package/lib/module/EnrichedMarkdownTextInput.js.map +1 -1
  215. package/lib/module/EnrichedMarkdownTextInputNativeComponent.ts +12 -0
  216. package/lib/module/EnrichedMarkdownTextNativeComponent.ts +115 -4
  217. package/lib/module/admonitionDefaults.js +34 -0
  218. package/lib/module/admonitionDefaults.js.map +1 -0
  219. package/lib/module/index.js.map +1 -1
  220. package/lib/module/jest/index.js +84 -4
  221. package/lib/module/jest/index.js.map +1 -1
  222. package/lib/module/native/EnrichedMarkdownText.js +58 -5
  223. package/lib/module/native/EnrichedMarkdownText.js.map +1 -1
  224. package/lib/module/normalizeMarkdownShortcuts.js +31 -0
  225. package/lib/module/normalizeMarkdownShortcuts.js.map +1 -0
  226. package/lib/module/normalizeMarkdownStyle.js +15 -1
  227. package/lib/module/normalizeMarkdownStyle.js.map +1 -1
  228. package/lib/module/normalizeMarkdownStyle.web.js +15 -1
  229. package/lib/module/normalizeMarkdownStyle.web.js.map +1 -1
  230. package/lib/module/styleUtils.js +15 -3
  231. package/lib/module/styleUtils.js.map +1 -1
  232. package/lib/module/utils/textInputState.js +4 -3
  233. package/lib/module/utils/textInputState.js.map +1 -1
  234. package/lib/module/utils/usePressability.js +28 -0
  235. package/lib/module/utils/usePressability.js.map +1 -0
  236. package/lib/module/web/EnrichedMarkdownText.js +19 -6
  237. package/lib/module/web/EnrichedMarkdownText.js.map +1 -1
  238. package/lib/module/web/globalStyles.js +7 -1
  239. package/lib/module/web/globalStyles.js.map +1 -1
  240. package/lib/module/web/nativeProps.js +70 -0
  241. package/lib/module/web/nativeProps.js.map +1 -0
  242. package/lib/module/web/parseMarkdown.js +5 -3
  243. package/lib/module/web/parseMarkdown.js.map +1 -1
  244. package/lib/module/web/renderers/BlockRenderers.js +164 -8
  245. package/lib/module/web/renderers/BlockRenderers.js.map +1 -1
  246. package/lib/module/web/renderers/admonitionIcons.js +34 -0
  247. package/lib/module/web/renderers/admonitionIcons.js.map +1 -0
  248. package/lib/module/web/styles.js +30 -8
  249. package/lib/module/web/styles.js.map +1 -1
  250. package/lib/module/web/wasm/md4c.js +0 -0
  251. package/lib/module/web/wasm/md4c.js.map +1 -1
  252. package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts +103 -3
  253. package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts.map +1 -1
  254. package/lib/typescript/src/EnrichedMarkdownTextInput.d.ts +27 -3
  255. package/lib/typescript/src/EnrichedMarkdownTextInput.d.ts.map +1 -1
  256. package/lib/typescript/src/EnrichedMarkdownTextInputNativeComponent.d.ts +11 -0
  257. package/lib/typescript/src/EnrichedMarkdownTextInputNativeComponent.d.ts.map +1 -1
  258. package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts +108 -3
  259. package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts.map +1 -1
  260. package/lib/typescript/src/admonitionDefaults.d.ts +10 -0
  261. package/lib/typescript/src/admonitionDefaults.d.ts.map +1 -0
  262. package/lib/typescript/src/index.d.ts +3 -2
  263. package/lib/typescript/src/index.d.ts.map +1 -1
  264. package/lib/typescript/src/index.web.d.ts +1 -1
  265. package/lib/typescript/src/index.web.d.ts.map +1 -1
  266. package/lib/typescript/src/jest/index.d.ts +2 -2
  267. package/lib/typescript/src/jest/index.d.ts.map +1 -1
  268. package/lib/typescript/src/native/EnrichedMarkdownText.d.ts +3 -3
  269. package/lib/typescript/src/native/EnrichedMarkdownText.d.ts.map +1 -1
  270. package/lib/typescript/src/normalizeMarkdownShortcuts.d.ts +7 -0
  271. package/lib/typescript/src/normalizeMarkdownShortcuts.d.ts.map +1 -0
  272. package/lib/typescript/src/normalizeMarkdownStyle.d.ts.map +1 -1
  273. package/lib/typescript/src/normalizeMarkdownStyle.web.d.ts.map +1 -1
  274. package/lib/typescript/src/styleUtils.d.ts.map +1 -1
  275. package/lib/typescript/src/types/MarkdownStyle.d.ts +59 -1
  276. package/lib/typescript/src/types/MarkdownStyle.d.ts.map +1 -1
  277. package/lib/typescript/src/types/MarkdownStyleInternal.d.ts +21 -0
  278. package/lib/typescript/src/types/MarkdownStyleInternal.d.ts.map +1 -1
  279. package/lib/typescript/src/types/MarkdownTextProps.d.ts +93 -8
  280. package/lib/typescript/src/types/MarkdownTextProps.d.ts.map +1 -1
  281. package/lib/typescript/src/types/MarkdownTextProps.web.d.ts +25 -1
  282. package/lib/typescript/src/types/MarkdownTextProps.web.d.ts.map +1 -1
  283. package/lib/typescript/src/types/events.d.ts +33 -5
  284. package/lib/typescript/src/types/events.d.ts.map +1 -1
  285. package/lib/typescript/src/utils/textInputState.d.ts +5 -3
  286. package/lib/typescript/src/utils/textInputState.d.ts.map +1 -1
  287. package/lib/typescript/src/utils/usePressability.d.ts +24 -0
  288. package/lib/typescript/src/utils/usePressability.d.ts.map +1 -0
  289. package/lib/typescript/src/web/EnrichedMarkdownText.d.ts +1 -1
  290. package/lib/typescript/src/web/EnrichedMarkdownText.d.ts.map +1 -1
  291. package/lib/typescript/src/web/globalStyles.d.ts +1 -0
  292. package/lib/typescript/src/web/globalStyles.d.ts.map +1 -1
  293. package/lib/typescript/src/web/nativeProps.d.ts +34 -0
  294. package/lib/typescript/src/web/nativeProps.d.ts.map +1 -0
  295. package/lib/typescript/src/web/parseMarkdown.d.ts +1 -1
  296. package/lib/typescript/src/web/parseMarkdown.d.ts.map +1 -1
  297. package/lib/typescript/src/web/renderers/BlockRenderers.d.ts.map +1 -1
  298. package/lib/typescript/src/web/renderers/admonitionIcons.d.ts +5 -0
  299. package/lib/typescript/src/web/renderers/admonitionIcons.d.ts.map +1 -0
  300. package/lib/typescript/src/web/styles.d.ts +1 -0
  301. package/lib/typescript/src/web/styles.d.ts.map +1 -1
  302. package/lib/typescript/src/web/types.d.ts +8 -2
  303. package/lib/typescript/src/web/types.d.ts.map +1 -1
  304. package/package.json +1 -1
  305. package/postinstall.mjs +7 -0
  306. package/src/EnrichedMarkdownNativeComponent.ts +110 -4
  307. package/src/EnrichedMarkdownTextInput.tsx +101 -4
  308. package/src/EnrichedMarkdownTextInputNativeComponent.ts +12 -0
  309. package/src/EnrichedMarkdownTextNativeComponent.ts +115 -4
  310. package/src/admonitionDefaults.ts +58 -0
  311. package/src/index.tsx +5 -0
  312. package/src/index.web.tsx +3 -0
  313. package/src/jest/index.tsx +138 -5
  314. package/src/native/EnrichedMarkdownText.tsx +55 -3
  315. package/src/normalizeMarkdownShortcuts.ts +38 -0
  316. package/src/normalizeMarkdownStyle.ts +17 -0
  317. package/src/normalizeMarkdownStyle.web.ts +17 -0
  318. package/src/styleUtils.ts +17 -6
  319. package/src/types/MarkdownStyle.ts +62 -1
  320. package/src/types/MarkdownStyleInternal.ts +24 -0
  321. package/src/types/MarkdownTextProps.ts +95 -7
  322. package/src/types/MarkdownTextProps.web.ts +26 -0
  323. package/src/types/events.ts +36 -5
  324. package/src/utils/textInputState.ts +5 -3
  325. package/src/utils/usePressability.ts +34 -0
  326. package/src/web/EnrichedMarkdownText.tsx +36 -3
  327. package/src/web/globalStyles.ts +10 -0
  328. package/src/web/nativeProps.ts +78 -0
  329. package/src/web/parseMarkdown.ts +10 -2
  330. package/src/web/renderers/BlockRenderers.tsx +175 -6
  331. package/src/web/renderers/admonitionIcons.ts +37 -0
  332. package/src/web/styles.ts +28 -3
  333. package/src/web/types.ts +12 -1
  334. package/src/web/wasm/md4c.js +0 -0
  335. package/vendor-ratex.mjs +86 -17
  336. package/android/src/main/java/com/swmansion/enriched/markdown/renderer/DocumentRenderer.kt +0 -16
  337. package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/RenderedSegment.kt +0 -88
  338. package/ios/utils/SegmentRenderer.h +0 -24
  339. /package/ios/{views → segments}/ENRMTableGridView.h +0 -0
  340. /package/ios/{views → segments}/ENRMTableGridView.m +0 -0
  341. /package/ios/{views → segments}/ENRMTableIOSGridView.h +0 -0
  342. /package/ios/{views → segments}/ENRMTableIOSGridView.m +0 -0
  343. /package/ios/{utils → segments}/SegmentReconciler.h +0 -0
  344. /package/ios/{utils → segments}/SegmentReconciler.m +0 -0
  345. /package/ios/{utils → segments}/SegmentViewRegistry.h +0 -0
  346. /package/ios/{utils → segments}/SegmentViewRegistry.m +0 -0
@@ -0,0 +1,90 @@
1
+ #pragma once
2
+
3
+ #import "ENRMCodeBlockContainerView.h"
4
+ #import "ENRMContainerNodeView.h"
5
+ #import "StyleConfig.h"
6
+
7
+ @class MarkdownASTNode;
8
+ @class ENRMAccessibilityLabels;
9
+
10
+ NS_ASSUME_NONNULL_BEGIN
11
+
12
+ typedef void (^ENRMBlockquoteLinkBlock)(NSString *url);
13
+
14
+ /**
15
+ * A GFM blockquote rendered as a recursive container (issue #608): it splits its
16
+ * own AST children into segments and lays them out through the shared
17
+ * ENRMContainerNodeView machinery, so a nested quote becomes another
18
+ * ENRMBlockquoteContainerView, a fenced code block becomes an
19
+ * ENRMCodeBlockContainerView, and prose collapses into a single inner text view.
20
+ * Nesting depth is automatic: each level is its own view, inset further by its
21
+ * padding, so drawRect: only ever renders one accent bar plus the background for
22
+ * this single level. This mirrors Android's BlockquoteContainerView.
23
+ *
24
+ * The content inset is applied via contentInsets (left = borderWidth + gapWidth
25
+ * + padding, other edges = padding), reusing the geometry the commonmark
26
+ * BlockquoteBorder draws for the in-text (list-nested) path, which stays
27
+ * untouched. The base measure/layout already honor contentInsets.
28
+ *
29
+ * Streaming is static inside a quote (no pending fence, no animation); a content
30
+ * change re-signs the whole subtree so the outer reconciler still reuses the
31
+ * quote view.
32
+ */
33
+ @interface ENRMBlockquoteContainerView : ENRMContainerNodeView
34
+
35
+ - (instancetype)initWithConfig:(StyleConfig *)config;
36
+
37
+ // Splits the node's children into segments and applies them to this container.
38
+ - (void)applyBlockquoteNode:(MarkdownASTNode *)node;
39
+
40
+ // Laid-out height of this quote at the given outer width (the width the parent
41
+ // lays it out at, before this view's own inset).
42
+ - (CGFloat)measureHeight:(CGFloat)maxWidth;
43
+
44
+ // View-free height for the shadow-node measurement pass: the same height an
45
+ // instance's measureHeight: reports for the node, without building a view. It
46
+ // sums the child segments at the reduced inner width and adds the vertical
47
+ // inset, recursing into itself for nested quotes. pointScaleFactor is the layout
48
+ // context's scale (the visible instance path uses RCTScreenScale), threaded so
49
+ // the per-text-segment pixel rounding matches the laid-out height.
50
+ + (CGFloat)measureHeightForBlockquoteNode:(MarkdownASTNode *)node
51
+ config:(StyleConfig *)config
52
+ maxWidth:(CGFloat)maxWidth
53
+ pointScaleFactor:(CGFloat)pointScaleFactor
54
+ allowFontScaling:(BOOL)allowFontScaling
55
+ lineBreakStrategy:(NSLineBreakStrategy)lineBreakStrategy;
56
+
57
+ // Consumer text props threaded into the quote's inner content so it honors them
58
+ // the same way the root document path does, instead of assuming defaults. Set by
59
+ // the host (root view or parent quote) at creation; propagated to nested quotes.
60
+ @property (nonatomic, assign) BOOL allowFontScaling;
61
+ @property (nonatomic, assign) NSLineBreakStrategy lineBreakStrategy;
62
+
63
+ // YES when this quote is nested directly inside another quote. A nested quote
64
+ // carries no vertical margin (only the outermost quote does, applied by the root
65
+ // host), matching the commonmark path which applies blockquote margins only at
66
+ // depth 0. Set by the parent quote's child registry.
67
+ @property (nonatomic, assign) BOOL nested;
68
+
69
+ // Bridged up to the JS onLinkPress/onLinkLongPress events; propagated to nested
70
+ // quotes so links at any depth fire.
71
+ @property (nonatomic, copy, nullable) ENRMBlockquoteLinkBlock onLinkPress;
72
+ @property (nonatomic, copy, nullable) ENRMBlockquoteLinkBlock onLinkLongPress;
73
+
74
+ @property (nonatomic, copy, nullable) ENRMCodeBlockCopyBlock onCopyPress;
75
+ @property (nonatomic, copy, nullable) ENRMCodeBlockPressBlock onCodeBlockPress;
76
+
77
+ // Shared, runtime-mutable block props (context-menu gate, code-block tap gate,
78
+ // copy labels) read live at use-time. Set to the root's shared instance at
79
+ // creation and handed unchanged to this quote's children, so a child added after
80
+ // a toggle is born current with no per-toggle push. See ENRMDynamicBlockProps.
81
+ @property (nonatomic, strong) ENRMDynamicBlockProps *dynamicProps;
82
+
83
+ // Resolved VoiceOver strings (list, quote, table and math announcements). Set by
84
+ // the host at creation and pushed to this quote's children, recursing into
85
+ // nested quotes, so they are labelled the same way top-level segments are.
86
+ @property (nonatomic, strong, nullable) ENRMAccessibilityLabels *accessibilityLabels;
87
+
88
+ @end
89
+
90
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,551 @@
1
+ #import "ENRMBlockquoteContainerView.h"
2
+ #import "ENRMAdmonitionIcons.h"
3
+ #import "ENRMCodeBlockContainerView.h"
4
+ #import "ENRMFeatureFlags.h"
5
+ #import "ENRMSegmentHeightMeasurer.h"
6
+ #import "ENRMTextInteractionUtils.h"
7
+ #import "ENRMTextRenderer.h"
8
+ #import "EnrichedMarkdownInternalText.h"
9
+ #import "MarkdownASTNode.h"
10
+ #import "MarkdownASTSerializer.h"
11
+ #import "PasteboardUtils.h"
12
+ #import "SegmentRenderer.h"
13
+ #import "TableContainerView.h"
14
+ #if ENRICHED_MARKDOWN_MATH
15
+ #import "ENRMMathContainerView.h"
16
+ #endif
17
+ #if ENRICHED_MARKDOWN_VIDEO
18
+ #import "ENRMVideoContainerView.h"
19
+ #endif
20
+ #if TARGET_OS_OSX
21
+ #import "ENRMMenuAction.h"
22
+ #endif
23
+
24
+ // Inner content is rendered with trailing margins disabled; the quote's own
25
+ // vertical inset provides the bottom gap, and per-segment margins between children
26
+ // still apply (allowTrailingMargin only gates the last child's bottom margin). The
27
+ // consumer's allowFontScaling / lineBreakStrategy are threaded through so the
28
+ // quote's content honors them the same way the root document path does.
29
+ static NSArray<ENRMRenderedSegment *> *ENRMRenderBlockquoteChildren(MarkdownASTNode *node, StyleConfig *config,
30
+ BOOL allowFontScaling,
31
+ NSLineBreakStrategy lineBreakStrategy)
32
+ {
33
+ return ENRMRenderSegmentsFromAST(node, config, /*allowTrailingMargin*/ NO, allowFontScaling,
34
+ config.maxFontSizeMultiplier, lineBreakStrategy, /*blockquoteContent*/ YES);
35
+ }
36
+
37
+ // The admonition type ("note"/"tip"/…) for a node, or nil for a plain quote.
38
+ static NSString *ENRMAdmonitionTypeForNode(MarkdownASTNode *node)
39
+ {
40
+ if (node.type != MarkdownNodeTypeAdmonition) {
41
+ return nil;
42
+ }
43
+ NSString *type = node.attributes[@"admonitionType"];
44
+ return type.length > 0 ? type : @"note";
45
+ }
46
+
47
+ static CGFloat ENRMAdmonitionIconSize(StyleConfig *config)
48
+ {
49
+ return ceil(config.blockquoteFontSize);
50
+ }
51
+
52
+ // Bold variant of the blockquote font for the header title, respecting the
53
+ // configured family where the platform supports trait derivation.
54
+ static UIFont *ENRMAdmonitionTitleFont(StyleConfig *config)
55
+ {
56
+ UIFont *base = config.blockquoteFont;
57
+ #if !TARGET_OS_OSX
58
+ UIFontDescriptor *descriptor = [base.fontDescriptor
59
+ fontDescriptorWithSymbolicTraits:(base.fontDescriptor.symbolicTraits | UIFontDescriptorTraitBold)];
60
+ UIFont *bold = descriptor ? [UIFont fontWithDescriptor:descriptor size:base.pointSize] : nil;
61
+ return bold ?: [UIFont boldSystemFontOfSize:base.pointSize];
62
+ #else
63
+ NSFontDescriptor *descriptor = [base.fontDescriptor fontDescriptorWithSymbolicTraits:NSFontDescriptorTraitBold];
64
+ NSFont *bold = descriptor ? [NSFont fontWithDescriptor:descriptor size:base.pointSize] : nil;
65
+ return bold ?: [NSFont boldSystemFontOfSize:base.pointSize];
66
+ #endif
67
+ }
68
+
69
+ // Height of the header band (icon + title row); body sits a gap below it.
70
+ static CGFloat ENRMAdmonitionHeaderContentHeight(StyleConfig *config)
71
+ {
72
+ return ceil(MAX(ENRMAdmonitionIconSize(config), config.blockquoteFontSize * 1.35));
73
+ }
74
+
75
+ static CGFloat ENRMAdmonitionHeaderToBodyGap(StyleConfig *config)
76
+ {
77
+ return round(config.blockquoteFontSize * 0.4);
78
+ }
79
+
80
+ // Vertical space reserved above the body for the header (0 for a plain quote).
81
+ static CGFloat ENRMAdmonitionHeaderReservedHeight(StyleConfig *config, BOOL isAdmonition)
82
+ {
83
+ if (!isAdmonition) {
84
+ return 0;
85
+ }
86
+ return ENRMAdmonitionHeaderContentHeight(config) + ENRMAdmonitionHeaderToBodyGap(config);
87
+ }
88
+
89
+ static UIEdgeInsets ENRMBlockquoteContentInsetsForNode(StyleConfig *config, BOOL isAdmonition)
90
+ {
91
+ CGFloat padding = config.blockquotePadding;
92
+ CGFloat left = ceil(config.blockquoteBorderWidth + config.blockquoteGapWidth + padding);
93
+ CGFloat top = ceil(padding + ENRMAdmonitionHeaderReservedHeight(config, isAdmonition));
94
+ CGFloat vertical = ceil(padding);
95
+ CGFloat right = ceil(padding);
96
+ return UIEdgeInsetsMake(top, left, vertical, right);
97
+ }
98
+
99
+ static UIEdgeInsets ENRMBlockquoteContentInsets(StyleConfig *config)
100
+ {
101
+ return ENRMBlockquoteContentInsetsForNode(config, NO);
102
+ }
103
+
104
+ @interface ENRMBlockquoteContainerView ()
105
+ #if !TARGET_OS_OSX
106
+ <UIContextMenuInteractionDelegate>
107
+ #endif
108
+ // nil for a plain blockquote; the admonition type string otherwise.
109
+ @property (nonatomic, copy, nullable) NSString *admonitionType;
110
+ @property (nonatomic, copy) NSString *cachedMarkdown;
111
+ @property (nonatomic, copy) NSString *cachedPlainText;
112
+ @end
113
+
114
+ @implementation ENRMBlockquoteContainerView
115
+
116
+ - (instancetype)initWithConfig:(StyleConfig *)config
117
+ {
118
+ self = [super initWithFrame:CGRectZero];
119
+ if (self) {
120
+ self.config = config;
121
+ self.contentInsets = ENRMBlockquoteContentInsets(config);
122
+ self.allowTrailingMargin = NO;
123
+ // Preserved prior defaults until the host overrides them at creation.
124
+ _allowFontScaling = YES;
125
+ _lineBreakStrategy = NSLineBreakStrategyNone;
126
+ _dynamicProps = [[ENRMDynamicBlockProps alloc] init];
127
+ _cachedMarkdown = @"";
128
+ _cachedPlainText = @"";
129
+ #if !TARGET_OS_OSX
130
+ self.contentMode = UIViewContentModeRedraw;
131
+ UIContextMenuInteraction *contextMenu = [[UIContextMenuInteraction alloc] initWithDelegate:self];
132
+ [self addInteraction:contextMenu];
133
+ #endif
134
+ self.segmentViewRegistry = [self buildChildRegistry];
135
+ }
136
+ return self;
137
+ }
138
+
139
+ - (void)applyBlockquoteNode:(MarkdownASTNode *)node
140
+ {
141
+ self.admonitionType = ENRMAdmonitionTypeForNode(node);
142
+ self.contentInsets = ENRMBlockquoteContentInsetsForNode(self.config, self.admonitionType != nil);
143
+ self.cachedMarkdown = markdownFromBlockquoteNode(node);
144
+ self.cachedPlainText = plainTextFromASTNode(node);
145
+ NSArray<ENRMRenderedSegment *> *rendered =
146
+ ENRMRenderBlockquoteChildren(node, self.config, self.allowFontScaling, self.lineBreakStrategy);
147
+ [self applySegments:rendered reset:NO];
148
+ #if !TARGET_OS_OSX
149
+ [self setNeedsDisplay];
150
+ #else
151
+ self.needsDisplay = YES;
152
+ #endif
153
+ }
154
+
155
+ - (void)setAccessibilityLabels:(ENRMAccessibilityLabels *)accessibilityLabels
156
+ {
157
+ if (_accessibilityLabels == accessibilityLabels) {
158
+ return;
159
+ }
160
+ _accessibilityLabels = accessibilityLabels;
161
+ // Children created before this point (or before a labels prop change) still
162
+ // hold the previous labels; nested quotes forward them to their own children.
163
+ for (RCTUIView *child in self.subviews) {
164
+ if ([child isKindOfClass:[EnrichedMarkdownInternalText class]]) {
165
+ ((EnrichedMarkdownInternalText *)child).accessibilityLabels = accessibilityLabels;
166
+ } else if ([child isKindOfClass:[TableContainerView class]]) {
167
+ ((TableContainerView *)child).accessibilityLabels = accessibilityLabels;
168
+ } else if ([child isKindOfClass:[ENRMBlockquoteContainerView class]]) {
169
+ ((ENRMBlockquoteContainerView *)child).accessibilityLabels = accessibilityLabels;
170
+ }
171
+ #if ENRICHED_MARKDOWN_MATH
172
+ else if ([child isKindOfClass:[ENRMMathContainerView class]]) {
173
+ ((ENRMMathContainerView *)child).accessibilityLabels = accessibilityLabels;
174
+ }
175
+ #endif
176
+ }
177
+ }
178
+
179
+ // Child registry for this quote's own content. It reuses static creators for
180
+ // every kind and, for a nested Blockquote, creates another
181
+ // ENRMBlockquoteContainerView (the recursion). Streaming is static: no
182
+ // animation, no pending-fence sync.
183
+ - (ENRMSegmentViewRegistry *)buildChildRegistry
184
+ {
185
+ StyleConfig *config = self.config;
186
+ __weak ENRMBlockquoteContainerView *weakSelf = self;
187
+ NSMutableArray<ENRMSegmentViewHandler *> *handlers = [NSMutableArray array];
188
+
189
+ [handlers
190
+ addObject:[ENRMSegmentViewHandler handlerWithKind:ENRMSegmentKindText
191
+ matchesView:^BOOL(RCTUIView *view, ENRMRenderedSegment *segment) {
192
+ return [view isKindOfClass:[EnrichedMarkdownInternalText class]];
193
+ }
194
+ createView:^RCTUIView *(ENRMRenderedSegment *segment) {
195
+ ENRMBlockquoteContainerView *strongSelf = weakSelf;
196
+ EnrichedMarkdownInternalText *view = [[EnrichedMarkdownInternalText alloc] initWithConfig:config];
197
+ view.lastElementMarginBottom = segment.textResult.lastElementMarginBottom;
198
+ view.accessibilityInfo = segment.textResult.accessibilityInfo;
199
+ view.accessibilityLabels = strongSelf.accessibilityLabels;
200
+ [view applyAttributedText:segment.textResult.attributedText context:segment.textResult.context];
201
+ if (strongSelf) {
202
+ [strongSelf attachLinkTapToTextView:view];
203
+ }
204
+ return view;
205
+ }
206
+ updateView:^(RCTUIView *view, ENRMRenderedSegment *segment) {
207
+ EnrichedMarkdownInternalText *textView = (EnrichedMarkdownInternalText *)view;
208
+ textView.lastElementMarginBottom = segment.textResult.lastElementMarginBottom;
209
+ textView.accessibilityInfo = segment.textResult.accessibilityInfo;
210
+ [textView applyAttributedText:segment.textResult.attributedText
211
+ context:segment.textResult.context];
212
+ }]];
213
+
214
+ [handlers addObject:[ENRMSegmentViewHandler handlerWithKind:ENRMSegmentKindTable
215
+ matchesView:^BOOL(RCTUIView *view, ENRMRenderedSegment *segment) {
216
+ return [view isKindOfClass:[TableContainerView class]];
217
+ }
218
+ createView:^RCTUIView *(ENRMRenderedSegment *segment) {
219
+ TableContainerView *view = [[TableContainerView alloc] initWithConfig:config];
220
+ ENRMBlockquoteContainerView *strongSelf = weakSelf;
221
+ if (strongSelf) {
222
+ view.dynamicProps = strongSelf.dynamicProps;
223
+ view.accessibilityLabels = strongSelf.accessibilityLabels;
224
+ view.onLinkPress = ^(NSString *url) {
225
+ ENRMBlockquoteContainerView *s = weakSelf;
226
+ if (s.onLinkPress && url)
227
+ s.onLinkPress(url);
228
+ };
229
+ view.onLinkLongPress = ^(NSString *url) {
230
+ ENRMBlockquoteContainerView *s = weakSelf;
231
+ if (s.onLinkLongPress && url)
232
+ s.onLinkLongPress(url);
233
+ };
234
+ }
235
+ [view applyTableNode:segment.tableSegment.tableNode];
236
+ return view;
237
+ }
238
+ updateView:^(RCTUIView *view, ENRMRenderedSegment *segment) {
239
+ [(TableContainerView *)view applyTableNode:segment.tableSegment.tableNode];
240
+ }]];
241
+
242
+ [handlers
243
+ addObject:[ENRMSegmentViewHandler handlerWithKind:ENRMSegmentKindCodeBlock
244
+ matchesView:^BOOL(RCTUIView *view, ENRMRenderedSegment *segment) {
245
+ return [view isKindOfClass:[ENRMCodeBlockContainerView class]];
246
+ }
247
+ createView:^RCTUIView *(ENRMRenderedSegment *segment) {
248
+ ENRMCodeBlockContainerView *view = [[ENRMCodeBlockContainerView alloc] initWithConfig:config];
249
+ ENRMBlockquoteContainerView *strongSelf = weakSelf;
250
+ view.dynamicProps = strongSelf.dynamicProps;
251
+ view.onCopyPress = ^(NSString *code, NSString *language) {
252
+ ENRMBlockquoteContainerView *s = weakSelf;
253
+ if (s.onCopyPress)
254
+ s.onCopyPress(code, language);
255
+ };
256
+ view.onCodeBlockPress = ^(NSString *code, NSString *language) {
257
+ ENRMBlockquoteContainerView *s = weakSelf;
258
+ if (s.onCodeBlockPress)
259
+ s.onCodeBlockPress(code, language);
260
+ };
261
+ [view applyCodeBlockNode:segment.codeBlockSegment.codeBlockNode];
262
+ return view;
263
+ }
264
+ updateView:^(RCTUIView *view, ENRMRenderedSegment *segment) {
265
+ [(ENRMCodeBlockContainerView *)view applyCodeBlockNode:segment.codeBlockSegment.codeBlockNode];
266
+ }]];
267
+
268
+ [handlers addObject:[ENRMSegmentViewHandler handlerWithKind:ENRMSegmentKindBlockquote
269
+ matchesView:^BOOL(RCTUIView *view, ENRMRenderedSegment *segment) {
270
+ return [view isKindOfClass:[ENRMBlockquoteContainerView class]];
271
+ }
272
+ createView:^RCTUIView *(ENRMRenderedSegment *segment) {
273
+ ENRMBlockquoteContainerView *view =
274
+ [[ENRMBlockquoteContainerView alloc] initWithConfig:config];
275
+ view.nested = YES;
276
+ ENRMBlockquoteContainerView *strongSelf = weakSelf;
277
+ if (strongSelf) {
278
+ view.allowFontScaling = strongSelf.allowFontScaling;
279
+ view.lineBreakStrategy = strongSelf.lineBreakStrategy;
280
+ view.dynamicProps = strongSelf.dynamicProps;
281
+ view.accessibilityLabels = strongSelf.accessibilityLabels;
282
+ view.onCopyPress = strongSelf.onCopyPress;
283
+ view.onCodeBlockPress = strongSelf.onCodeBlockPress;
284
+ view.onLinkPress = ^(NSString *url) {
285
+ ENRMBlockquoteContainerView *s = weakSelf;
286
+ if (s.onLinkPress && url)
287
+ s.onLinkPress(url);
288
+ };
289
+ view.onLinkLongPress = ^(NSString *url) {
290
+ ENRMBlockquoteContainerView *s = weakSelf;
291
+ if (s.onLinkLongPress && url)
292
+ s.onLinkLongPress(url);
293
+ };
294
+ }
295
+ [view applyBlockquoteNode:segment.blockquoteSegment.blockquoteNode];
296
+ return view;
297
+ }
298
+ updateView:^(RCTUIView *view, ENRMRenderedSegment *segment) {
299
+ [(ENRMBlockquoteContainerView *)view
300
+ applyBlockquoteNode:segment.blockquoteSegment.blockquoteNode];
301
+ }]];
302
+
303
+ #if ENRICHED_MARKDOWN_MATH
304
+ #if !TARGET_OS_OSX
305
+ [handlers addObject:[ENRMSegmentViewHandler handlerWithKind:ENRMSegmentKindMath
306
+ matchesView:^BOOL(RCTUIView *view, ENRMRenderedSegment *segment) {
307
+ return [view isKindOfClass:[ENRMMathContainerView class]];
308
+ }
309
+ createView:^RCTUIView *(ENRMRenderedSegment *segment) {
310
+ ENRMMathContainerView *view = [[ENRMMathContainerView alloc] initWithConfig:config];
311
+ ENRMBlockquoteContainerView *strongSelf = weakSelf;
312
+ view.dynamicProps = strongSelf.dynamicProps;
313
+ view.accessibilityLabels = strongSelf.accessibilityLabels;
314
+ [view applyLatex:segment.mathSegment.latex];
315
+ return view;
316
+ }
317
+ updateView:^(RCTUIView *view, ENRMRenderedSegment *segment) {
318
+ [(ENRMMathContainerView *)view applyLatex:segment.mathSegment.latex];
319
+ }]];
320
+ #endif
321
+ #endif
322
+
323
+ #if ENRICHED_MARKDOWN_VIDEO
324
+ __weak ENRMBlockquoteContainerView *weakBQ = self;
325
+ [handlers addObject:[ENRMSegmentViewHandler handlerWithKind:ENRMSegmentKindVideo
326
+ matchesView:^BOOL(RCTUIView *view, ENRMRenderedSegment *segment) {
327
+ return [view isKindOfClass:[ENRMVideoContainerView class]];
328
+ }
329
+ createView:^RCTUIView *(ENRMRenderedSegment *segment) {
330
+ ENRMVideoContainerView *view = [[ENRMVideoContainerView alloc] initWithConfig:config];
331
+ ENRMBlockquoteContainerView *bq = weakBQ;
332
+ if (bq) {
333
+ view.dynamicProps = bq.dynamicProps;
334
+ }
335
+ [view applyVideoNode:segment.videoSegment.videoNode];
336
+ return view;
337
+ }
338
+ updateView:^(RCTUIView *view, ENRMRenderedSegment *segment) {
339
+ [(ENRMVideoContainerView *)view applyVideoNode:segment.videoSegment.videoNode];
340
+ }]];
341
+ #endif
342
+
343
+ return [[ENRMSegmentViewRegistry alloc] initWithHandlers:handlers];
344
+ }
345
+
346
+ - (void)attachLinkTapToTextView:(EnrichedMarkdownInternalText *)view
347
+ {
348
+ ENRMTapRecognizer *tap = [[ENRMTapRecognizer alloc] initWithTarget:self action:@selector(handleTextTap:)];
349
+ [view.textView addGestureRecognizer:tap];
350
+ }
351
+
352
+ - (void)handleTextTap:(ENRMTapRecognizer *)recognizer
353
+ {
354
+ ENRMPlatformTextView *textView = (ENRMPlatformTextView *)recognizer.view;
355
+ __weak ENRMBlockquoteContainerView *weakSelf = self;
356
+ ENRMHandleTapOnTextView(textView, recognizer, ^(NSString *url) {
357
+ ENRMBlockquoteContainerView *strongSelf = weakSelf;
358
+ if (strongSelf.onLinkPress && url)
359
+ strongSelf.onLinkPress(url);
360
+ });
361
+ }
362
+
363
+ - (CGFloat)measureHeight:(CGFloat)maxWidth
364
+ {
365
+ return [self computeContentHeightForWidth:MAX(maxWidth - self.contentInsets.left - self.contentInsets.right, 0)];
366
+ }
367
+
368
+ + (CGFloat)measureHeightForBlockquoteNode:(MarkdownASTNode *)node
369
+ config:(StyleConfig *)config
370
+ maxWidth:(CGFloat)maxWidth
371
+ pointScaleFactor:(CGFloat)pointScaleFactor
372
+ allowFontScaling:(BOOL)allowFontScaling
373
+ lineBreakStrategy:(NSLineBreakStrategy)lineBreakStrategy
374
+ {
375
+ UIEdgeInsets insets = ENRMBlockquoteContentInsetsForNode(config, ENRMAdmonitionTypeForNode(node) != nil);
376
+ CGFloat innerWidth = MAX(maxWidth - insets.left - insets.right, 1);
377
+
378
+ NSArray<ENRMRenderedSegment *> *rendered =
379
+ ENRMRenderBlockquoteChildren(node, config, allowFontScaling, lineBreakStrategy);
380
+ CGFloat childrenHeight = ENRMMeasureSegmentsHeightViewFree(
381
+ rendered, config, innerWidth, /*allowTrailingMargin*/ NO, pointScaleFactor, ENRMWritingDirectionModeFirstStrong,
382
+ NSWritingDirectionNatural, allowFontScaling, lineBreakStrategy);
383
+
384
+ return childrenHeight + insets.top + insets.bottom;
385
+ }
386
+
387
+ - (void)drawRect:(CGRect)rect
388
+ {
389
+ StyleConfig *config = self.config;
390
+ CGFloat borderWidth = config.blockquoteBorderWidth;
391
+ CGFloat radius = config.blockquoteBorderRadius;
392
+ CGRect bounds = self.bounds;
393
+
394
+ // The rounded (or plain) box outline, shared by the background fill and the accent
395
+ // bar's clip so the bar's left corners follow the border radius.
396
+ #if !TARGET_OS_OSX
397
+ UIBezierPath *boxPath = radius > 0 ? [UIBezierPath bezierPathWithRoundedRect:bounds cornerRadius:radius]
398
+ : [UIBezierPath bezierPathWithRect:bounds];
399
+ #else
400
+ NSBezierPath *boxPath = radius > 0 ? [NSBezierPath bezierPathWithRoundedRect:bounds xRadius:radius yRadius:radius]
401
+ : [NSBezierPath bezierPathWithRect:bounds];
402
+ #endif
403
+
404
+ // Admonitions theme the box with their per-type color; a plain quote keeps the
405
+ // base blockquote colors.
406
+ NSString *admonitionType = self.admonitionType;
407
+ RCTUIColor *backgroundColor =
408
+ admonitionType ? [config admonitionBackgroundColorForType:admonitionType] : config.blockquoteBackgroundColor;
409
+ if (backgroundColor && backgroundColor != [RCTUIColor clearColor]) {
410
+ [backgroundColor setFill];
411
+ [boxPath fill];
412
+ }
413
+
414
+ if (borderWidth > 0) {
415
+ RCTUIColor *borderColor =
416
+ admonitionType ? [config admonitionColorForType:admonitionType] : config.blockquoteBorderColor;
417
+ if (borderColor) {
418
+ CGRect barRect = CGRectMake(0, 0, borderWidth, bounds.size.height);
419
+ [borderColor setFill];
420
+ #if !TARGET_OS_OSX
421
+ CGContextRef ctx = UIGraphicsGetCurrentContext();
422
+ CGContextSaveGState(ctx);
423
+ [boxPath addClip];
424
+ [[UIBezierPath bezierPathWithRect:barRect] fill];
425
+ CGContextRestoreGState(ctx);
426
+ #else
427
+ [NSGraphicsContext saveGraphicsState];
428
+ [boxPath addClip];
429
+ [[NSBezierPath bezierPathWithRect:barRect] fill];
430
+ [NSGraphicsContext restoreGraphicsState];
431
+ #endif
432
+ }
433
+ }
434
+
435
+ if (admonitionType) {
436
+ [self drawAdmonitionHeaderForType:admonitionType config:config];
437
+ }
438
+ }
439
+
440
+ // Draws the admonition header (tinted octicon + capitalized title) in the band
441
+ // reserved at the top by the enlarged content inset. The view is flipped on
442
+ // macOS, so the y-down icon path and text draw identically on both platforms.
443
+ - (void)drawAdmonitionHeaderForType:(NSString *)type config:(StyleConfig *)config
444
+ {
445
+ RCTUIColor *tint = [config admonitionColorForType:type];
446
+ CGFloat padding = config.blockquotePadding;
447
+ CGFloat leftInset = ceil(config.blockquoteBorderWidth + config.blockquoteGapWidth + padding);
448
+ CGFloat iconSize = ENRMAdmonitionIconSize(config);
449
+ CGFloat headerHeight = ENRMAdmonitionHeaderContentHeight(config);
450
+ CGFloat headerTop = ceil(padding);
451
+ CGFloat titleX = leftInset;
452
+
453
+ CGPathRef iconPath = ENRMAdmonitionIconPath(type);
454
+ if (iconPath) {
455
+ #if !TARGET_OS_OSX
456
+ CGContextRef ctx = UIGraphicsGetCurrentContext();
457
+ #else
458
+ CGContextRef ctx = [[NSGraphicsContext currentContext] CGContext];
459
+ #endif
460
+ if (ctx) {
461
+ CGFloat scale = iconSize / ENRMAdmonitionIconViewBox;
462
+ CGFloat iconY = headerTop + (headerHeight - iconSize) / 2.0;
463
+ CGContextSaveGState(ctx);
464
+ CGContextTranslateCTM(ctx, leftInset, iconY);
465
+ CGContextScaleCTM(ctx, scale, scale);
466
+ CGContextAddPath(ctx, iconPath);
467
+ [tint setFill];
468
+ CGContextFillPath(ctx);
469
+ CGContextRestoreGState(ctx);
470
+ }
471
+ titleX = leftInset + iconSize + round(iconSize * 0.4);
472
+ }
473
+
474
+ NSString *title = ENRMAdmonitionTitle(type);
475
+ UIFont *titleFont = ENRMAdmonitionTitleFont(config);
476
+ NSDictionary<NSAttributedStringKey, id> *attributes =
477
+ @{NSFontAttributeName : titleFont, NSForegroundColorAttributeName : tint};
478
+ NSAttributedString *attributed = [[NSAttributedString alloc] initWithString:title attributes:attributes];
479
+ CGSize titleSize = [attributed size];
480
+ CGFloat titleY = headerTop + (headerHeight - titleSize.height) / 2.0;
481
+ [attributed drawAtPoint:CGPointMake(titleX, titleY)];
482
+ }
483
+
484
+ #pragma mark - Context menu
485
+
486
+ - (void)copyMarkdownToPasteboard
487
+ {
488
+ if (_cachedMarkdown.length > 0) {
489
+ copyStringToPasteboard(_cachedMarkdown);
490
+ }
491
+ }
492
+
493
+ - (void)copyPlainTextToPasteboard
494
+ {
495
+ if (_cachedPlainText.length > 0) {
496
+ NSMutableDictionary *items = [NSMutableDictionary dictionary];
497
+ items[kUTIPlainText] = _cachedPlainText;
498
+ if (_cachedMarkdown.length > 0) {
499
+ items[kUTIMarkdown] = _cachedMarkdown;
500
+ }
501
+ copyItemsToPasteboard(items);
502
+ }
503
+ }
504
+
505
+ #if !TARGET_OS_OSX
506
+ - (UIContextMenuConfiguration *)contextMenuInteraction:(UIContextMenuInteraction *)interaction
507
+ configurationForMenuAtLocation:(CGPoint)location
508
+ {
509
+ if (!self.dynamicProps.enableBlockContextMenu) {
510
+ return nil;
511
+ }
512
+ return [UIContextMenuConfiguration
513
+ configurationWithIdentifier:nil
514
+ previewProvider:nil
515
+ actionProvider:^UIMenu *(NSArray<UIMenuElement *> *suggestedActions) {
516
+ UIAction *copyPlainText =
517
+ [UIAction actionWithTitle:self.dynamicProps.menuCopyLabel
518
+ image:[RCTUIImage systemImageNamed:@"doc.on.doc"]
519
+ identifier:nil
520
+ handler:^(__kindof UIAction *action) { [self copyPlainTextToPasteboard]; }];
521
+
522
+ UIAction *copyMarkdown =
523
+ [UIAction actionWithTitle:self.dynamicProps.menuCopyAsMarkdownLabel
524
+ image:[RCTUIImage systemImageNamed:@"doc.text"]
525
+ identifier:nil
526
+ handler:^(__kindof UIAction *action) { [self copyMarkdownToPasteboard]; }];
527
+
528
+ return [UIMenu menuWithTitle:@"" children:@[ copyPlainText, copyMarkdown ]];
529
+ }];
530
+ }
531
+ #endif // !TARGET_OS_OSX
532
+
533
+ #if TARGET_OS_OSX
534
+ - (BOOL)isFlipped
535
+ {
536
+ return YES;
537
+ }
538
+
539
+ - (NSMenu *)menuForEvent:(NSEvent *)event
540
+ {
541
+ if (!self.dynamicProps.enableBlockContextMenu) {
542
+ return [super menuForEvent:event];
543
+ }
544
+ NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
545
+ [menu addItem:ENRMCreateMenuItem(self.dynamicProps.menuCopyLabel, ^{ [self copyPlainTextToPasteboard]; })];
546
+ [menu addItem:ENRMCreateMenuItem(self.dynamicProps.menuCopyAsMarkdownLabel, ^{ [self copyMarkdownToPasteboard]; })];
547
+ return menu;
548
+ }
549
+ #endif
550
+
551
+ @end
@@ -1,5 +1,6 @@
1
1
  #pragma once
2
2
  #import "ENRMBlockMenu.h"
3
+ #import "ENRMDynamicBlockProps.h"
3
4
  #import "ENRMUIKit.h"
4
5
  #import "StyleConfig.h"
5
6
 
@@ -8,6 +9,7 @@
8
9
  NS_ASSUME_NONNULL_BEGIN
9
10
 
10
11
  typedef void (^ENRMCodeBlockCopyBlock)(NSString *code, NSString *language);
12
+ typedef void (^ENRMCodeBlockPressBlock)(NSString *code, NSString *language);
11
13
 
12
14
  @interface ENRMCodeBlockContainerView : RCTUIView
13
15
 
@@ -27,10 +29,10 @@ typedef void (^ENRMCodeBlockCopyBlock)(NSString *code, NSString *language);
27
29
  // disabled, while the header stays visible.
28
30
  @property (nonatomic, assign) BOOL pending;
29
31
 
30
- // Renamed getters avoid the Cocoa `copy` method family (which signals +1
31
- // retained returns). Property names are unchanged so call sites stay the same.
32
- @property (nonatomic, copy, nullable, getter=menuCopyLabel) NSString *copyLabel;
33
- @property (nonatomic, copy, nullable, getter=menuCopyAsMarkdownLabel) NSString *copyAsMarkdownLabel;
32
+ // Shared, runtime-mutable block props (context-menu gate, tap gate, copy labels)
33
+ // read live at use-time. Set to the root's shared instance at creation so a code
34
+ // block added after a toggle is born current. See ENRMDynamicBlockProps.
35
+ @property (nonatomic, strong) ENRMDynamicBlockProps *dynamicProps;
34
36
 
35
37
  /// Suppresses the long-press copy menu on this block. Mirrors the
36
38
  /// `contextMenuHidden` prop; the header copy button is a visible control, not a
@@ -55,6 +57,9 @@ typedef void (^ENRMCodeBlockCopyBlock)(NSString *code, NSString *language);
55
57
  // `menuOptions.copyWritesMarkdown` is set.
56
58
  @property (nonatomic, copy, nullable) ENRMCodeBlockCopyBlock onCopyPress;
57
59
 
60
+ // Bridges a whole-block tap (not the copy button) up to the JS onCodeBlockPress event.
61
+ @property (nonatomic, copy, nullable) ENRMCodeBlockPressBlock onCodeBlockPress;
62
+
58
63
  @end
59
64
 
60
65
  NS_ASSUME_NONNULL_END