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
@@ -6,6 +6,7 @@
6
6
  #import "ENRMAtomicSize.h"
7
7
  #import "ENRMContextMenuTextView+macOS.h"
8
8
  #import "ENRMImageAttachment.h"
9
+ #import "ENRMLatexErrorCoordinator.h"
9
10
  #import "ENRMLinkLayout.h"
10
11
  #import "ENRMMarkdownParser.h"
11
12
  #import "ENRMSelectionChange.h"
@@ -28,6 +29,7 @@
28
29
  #import "MeasurementCache.h"
29
30
  #import "ParagraphStyleUtils.h"
30
31
  #import "PasteboardUtils.h"
32
+ #import "RenderContext.h"
31
33
  #import "RuntimeKeys.h"
32
34
  #import "SelectionColorUtils.h"
33
35
  #import "StylePropsUtils.h"
@@ -60,6 +62,8 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
60
62
  - (void)emitLinkPress:(NSString *)url;
61
63
  - (void)emitLinkLongPress:(NSString *)url;
62
64
  - (void)emitLinkLayoutIfNeeded;
65
+ - (void)emitImagePress:(NSString *)url altText:(NSString *)altText;
66
+ - (void)emitCodeBlockPress:(NSString *)code language:(NSString *)language;
63
67
  - (void)emitTaskListItemPress:(NSInteger)index checked:(BOOL)checked text:(NSString *)text;
64
68
  - (void)emitContextMenuItemPress:(NSString *)itemText
65
69
  selectedText:(NSString *)selectedText
@@ -75,6 +79,7 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
75
79
  NSString *_renderedMarkdown;
76
80
  StyleConfig *_config;
77
81
  ENRMMd4cFlags *_md4cFlags;
82
+ BOOL _isGFM;
78
83
 
79
84
  ENRMAsyncRenderCoordinator *_renderCoordinator;
80
85
 
@@ -90,6 +95,8 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
90
95
  BOOL _linkLongPressSelects;
91
96
  BOOL _enableTaskListItemToggle;
92
97
  BOOL _contextMenuHidden;
98
+ BOOL _enableImagePress;
99
+ BOOL _enableCodeBlockPress;
93
100
  BOOL _streamingAnimation;
94
101
  BOOL _forceHeightUpdateOnNextRender;
95
102
 
@@ -125,12 +132,17 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
125
132
 
126
133
  NSLineBreakStrategy _lineBreakStrategy;
127
134
 
135
+ NSInteger _numberOfLines;
136
+ NSLineBreakMode _ellipsizeLineBreakMode;
137
+
128
138
  ENRMWritingDirectionMode _writingDirectionMode;
129
139
  NSWritingDirection _resolvedLayoutDirection;
130
140
 
131
141
  ENRMDirtyFlags _dirtyFlags;
132
142
 
133
143
  ENRMAtomicSize _lastCommittedSize;
144
+
145
+ ENRMLatexErrorCoordinator *_latexErrorCoordinator;
134
146
  }
135
147
 
136
148
  + (ComponentDescriptorProvider)componentDescriptorProvider
@@ -147,11 +159,41 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
147
159
  flags.latexMath = props.latexMath;
148
160
  flags.highlight = props.highlight;
149
161
  flags.hardSoftBreaks = props.hardSoftBreaks;
162
+ flags.preserveBlankLines = props.preserveBlankLines;
163
+ flags.admonitions = props.admonitions;
150
164
  return flags;
151
165
  }
152
166
 
153
167
  #pragma mark - Measuring and State
154
168
 
169
+ /// The box the text actually lives in: `self.bounds` inset by the
170
+ /// `containerStyle` border and padding.
171
+ ///
172
+ /// Yoga hands `measureContent` an available size that already excludes those
173
+ /// insets, and `RCTViewComponentView` sizes `contentView` (our text view) to
174
+ /// `layoutMetrics.getContentFrame()`, so the shadow node's height and the text
175
+ /// view's frame are both content-box quantities. Measuring at `self.bounds`
176
+ /// instead overshoots by the horizontal insets, and because
177
+ /// `ENRMMeasureTextLayout` measures by resizing the live display container and
178
+ /// leaves it there (UIKit never re-syncs it - `widthTracksTextView` does not
179
+ /// apply with `scrollEnabled = NO`), the overshoot becomes the layout the user
180
+ /// sees: glyphs spill past the text view and get clipped, while the taller
181
+ /// content-width height Yoga committed shows up as blank space at the bottom.
182
+ ///
183
+ /// The text view's frame is authoritative, so this is zero-sized both before the
184
+ /// first layout metrics arrive and when the insets consume the whole component
185
+ /// width. Neither may fall back to `self.bounds`: that is the padded border box,
186
+ /// and in the second case it is a real layout the text would then be drawn
187
+ /// across. Callers skip measuring and laying out at a zero width instead.
188
+ ///
189
+ /// The frame, not the bounds: a `UITextView` is a scroll view, so its
190
+ /// `bounds.origin` is the content offset rather than the inset the segments of
191
+ /// `EnrichedMarkdown` get from the matching method.
192
+ - (CGRect)contentBounds
193
+ {
194
+ return _textView.frame;
195
+ }
196
+
155
197
  - (CGSize)measureSize:(CGFloat)maxWidth
156
198
  {
157
199
  CGSize size = ENRMMeasureMarkdownText(_textView, maxWidth, _config, _allowTrailingMargin, _lastElementMarginBottom);
@@ -187,15 +229,21 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
187
229
  }
188
230
  }
189
231
 
190
- /// Yoga-resolved direction inherited from any ancestor `direction` style.
191
- /// In FirstStrong mode this feeds the neutral-paragraph fallback, so a change
192
- /// requires a re-render of the cached markdown.
232
+ /// Publishes the committed size to the streaming fast path's mailbox, and picks
233
+ /// up the Yoga-resolved direction inherited from any ancestor `direction` style.
234
+ /// In FirstStrong mode the direction feeds the neutral-paragraph fallback, so a
235
+ /// change requires a re-render of the cached markdown.
236
+ ///
237
+ /// The mailbox holds a content size, not the border box: `measureContent`
238
+ /// returns it straight to Yoga, which adds the `containerStyle` insets back on
239
+ /// top of whatever it gets, so storing `frame.size` would double-count them.
193
240
  - (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics
194
241
  oldLayoutMetrics:(const LayoutMetrics &)oldLayoutMetrics
195
242
  {
196
243
  [super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
197
244
 
198
- _lastCommittedSize.store(CGSizeMake(layoutMetrics.frame.size.width, layoutMetrics.frame.size.height));
245
+ const auto contentSize = layoutMetrics.getContentFrame().size;
246
+ _lastCommittedSize.store(CGSizeMake(contentSize.width, contentSize.height));
199
247
  #if TARGET_OS_OSX
200
248
  [self emitLinkLayoutIfNeeded];
201
249
  #endif
@@ -229,9 +277,10 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
229
277
  facebook::react::MeasurementCache::shared().removeMatchingMarkdown(std::string(_renderedMarkdown.UTF8String));
230
278
  }
231
279
 
232
- if (self.bounds.size.width > 0) {
233
- CGSize measured = [self measureSize:self.bounds.size.width];
234
- if (needsHeightUpdate(measured, self.bounds)) {
280
+ CGRect contentBounds = [self contentBounds];
281
+ if (contentBounds.size.width > 0) {
282
+ CGSize measured = [self measureSize:contentBounds.size.width];
283
+ if (needsHeightUpdate(measured, contentBounds)) {
235
284
  [self requestHeightUpdate];
236
285
  }
237
286
  [self emitLinkLayoutIfNeeded];
@@ -247,18 +296,39 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
247
296
  self.backgroundColor = [RCTUIColor clearColor];
248
297
  _parser = [[ENRMMarkdownParser alloc] init];
249
298
  _md4cFlags = [EnrichedMarkdownText flagsFromProps:defaultProps->md4cFlags];
299
+ _isGFM = defaultProps->isGFM;
250
300
 
251
301
  _renderCoordinator =
252
302
  [[ENRMAsyncRenderCoordinator alloc] initWithQueueLabel:"com.swmansion.enriched.markdown.render"];
253
303
 
304
+ __weak __typeof(self) weakLatexSelf = self;
305
+ _latexErrorCoordinator =
306
+ [[ENRMLatexErrorCoordinator alloc] initWithEmit:^BOOL(NSString *source, NSString *message, BOOL displayMode) {
307
+ __typeof(self) strongSelf = weakLatexSelf;
308
+ if (!strongSelf)
309
+ return NO;
310
+ auto emitter = std::static_pointer_cast<EnrichedMarkdownTextEventEmitter const>(strongSelf->_eventEmitter);
311
+ if (!emitter)
312
+ return NO;
313
+ emitter->onLatexError({
314
+ .source = std::string(source.UTF8String ?: ""),
315
+ .message = std::string(message.UTF8String ?: ""),
316
+ .displayMode = displayMode ? true : false,
317
+ });
318
+ return YES;
319
+ }];
254
320
  _maxFontSizeMultiplier = 0;
255
321
  _allowTrailingMargin = NO;
256
322
  _enableLinkPreview = YES;
257
323
  _enableTaskListItemToggle = YES;
324
+ _enableImagePress = NO;
325
+ _enableCodeBlockPress = NO;
258
326
  _forceHeightUpdateOnNextRender = NO;
259
327
  _contextMenuHidden = NO;
260
328
  _selectionMenuConfig = ENRMDefaultSelectionMenuConfig();
261
329
  _lineBreakStrategy = NSLineBreakStrategyNone;
330
+ _numberOfLines = 0;
331
+ _ellipsizeLineBreakMode = NSLineBreakByTruncatingTail;
262
332
  _writingDirectionMode = ENRMWritingDirectionModeFirstStrong;
263
333
  _resolvedLayoutDirection =
264
334
  [[RCTI18nUtil sharedInstance] isRTL] ? NSWritingDirectionRightToLeft : NSWritingDirectionLeftToRight;
@@ -390,7 +460,8 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
390
460
  selectionEnd:selectionEnd];
391
461
  });
392
462
  return buildEditMenuForSelection(textView.textStorage, textView.selectedRange, strongSelf->_cachedMarkdown,
393
- strongSelf->_config, @[ baseMenu ], customItems, strongSelf->_selectionMenuConfig);
463
+ strongSelf->_config, @[ baseMenu ], customItems,
464
+ strongSelf -> _selectionMenuConfig);
394
465
  };
395
466
  #endif
396
467
 
@@ -432,6 +503,7 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
432
503
  StyleConfig *config = [_config copy];
433
504
  ENRMMarkdownParser *parser = _parser;
434
505
  ENRMMd4cFlags *md4cFlags = [_md4cFlags copy];
506
+ BOOL isGFM = _isGFM;
435
507
 
436
508
  BOOL allowFontScaling = _fontScaleObserver.allowFontScaling;
437
509
  CGFloat maxFontSizeMultiplier = _maxFontSizeMultiplier;
@@ -444,7 +516,7 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
444
516
 
445
517
  [_renderCoordinator
446
518
  scheduleRender:^BOOL {
447
- MarkdownASTNode *ast = [parser parseMarkdown:markdownString flags:md4cFlags];
519
+ MarkdownASTNode *ast = [parser parseMarkdown:markdownString flags:md4cFlags isGFM:isGFM];
448
520
  if (!ast)
449
521
  return NO;
450
522
 
@@ -457,13 +529,14 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
457
529
  self->_lastElementMarginBottom = result.lastElementMarginBottom;
458
530
  self->_accessibilityInfo = result.accessibilityInfo;
459
531
  self->_renderedStyleFingerprint = self->_pendingStyleFingerprint;
532
+ [self->_latexErrorCoordinator wireReporters:result.context.mathReporters];
460
533
  [self applyRenderedText:result.attributedText];
461
534
  }];
462
535
  }
463
536
 
464
537
  - (NSMutableAttributedString *)parseAndRenderMarkdown:(NSString *)markdownString
465
538
  {
466
- MarkdownASTNode *ast = [_parser parseMarkdown:markdownString flags:_md4cFlags];
539
+ MarkdownASTNode *ast = [_parser parseMarkdown:markdownString flags:_md4cFlags isGFM:_isGFM];
467
540
  if (!ast) {
468
541
  return nil;
469
542
  }
@@ -499,6 +572,21 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
499
572
  _renderedStyleFingerprint = _pendingStyleFingerprint;
500
573
  }
501
574
 
575
+ // Kept in sync with the view-free measurement so the rendered line count matches
576
+ // the measured height: both clamp a layout performed at the content width (see
577
+ // contentBounds), so the truncation falls on the same word.
578
+ // numberOfLines == 0 restores the unlimited default.
579
+ - (void)applyLineClampToTextContainer
580
+ {
581
+ if (_numberOfLines > 0) {
582
+ _textView.textContainer.maximumNumberOfLines = _numberOfLines;
583
+ _textView.textContainer.lineBreakMode = _ellipsizeLineBreakMode;
584
+ } else {
585
+ _textView.textContainer.maximumNumberOfLines = 0;
586
+ _textView.textContainer.lineBreakMode = NSLineBreakByWordWrapping;
587
+ }
588
+ }
589
+
502
590
  - (void)applyRenderedText:(NSMutableAttributedString *)attributedText
503
591
  {
504
592
  NSUInteger tailStart = _previousTextLength;
@@ -513,11 +601,13 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
513
601
  // Ensure the text container has unlimited height before setting content.
514
602
  // updateLayoutMetrics may have shrunk the frame (and thus the text container)
515
603
  // from a previous layout pass, which would clip the new attributed text.
516
- CGFloat containerWidth = _textView.textContainer.size.width;
604
+ CGRect contentBounds = [self contentBounds];
605
+ CGFloat containerWidth = contentBounds.size.width;
517
606
  if (containerWidth <= 0) {
518
- containerWidth = self.bounds.size.width;
607
+ containerWidth = _textView.textContainer.size.width;
519
608
  }
520
609
  _textView.textContainer.size = CGSizeMake(containerWidth, CGFLOAT_MAX);
610
+ [self applyLineClampToTextContainer];
521
611
 
522
612
  _accessibilityElements = nil;
523
613
  _accessibilityNeedsRebuild = YES;
@@ -534,7 +624,7 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
534
624
  // that corrupts the height sent to Yoga.
535
625
  [_spoilerManager setNeedsUpdate];
536
626
 
537
- if (self.bounds.size.width > 0) {
627
+ if (contentBounds.size.width > 0) {
538
628
  // Font/style changes can produce the same measured size before UIKit has
539
629
  // fully refreshed layout, so force one Yoga update after those renders.
540
630
  BOOL forceHeightUpdate = _forceHeightUpdateOnNextRender;
@@ -548,8 +638,8 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
548
638
 
549
639
  [_spoilerManager updateIfNeeded];
550
640
 
551
- CGSize measured = [self measureSize:self.bounds.size.width];
552
- if (forceHeightUpdate || needsHeightUpdate(measured, self.bounds)) {
641
+ CGSize measured = [self measureSize:contentBounds.size.width];
642
+ if (forceHeightUpdate || needsHeightUpdate(measured, contentBounds)) {
553
643
  [self requestHeightUpdate];
554
644
  }
555
645
 
@@ -597,7 +687,6 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
597
687
  }
598
688
 
599
689
  if (applyMarkdownStyleToConfig(_config, newViewProps.markdownStyle, oldViewProps.markdownStyle)) {
600
- [ENRMImageAttachment clearAttachmentRegistry];
601
690
  _forceHeightUpdateOnNextRender = YES;
602
691
  _dirtyFlags |= ENRMDirtyRender;
603
692
  }
@@ -664,16 +753,26 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
664
753
  newViewProps.md4cFlags.subscript != oldViewProps.md4cFlags.subscript ||
665
754
  newViewProps.md4cFlags.latexMath != oldViewProps.md4cFlags.latexMath ||
666
755
  newViewProps.md4cFlags.highlight != oldViewProps.md4cFlags.highlight ||
667
- newViewProps.md4cFlags.hardSoftBreaks != oldViewProps.md4cFlags.hardSoftBreaks) {
756
+ newViewProps.md4cFlags.hardSoftBreaks != oldViewProps.md4cFlags.hardSoftBreaks ||
757
+ newViewProps.md4cFlags.preserveBlankLines != oldViewProps.md4cFlags.preserveBlankLines ||
758
+ newViewProps.md4cFlags.admonitions != oldViewProps.md4cFlags.admonitions) {
668
759
  _md4cFlags = [EnrichedMarkdownText flagsFromProps:newViewProps.md4cFlags];
669
760
  _forceHeightUpdateOnNextRender = YES;
670
761
  _dirtyFlags |= ENRMDirtyRender;
671
762
  }
672
763
 
764
+ if (newViewProps.isGFM != oldViewProps.isGFM) {
765
+ _isGFM = newViewProps.isGFM;
766
+ _forceHeightUpdateOnNextRender = YES;
767
+ _dirtyFlags |= ENRMDirtyRender;
768
+ }
769
+
673
770
  _enableLinkPreview = newViewProps.enableLinkPreview;
674
771
  _linkLongPressSelects = newViewProps.linkLongPressSelects;
675
772
  _enableTaskListItemToggle = newViewProps.enableTaskListItemToggle;
676
773
  _contextMenuHidden = newViewProps.contextMenuHidden;
774
+ _enableImagePress = newViewProps.enableImagePress;
775
+ _enableCodeBlockPress = newViewProps.enableCodeBlockPress;
677
776
 
678
777
  if (ENRMContextMenuItemsChanged(oldViewProps.contextMenuItems, newViewProps.contextMenuItems)) {
679
778
  _contextMenuItemTexts = ENRMContextMenuTextsFromItems(newViewProps.contextMenuItems);
@@ -740,6 +839,21 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
740
839
  _dirtyFlags |= ENRMDirtyRender;
741
840
  }
742
841
 
842
+ if (newViewProps.numberOfLines != oldViewProps.numberOfLines) {
843
+ _numberOfLines = (NSInteger)newViewProps.numberOfLines;
844
+ [self applyLineClampToTextContainer];
845
+ _forceHeightUpdateOnNextRender = YES;
846
+ _dirtyFlags |= ENRMDirtyRender;
847
+ }
848
+
849
+ if (newViewProps.ellipsizeMode != oldViewProps.ellipsizeMode) {
850
+ _ellipsizeLineBreakMode =
851
+ ENRMResolveEllipsizeLineBreakMode([[NSString alloc] initWithUTF8String:newViewProps.ellipsizeMode.c_str()]);
852
+ [self applyLineClampToTextContainer];
853
+ _forceHeightUpdateOnNextRender = YES;
854
+ _dirtyFlags |= ENRMDirtyRender;
855
+ }
856
+
743
857
  if (_dirtyFlags & ENRMDirtyRender) {
744
858
  _pendingStyleFingerprint =
745
859
  computeStyleFingerprint(newViewProps.markdownStyle) ^ std::hash<bool>{}(newViewProps.allowTrailingMargin);
@@ -757,14 +871,20 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
757
871
 
758
872
  if (self.window && _renderedMarkdown != nil) {
759
873
  _textView.hidden = NO;
760
- ENRMRefreshTextViewAfterWindowAttach(_textView, self.bounds);
874
+ // Refresh in place: RCTViewComponentView owns the text view's frame and has
875
+ // already set it to the content frame, so re-assigning self.bounds here would
876
+ // drop the containerStyle insets (see contentBounds).
877
+ ENRMRefreshTextViewLayout(_textView);
761
878
 
762
879
  [_spoilerManager setNeedsUpdate];
763
880
  [_spoilerManager updateIfNeeded];
764
881
 
765
- CGSize measured = [self measureSize:self.bounds.size.width];
766
- if (needsHeightUpdate(measured, self.bounds)) {
767
- [self requestHeightUpdate];
882
+ CGRect contentBounds = [self contentBounds];
883
+ if (contentBounds.size.width > 0) {
884
+ CGSize measured = [self measureSize:contentBounds.size.width];
885
+ if (needsHeightUpdate(measured, contentBounds)) {
886
+ [self requestHeightUpdate];
887
+ }
768
888
  }
769
889
  }
770
890
  }
@@ -784,6 +904,7 @@ typedef NS_OPTIONS(NSUInteger, ENRMDirtyFlags) {
784
904
  _renderedMarkdown = nil;
785
905
  _config = nil;
786
906
  _md4cFlags = [EnrichedMarkdownText flagsFromProps:resetProps->md4cFlags];
907
+ _isGFM = resetProps->isGFM;
787
908
  _maxFontSizeMultiplier = 0;
788
909
  _lastElementMarginBottom = 0;
789
910
  _allowTrailingMargin = NO;
@@ -829,7 +950,7 @@ Class<RCTComponentViewProtocol> EnrichedMarkdownTextCls(void)
829
950
  {
830
951
  if (_textView) {
831
952
  CGPoint textViewPoint = [self convertPoint:point toView:_textView];
832
- if (isPointOnInteractiveElement(_textView, textViewPoint)) {
953
+ if (isPointOnInteractiveElement(_textView, textViewPoint, _enableImagePress, _enableCodeBlockPress)) {
833
954
  return nil;
834
955
  }
835
956
  }
@@ -870,6 +991,21 @@ Class<RCTComponentViewProtocol> EnrichedMarkdownTextCls(void)
870
991
  emitter->onLinkLayout(ENRMLinkLayoutEventFromFragments<EnrichedMarkdownTextEventEmitter::OnLinkLayout>(fragments));
871
992
  }
872
993
 
994
+ - (void)emitImagePress:(NSString *)url altText:(NSString *)altText
995
+ {
996
+ auto emitter = std::static_pointer_cast<EnrichedMarkdownTextEventEmitter const>(_eventEmitter);
997
+ if (emitter)
998
+ emitter->onImagePress({.url = std::string(url.UTF8String ?: ""), .altText = std::string(altText.UTF8String ?: "")});
999
+ }
1000
+
1001
+ - (void)emitCodeBlockPress:(NSString *)code language:(NSString *)language
1002
+ {
1003
+ auto emitter = std::static_pointer_cast<EnrichedMarkdownTextEventEmitter const>(_eventEmitter);
1004
+ if (emitter)
1005
+ emitter->onCodeBlockPress(
1006
+ {.code = std::string(code.UTF8String ?: ""), .language = std::string(language.UTF8String ?: "")});
1007
+ }
1008
+
873
1009
  - (void)emitTaskListItemPress:(NSInteger)index checked:(BOOL)checked text:(NSString *)text
874
1010
  {
875
1011
  auto emitter = std::static_pointer_cast<EnrichedMarkdownTextEventEmitter const>(_eventEmitter);
@@ -904,6 +1040,12 @@ Class<RCTComponentViewProtocol> EnrichedMarkdownTextCls(void)
904
1040
  });
905
1041
  }
906
1042
 
1043
+ - (void)updateEventEmitter:(const facebook::react::EventEmitter::Shared &)eventEmitter
1044
+ {
1045
+ [super updateEventEmitter:eventEmitter];
1046
+ [_latexErrorCoordinator flushPending];
1047
+ }
1048
+
907
1049
  - (void)textTapped:(ENRMTapRecognizer *)recognizer
908
1050
  {
909
1051
  ENRMPlatformTextView *textView = (ENRMPlatformTextView *)recognizer.view;
@@ -922,7 +1064,27 @@ Class<RCTComponentViewProtocol> EnrichedMarkdownTextCls(void)
922
1064
  return;
923
1065
  }
924
1066
 
925
- ENRMHandleTapOnTextView(textView, recognizer, ^(NSString *url) { [self emitLinkPress:url]; });
1067
+ if (ENRMHandleTapOnTextView(textView, recognizer, ^(NSString *url) { [self emitLinkPress:url]; })) {
1068
+ return;
1069
+ }
1070
+
1071
+ if (_enableImagePress) {
1072
+ NSDictionary<NSString *, NSString *> *image = imageAtTapLocation(textView, recognizer);
1073
+ if (image) {
1074
+ [self emitImagePress:image[@"url"] altText:image[@"altText"]];
1075
+ return;
1076
+ }
1077
+ }
1078
+
1079
+ // Skip while text is selected so the tap clears the selection instead of
1080
+ // firing the press (matches the web guard).
1081
+ if (_enableCodeBlockPress && textView.selectedRange.length == 0) {
1082
+ NSDictionary<NSString *, NSString *> *codeBlock = codeBlockAtTapLocation(textView, recognizer);
1083
+ if (codeBlock) {
1084
+ [self emitCodeBlockPress:codeBlock[@"code"] language:codeBlock[@"language"]];
1085
+ return;
1086
+ }
1087
+ }
926
1088
  }
927
1089
 
928
1090
  #pragma mark - UITextViewDelegate (Link Interaction)
@@ -14,6 +14,14 @@ NS_ASSUME_NONNULL_BEGIN
14
14
  - (void)imageAttachmentDidResolveLayout;
15
15
  @end
16
16
 
17
+ @interface RCTUIView (ENRMImageLayoutObserver)
18
+ /**
19
+ * Nearest ancestor (self included) adopting ENRMImageLayoutObserver, walking up
20
+ * the superview chain. Returns nil when none is found.
21
+ */
22
+ - (nullable id<ENRMImageLayoutObserver>)enrm_imageLayoutObserver;
23
+ @end
24
+
17
25
  /**
18
26
  * Custom NSTextAttachment for rendering markdown images.
19
27
  * Images are loaded asynchronously and scaled dynamically based on text container width.
@@ -24,9 +32,16 @@ NS_ASSUME_NONNULL_BEGIN
24
32
  @property (nonatomic, readonly) NSString *imageURL;
25
33
  @property (nonatomic, readonly) BOOL isInline;
26
34
 
27
- + (instancetype)attachmentForURL:(NSString *)imageURL config:(StyleConfig *)config isInline:(BOOL)isInline;
35
+ /**
36
+ * Invoked on the main thread whenever the image finishes loading/processing.
37
+ * Used by self-drawing hosts (e.g. a table grid) that rasterize the attributed
38
+ * string via -drawWithRect: and therefore never get a live text view for the
39
+ * attachment's normal -refreshDisplay invalidation to reach. Such hosts set this
40
+ * to trigger their own redraw (e.g. -setNeedsDisplay).
41
+ */
42
+ @property (nonatomic, copy, nullable) void (^onImageLoaded)(void);
28
43
 
29
- + (void)clearAttachmentRegistry;
44
+ + (instancetype)attachmentForURL:(NSString *)imageURL config:(StyleConfig *)config isInline:(BOOL)isInline;
30
45
 
31
46
  + (NSCache<NSString *, RCTUIImage *> *)originalImageCache;
32
47
  + (NSCache<NSString *, RCTUIImage *> *)processedImageCache;
@@ -17,7 +17,19 @@ static inline NSUInteger ENRMImageByteCost(RCTUIImage *image)
17
17
 
18
18
  static NSCache<NSString *, RCTUIImage *> *_originalImageCache;
19
19
  static NSCache<NSString *, RCTUIImage *> *_processedImageCache;
20
- static NSMapTable<NSString *, ENRMImageAttachment *> *_attachmentRegistry;
20
+
21
+ @implementation RCTUIView (ENRMImageLayoutObserver)
22
+
23
+ - (id<ENRMImageLayoutObserver>)enrm_imageLayoutObserver
24
+ {
25
+ RCTUIView *view = self;
26
+ while (view && ![view conformsToProtocol:@protocol(ENRMImageLayoutObserver)]) {
27
+ view = view.superview;
28
+ }
29
+ return (id<ENRMImageLayoutObserver>)view;
30
+ }
31
+
32
+ @end
21
33
 
22
34
  @interface ENRMImageAttachment ()
23
35
 
@@ -63,29 +75,13 @@ static NSMapTable<NSString *, ENRMImageAttachment *> *_attachmentRegistry;
63
75
  return _processedImageCache;
64
76
  }
65
77
 
66
- + (NSMapTable<NSString *, ENRMImageAttachment *> *)attachmentRegistry
67
- {
68
- static dispatch_once_t onceToken;
69
- dispatch_once(&onceToken, ^{ _attachmentRegistry = [NSMapTable strongToWeakObjectsMapTable]; });
70
- return _attachmentRegistry;
71
- }
72
-
73
78
  + (instancetype)attachmentForURL:(NSString *)imageURL config:(StyleConfig *)config isInline:(BOOL)isInline
74
79
  {
75
- NSString *key =
76
- [NSString stringWithFormat:@"%@_%d", ENRMImageCacheKey(imageURL, [config imageRequestHeaders]), isInline];
77
- ENRMImageAttachment *existing = [[self attachmentRegistry] objectForKey:key];
78
- if (existing && existing.loadedImage) {
79
- return existing;
80
- }
81
- ENRMImageAttachment *attachment = [[self alloc] initWithImageURL:imageURL config:config isInline:isInline];
82
- [[self attachmentRegistry] setObject:attachment forKey:key];
83
- return attachment;
84
- }
85
-
86
- + (void)clearAttachmentRegistry
87
- {
88
- [[self attachmentRegistry] removeAllObjects];
80
+ // Always a fresh instance, never shared across positions: the table renderer can draw
81
+ // the same image URL at a different width than a copy outside the table, and a shared
82
+ // NSTextAttachment would thrash its single last-processed width into a redraw loop. The
83
+ // image caches keep fresh instances cheap (no re-fetch or re-scale).
84
+ return [[self alloc] initWithImageURL:imageURL config:config isInline:isInline];
89
85
  }
90
86
 
91
87
  - (instancetype)initWithImageURL:(NSString *)imageURL config:(StyleConfig *)config isInline:(BOOL)isInline
@@ -335,6 +331,12 @@ static NSMapTable<NSString *, ENRMImageAttachment *> *_attachmentRegistry;
335
331
 
336
332
  - (void)refreshDisplay
337
333
  {
334
+ // Notify self-drawing hosts (e.g. a table grid) that rasterize us via
335
+ // -drawWithRect: and have no live text view for the invalidation below to reach.
336
+ if (self.onImageLoaded) {
337
+ self.onImageLoaded();
338
+ }
339
+
338
340
  UITextView *textView = [self fetchAssociatedTextView];
339
341
  if (!textView)
340
342
  return;
@@ -361,14 +363,10 @@ static NSMapTable<NSString *, ENRMImageAttachment *> *_attachmentRegistry;
361
363
  if (self.cachedMaxHeight <= 0 && self.cachedAspectRatio <= 0)
362
364
  return;
363
365
 
364
- RCTUIView *candidate = textView;
365
- while (candidate && ![candidate conformsToProtocol:@protocol(ENRMImageLayoutObserver)]) {
366
- candidate = candidate.superview;
367
- }
368
- if (!candidate)
366
+ id<ENRMImageLayoutObserver> observer = [textView enrm_imageLayoutObserver];
367
+ if (!observer)
369
368
  return;
370
369
 
371
- id<ENRMImageLayoutObserver> observer = (id<ENRMImageLayoutObserver>)candidate;
372
370
  dispatch_async(dispatch_get_main_queue(), ^{ [observer imageAttachmentDidResolveLayout]; });
373
371
  }
374
372
 
@@ -25,14 +25,22 @@
25
25
  - (void)renderForMacOS
26
26
  {
27
27
  RCTUIColor *color = self.mathTextColor ?: [RCTUIColor blackColor];
28
+ NSError *error = nil;
28
29
  ENRMRaTeXRenderResult *result = [ENRMRaTeXBridge parse:self.latex
29
30
  displayMode:NO
30
31
  fontSize:self.fontSize
31
32
  color:color
32
33
  bold:self.bold
33
- glyphOverflow:self.glyphOverflow];
34
- if (!result)
34
+ glyphOverflow:self.glyphOverflow
35
+ error:&error];
36
+ if (!result) {
37
+ // Record the failure so the LaTeX error coordinator can report it (onLatexError) once
38
+ // wired, matching the iOS path in prepareIfNeeded.
39
+ _parseFailed = YES;
40
+ _parseMessage = error.localizedDescription ?: @"";
41
+ [self reportLatexErrorIfNeeded];
35
42
  return;
43
+ }
36
44
 
37
45
  _renderResult = result;
38
46
  _mathAscent = result.ascent;
@@ -1,13 +1,15 @@
1
1
  #pragma once
2
+ #import "ENRMLatexErrorReporting.h"
2
3
  #import "ENRMUIKit.h"
3
4
 
4
5
  NS_ASSUME_NONNULL_BEGIN
5
6
 
6
- @interface ENRMMathInlineAttachment : NSTextAttachment
7
+ @interface ENRMMathInlineAttachment : NSTextAttachment <ENRMLatexErrorReporting>
7
8
 
8
9
  @property (nonatomic, strong) NSString *latex;
9
10
  @property (nonatomic, assign) CGFloat fontSize;
10
11
  @property (nonatomic, strong, nullable) RCTUIColor *mathTextColor;
12
+ @property (nonatomic, copy, nullable) ENRMLatexErrorHandler onLatexError;
11
13
 
12
14
  @property (nonatomic, readonly) CGFloat boxHeight;
13
15
 
@@ -30,6 +30,14 @@
30
30
  _mathDescent = 0;
31
31
  }
32
32
 
33
+ - (void)reportLatexErrorIfNeeded
34
+ {
35
+ if (_parseFailed && !_didReportError && self.onLatexError) {
36
+ _didReportError = YES;
37
+ self.onLatexError(self.latex, _parseMessage ?: @"", self.displayMode);
38
+ }
39
+ }
40
+
33
41
  #if !TARGET_OS_OSX
34
42
 
35
43
  - (void)prepareIfNeeded
@@ -38,13 +46,21 @@
38
46
  return;
39
47
 
40
48
  RCTUIColor *color = self.mathTextColor ?: [RCTUIColor blackColor];
49
+ NSError *error = nil;
50
+ // displayMode:NO is deliberate (merge decision D4): inline attachments, including the input's
51
+ // `$$` math chip, are typeset in text style on iOS. self.displayMode is only used for error
52
+ // reporting (onLatexError) and by the chip controller for serialization.
41
53
  ENRMRaTeXRenderResult *result = [ENRMRaTeXBridge parse:self.latex
42
54
  displayMode:NO
43
55
  fontSize:self.fontSize
44
56
  color:color
45
57
  bold:self.bold
46
- glyphOverflow:self.glyphOverflow];
58
+ glyphOverflow:self.glyphOverflow
59
+ error:&error];
47
60
  if (!result) {
61
+ _parseFailed = YES;
62
+ _parseMessage = error.localizedDescription ?: @"";
63
+ [self reportLatexErrorIfNeeded];
48
64
  _fallbackSource = ENRMMathFallbackString(self.latex, @"$", self.fontSize, color);
49
65
  UIFont *font = [_fallbackSource attribute:NSFontAttributeName atIndex:0 effectiveRange:NULL];
50
66
  CGRect bounds = [_fallbackSource boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
@@ -13,6 +13,9 @@
13
13
  ENRMRaTeXRenderResult *_renderResult;
14
14
  // Visible-source fallback when RaTeX cannot parse the span; see ENRMMathFallback.h.
15
15
  NSAttributedString *_fallbackSource;
16
+ BOOL _didReportError;
17
+ BOOL _parseFailed;
18
+ NSString *_parseMessage;
16
19
  }
17
20
  @end
18
21