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,164 @@
1
+ package com.swmansion.enriched.markdown.segments
2
+
3
+ import android.content.Context
4
+ import android.view.View
5
+ import android.widget.FrameLayout
6
+ import kotlin.math.ceil
7
+ import kotlin.math.max
8
+
9
+ /**
10
+ * Reusable view for an AST branch node that holds a vertical stack of block
11
+ * children (the document root and every blockquote). It owns the machinery
12
+ * shared by both: reconciling a list of RenderedSegment into real child views
13
+ * by signature, stacking them vertically with per-segment margins, and
14
+ * reporting the total height (including its own vertical padding).
15
+ *
16
+ * Per-kind view construction is delegated to a SegmentViewFactory the subclass
17
+ * supplies, so root-only wiring (link/copy callbacks, selection menu, spoiler,
18
+ * accessibility, task-list toggle, pending code block) lives with the root and
19
+ * the nested blockquote factory reuses only the shared creators.
20
+ *
21
+ * Layout honors paddingLeft/Top/Right/Bottom so a subclass can inset its
22
+ * children (e.g. a blockquote's border/gap/padding) via padding: children are
23
+ * measured at exactly width - paddingLeft - paddingRight and laid out starting
24
+ * at (paddingLeft, paddingTop). The root uses zero padding, so its behavior is
25
+ * unchanged.
26
+ */
27
+ open class ContainerNodeView(
28
+ context: Context,
29
+ ) : FrameLayout(context) {
30
+ protected val segmentViews = mutableListOf<View>()
31
+ protected val segmentSignatures = mutableListOf<Long>()
32
+
33
+ protected lateinit var segmentViewFactory: SegmentViewFactory
34
+
35
+ protected var trailingMarginEnabled: Boolean = false
36
+
37
+ /**
38
+ * Reconciles the current child views against renderedSegments, attaching and
39
+ * removing views as needed and updating segmentViews/segmentSignatures.
40
+ * Returns whether the topology changed (any view attached or removed).
41
+ */
42
+ protected fun applySegments(
43
+ renderedSegments: List<RenderedSegment>,
44
+ reset: Boolean,
45
+ ): Boolean {
46
+ val result =
47
+ SegmentReconciler.reconcile(
48
+ currentViews = segmentViews.toList(),
49
+ currentSignatures = segmentSignatures.toList(),
50
+ renderedSegments = renderedSegments,
51
+ reset = reset,
52
+ matchesKind = segmentViewFactory::matchesKind,
53
+ createView = { segment ->
54
+ val view = segmentViewFactory.createView(segment)
55
+ segmentViewFactory.animateNewView(view, segment)
56
+ view
57
+ },
58
+ updateView = { view, segment -> segmentViewFactory.updateView(view, segment) },
59
+ )
60
+
61
+ result.viewsToRemove.forEach { removeView(it) }
62
+ result.viewsToAttach.forEach { addView(it) }
63
+
64
+ // Only created views are appended, so a signature-based reorder would leave
65
+ // getChildAt out of step with segmentViews. detach/attach splices the child array
66
+ // without a detach-from-window pass, so a moved child keeps its selection, focus
67
+ // and scroll state; each step fixes one index without disturbing the ones before it.
68
+ result.views.forEachIndexed { index, view ->
69
+ if (getChildAt(index) !== view) {
70
+ detachViewFromParent(view)
71
+ attachViewToParent(view, index, view.layoutParams)
72
+ }
73
+ }
74
+
75
+ segmentViews.clear()
76
+ segmentViews.addAll(result.views)
77
+ segmentSignatures.clear()
78
+ segmentSignatures.addAll(result.signatures)
79
+
80
+ return result.viewsToAttach.isNotEmpty() || result.viewsToRemove.isNotEmpty()
81
+ }
82
+
83
+ protected fun layoutSegments() {
84
+ val containerWidth = width
85
+ if (containerWidth <= 0) return
86
+
87
+ val contentWidth = (containerWidth - paddingLeft - paddingRight).coerceAtLeast(0)
88
+
89
+ val needsOverhang =
90
+ segmentViews.any { view ->
91
+ view is TableContainerView &&
92
+ ceil(view.tableStyle.horizontalOverflow.toDouble()).toInt() > 0
93
+ }
94
+ if (clipChildren == needsOverhang) {
95
+ clipChildren = !needsOverhang
96
+ }
97
+
98
+ var currentY = paddingTop
99
+ val lastIndex = segmentViews.lastIndex
100
+ val widthSpec = MeasureSpec.makeMeasureSpec(contentWidth, MeasureSpec.EXACTLY)
101
+ val heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)
102
+
103
+ segmentViews.forEachIndexed { index, view ->
104
+ val segment = view as? BlockSegmentView
105
+ val shouldAddBottomMargin = index != lastIndex || trailingMarginEnabled
106
+
107
+ currentY += segment?.segmentMarginTop ?: 0
108
+
109
+ val overhang =
110
+ if (view is TableContainerView) {
111
+ max(ceil(view.tableStyle.horizontalOverflow.toDouble()).toInt(), 0)
112
+ } else {
113
+ 0
114
+ }
115
+
116
+ if (overhang > 0) {
117
+ val extendedWidth = contentWidth + overhang * 2
118
+ val extWidthSpec = MeasureSpec.makeMeasureSpec(extendedWidth, MeasureSpec.EXACTLY)
119
+ view.measure(extWidthSpec, heightSpec)
120
+ view.layout(
121
+ paddingLeft - overhang,
122
+ currentY,
123
+ paddingLeft + contentWidth + overhang,
124
+ currentY + view.measuredHeight,
125
+ )
126
+ } else {
127
+ view.measure(widthSpec, heightSpec)
128
+ view.layout(paddingLeft, currentY, paddingLeft + contentWidth, currentY + view.measuredHeight)
129
+ }
130
+ currentY += view.measuredHeight
131
+
132
+ if (shouldAddBottomMargin) {
133
+ currentY += segment?.segmentMarginBottom ?: 0
134
+ }
135
+ }
136
+ }
137
+
138
+ /**
139
+ * Measures every child at the inner content width so computeSegmentsTotalHeight
140
+ * can read accurate measuredHeights during a subclass's onMeasure, before the
141
+ * onLayout pass runs layoutSegments. Without this a container that sizes itself
142
+ * from its children (a blockquote) would measure them as zero-height and clip.
143
+ */
144
+ protected fun measureSegmentChildren(outerWidth: Int) {
145
+ val contentWidth = (outerWidth - paddingLeft - paddingRight).coerceAtLeast(0)
146
+ val widthSpec = MeasureSpec.makeMeasureSpec(contentWidth, MeasureSpec.EXACTLY)
147
+ val heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)
148
+ segmentViews.forEach { it.measure(widthSpec, heightSpec) }
149
+ }
150
+
151
+ protected fun computeSegmentsTotalHeight(): Int {
152
+ var totalHeight = paddingTop + paddingBottom
153
+ val lastIndex = segmentViews.lastIndex
154
+ segmentViews.forEachIndexed { index, view ->
155
+ val segment = view as? BlockSegmentView
156
+ totalHeight += segment?.segmentMarginTop ?: 0
157
+ totalHeight += view.measuredHeight
158
+ if (index != lastIndex || trailingMarginEnabled) {
159
+ totalHeight += segment?.segmentMarginBottom ?: 0
160
+ }
161
+ }
162
+ return totalHeight
163
+ }
164
+ }
@@ -1,4 +1,4 @@
1
- package com.swmansion.enriched.markdown.utils.common
1
+ package com.swmansion.enriched.markdown.segments
2
2
 
3
3
  import com.swmansion.enriched.markdown.parser.MarkdownASTNode
4
4
 
@@ -19,6 +19,14 @@ sealed interface MarkdownSegment {
19
19
  data class CodeBlock(
20
20
  val node: MarkdownASTNode,
21
21
  ) : MarkdownSegment
22
+
23
+ data class Blockquote(
24
+ val node: MarkdownASTNode,
25
+ ) : MarkdownSegment
26
+
27
+ data class Video(
28
+ val node: MarkdownASTNode,
29
+ ) : MarkdownSegment
22
30
  }
23
31
 
24
32
  fun splitASTIntoSegments(root: MarkdownASTNode): List<MarkdownSegment> {
@@ -55,6 +63,18 @@ fun splitASTIntoSegments(root: MarkdownASTNode): List<MarkdownSegment> {
55
63
  segments.add(MarkdownSegment.CodeBlock(child))
56
64
  }
57
65
 
66
+ MarkdownASTNode.NodeType.Blockquote,
67
+ MarkdownASTNode.NodeType.Admonition,
68
+ -> {
69
+ flushTextNodes()
70
+ segments.add(MarkdownSegment.Blockquote(child))
71
+ }
72
+
73
+ MarkdownASTNode.NodeType.Video -> {
74
+ flushTextNodes()
75
+ segments.add(MarkdownSegment.Video(child))
76
+ }
77
+
58
78
  else -> {
59
79
  currentTextNodes.add(child)
60
80
  }
@@ -0,0 +1,137 @@
1
+ package com.swmansion.enriched.markdown.segments
2
+
3
+ import android.content.Context
4
+ import android.text.Spannable
5
+ import com.swmansion.enriched.markdown.math.LatexErrorReporter
6
+ import com.swmansion.enriched.markdown.parser.MarkdownASTNode
7
+ import com.swmansion.enriched.markdown.renderer.BlockquoteTextRenderer
8
+ import com.swmansion.enriched.markdown.renderer.Renderer
9
+ import com.swmansion.enriched.markdown.spans.ImageSpan
10
+ import com.swmansion.enriched.markdown.styles.BlockquoteStyle
11
+ import com.swmansion.enriched.markdown.styles.StyleConfig
12
+
13
+ sealed interface RenderedSegment {
14
+ val signature: Long
15
+
16
+ data class Text(
17
+ /**
18
+ * The renderer's own buffer, which the segment's text view adopts uncopied.
19
+ * Once displayed it *is* the view's live text, so the view mutates it: `TextView`
20
+ * attaches its `ChangeWatcher`, the `Editor` its `SpanController`, and selection
21
+ * adds and moves the selection marks — all as spans on this very instance.
22
+ *
23
+ * A segment is therefore only a faithful record of what the renderer produced
24
+ * until the view takes it. Anything that caches, diffs, counts or hashes the spans
25
+ * here must read them before the segment is applied, or filter the view's spans
26
+ * out; reading afterwards yields the view's bookkeeping mixed in with the markdown
27
+ * spans, and a result that changes as the user merely selects text.
28
+ */
29
+ val styledText: Spannable,
30
+ val imageSpans: List<ImageSpan>,
31
+ val needsJustify: Boolean,
32
+ val lastElementMarginBottom: Float,
33
+ override val signature: Long,
34
+ ) : RenderedSegment
35
+
36
+ data class Table(
37
+ val node: MarkdownASTNode,
38
+ override val signature: Long,
39
+ ) : RenderedSegment
40
+
41
+ data class Math(
42
+ val latex: String,
43
+ val highlighted: Boolean,
44
+ override val signature: Long,
45
+ ) : RenderedSegment
46
+
47
+ data class CodeBlock(
48
+ val node: MarkdownASTNode,
49
+ override val signature: Long,
50
+ ) : RenderedSegment
51
+
52
+ data class Blockquote(
53
+ val node: MarkdownASTNode,
54
+ override val signature: Long,
55
+ ) : RenderedSegment
56
+
57
+ data class Video(
58
+ val node: MarkdownASTNode,
59
+ override val signature: Long,
60
+ ) : RenderedSegment
61
+ }
62
+
63
+ object MarkdownSegmentRenderer {
64
+ fun render(
65
+ segments: List<MarkdownSegment>,
66
+ style: StyleConfig,
67
+ context: Context,
68
+ onLinkPress: ((String) -> Unit)?,
69
+ onLinkLongPress: ((String) -> Unit)?,
70
+ blockquoteStyle: BlockquoteStyle? = null,
71
+ onLatexError: LatexErrorReporter? = null,
72
+ ): List<RenderedSegment> =
73
+ segments.map { segment ->
74
+ when (segment) {
75
+ is MarkdownSegment.Text -> {
76
+ renderTextSegment(segment.nodes, style, context, onLinkPress, onLinkLongPress, blockquoteStyle, onLatexError)
77
+ }
78
+
79
+ is MarkdownSegment.Table -> {
80
+ val signature = SegmentSignature.signatureForNode(segment.node) xor SegmentSignature.TABLE_KIND_SALT
81
+ RenderedSegment.Table(segment.node, signature)
82
+ }
83
+
84
+ is MarkdownSegment.Math -> {
85
+ var signature = SegmentSignature.signatureForNode(null) xor SegmentSignature.MATH_KIND_SALT
86
+ signature = SegmentSignature.fnvMixString(signature, segment.latex)
87
+ val highlighted = segment.node.getAttribute("highlight") == "true"
88
+ // A highlight toggle keeps the latex, so it must change the signature or the view is skipped.
89
+ if (highlighted) signature = SegmentSignature.fnvMixString(signature, "highlight")
90
+ RenderedSegment.Math(segment.latex, highlighted, signature)
91
+ }
92
+
93
+ is MarkdownSegment.CodeBlock -> {
94
+ val signature = SegmentSignature.signatureForNode(segment.node) xor SegmentSignature.CODE_BLOCK_KIND_SALT
95
+ RenderedSegment.CodeBlock(segment.node, signature)
96
+ }
97
+
98
+ is MarkdownSegment.Blockquote -> {
99
+ val signature = SegmentSignature.signatureForNode(segment.node) xor SegmentSignature.BLOCKQUOTE_KIND_SALT
100
+ RenderedSegment.Blockquote(segment.node, signature)
101
+ }
102
+
103
+ is MarkdownSegment.Video -> {
104
+ val signature = SegmentSignature.signatureForNode(segment.node) xor SegmentSignature.VIDEO_KIND_SALT
105
+ RenderedSegment.Video(segment.node, signature)
106
+ }
107
+ }
108
+ }
109
+
110
+ private fun renderTextSegment(
111
+ nodes: List<MarkdownASTNode>,
112
+ style: StyleConfig,
113
+ context: Context,
114
+ onLinkPress: ((String) -> Unit)?,
115
+ onLinkLongPress: ((String) -> Unit)?,
116
+ blockquoteStyle: BlockquoteStyle?,
117
+ onLatexError: LatexErrorReporter?,
118
+ ): RenderedSegment.Text {
119
+ val renderer = Renderer().apply { configure(style, context, onLatexError) }
120
+ val signature = SegmentSignature.signatureForNodes(nodes) xor SegmentSignature.TEXT_KIND_SALT
121
+
122
+ val styledText =
123
+ if (blockquoteStyle != null) {
124
+ BlockquoteTextRenderer(blockquoteStyle).render(renderer, nodes, onLinkPress, onLinkLongPress)
125
+ } else {
126
+ renderer.renderContent(nodes, onLinkPress, onLinkLongPress)
127
+ }
128
+
129
+ return RenderedSegment.Text(
130
+ styledText = styledText,
131
+ imageSpans = renderer.getCollectedImageSpans().toList(),
132
+ needsJustify = style.needsJustify,
133
+ lastElementMarginBottom = renderer.getLastElementMarginBottom(),
134
+ signature = signature,
135
+ )
136
+ }
137
+ }
@@ -0,0 +1,139 @@
1
+ package com.swmansion.enriched.markdown.segments
2
+
3
+ import android.content.Context
4
+ import android.graphics.Paint
5
+ import android.os.Build
6
+ import android.text.Layout
7
+ import android.text.StaticLayout
8
+ import android.text.TextPaint
9
+ import com.swmansion.enriched.markdown.MeasurementStore
10
+ import com.swmansion.enriched.markdown.styles.StyleConfig
11
+ import com.swmansion.enriched.markdown.utils.text.extensions.replaceMathSpansWithPlaceholders
12
+ import kotlin.math.ceil
13
+
14
+ /**
15
+ * View-free height summation for a vertical stack of RenderedSegments at a fixed
16
+ * content width, single-sourced so the shadow-node measurement pass
17
+ * (MeasurementStore) and the blockquote container's own static measurer report
18
+ * identical heights.
19
+ *
20
+ * Math heights must be measured up front on the main thread by the caller and
21
+ * supplied through mathHeightForIndex, because the summation runs off the main
22
+ * thread. Blockquote children recurse through
23
+ * BlockquoteContainerView.measureBlockquoteNodeHeight.
24
+ */
25
+ object SegmentHeightMeasurer {
26
+ fun measureSegmentsHeight(
27
+ segments: List<RenderedSegment>,
28
+ style: StyleConfig,
29
+ context: Context,
30
+ contentWidthPx: Float,
31
+ fontSizePx: Float,
32
+ breakStrategy: Int,
33
+ allowTrailingMargin: Boolean,
34
+ mathHeightForIndex: (Int) -> Float,
35
+ ): Float {
36
+ val widthPx = ceil(contentWidthPx).toInt().coerceAtLeast(1)
37
+ val lastIndex = segments.lastIndex
38
+ var totalHeightPx = 0f
39
+
40
+ for ((index, segment) in segments.withIndex()) {
41
+ val isLastSegment = index == lastIndex
42
+ val includeBottomMargin = if (isLastSegment) allowTrailingMargin else true
43
+
44
+ when (segment) {
45
+ is RenderedSegment.Text -> {
46
+ // Same inlineMath.paddingVertical (+ glyphOverflow) the real spans are built with,
47
+ // or the measured line box won't match the drawn one.
48
+ segment.styledText.replaceMathSpansWithPlaceholders(context, style.inlineMathStyle.boxPaddingVertical)
49
+ val layout = createStaticLayout(segment.styledText, fontSizePx, widthPx, breakStrategy)
50
+ totalHeightPx += layout.height
51
+ if (includeBottomMargin) {
52
+ totalHeightPx += segment.lastElementMarginBottom
53
+ }
54
+ }
55
+
56
+ is RenderedSegment.Table -> {
57
+ totalHeightPx += style.tableStyle.marginTop
58
+ totalHeightPx += TableContainerView.measureTableNodeHeight(segment.node, style, context)
59
+ if (includeBottomMargin) {
60
+ totalHeightPx += style.tableStyle.marginBottom
61
+ }
62
+ }
63
+
64
+ is RenderedSegment.Math -> {
65
+ totalHeightPx += style.mathStyle.marginTop
66
+ totalHeightPx += mathHeightForIndex(index)
67
+ if (includeBottomMargin) {
68
+ totalHeightPx += style.mathStyle.marginBottom
69
+ }
70
+ }
71
+
72
+ is RenderedSegment.CodeBlock -> {
73
+ totalHeightPx += style.codeBlockStyle.marginTop
74
+ totalHeightPx += CodeBlockContainerView.measureCodeBlockNodeHeight(segment.node, style, context, contentWidthPx)
75
+ if (includeBottomMargin) {
76
+ totalHeightPx += style.codeBlockStyle.marginBottom
77
+ }
78
+ }
79
+
80
+ is RenderedSegment.Blockquote -> {
81
+ // A quote encountered here is always nested inside another quote, so it
82
+ // carries no vertical margin (only the outermost quote does, added by
83
+ // MeasurementStore); this mirrors BlockquoteContainerView.nested.
84
+ totalHeightPx += BlockquoteContainerView.measureBlockquoteNodeHeight(segment.node, style, context, contentWidthPx)
85
+ }
86
+
87
+ is RenderedSegment.Video -> {
88
+ totalHeightPx += style.videoStyle.marginTop
89
+ totalHeightPx += contentWidthPx / style.videoStyle.resolvedAspectRatio
90
+ if (includeBottomMargin) {
91
+ totalHeightPx += style.videoStyle.marginBottom
92
+ }
93
+ }
94
+ }
95
+ }
96
+ return totalHeightPx
97
+ }
98
+
99
+ fun createStaticLayout(
100
+ text: CharSequence,
101
+ fontSizePx: Float,
102
+ widthPx: Int,
103
+ breakStrategy: Int,
104
+ ): StaticLayout {
105
+ val paint =
106
+ TextPaint(Paint.ANTI_ALIAS_FLAG).apply {
107
+ textSize = fontSizePx
108
+ }
109
+ // HWK-1415: AppCompatTextView draws emoji through EmojiCompat, which can be wider than
110
+ // the fallback glyph and wrap a line earlier, so measure the same glyphs here too
111
+ // (MeasurementStore measures every blockquote through this path).
112
+ val content = MeasurementStore.withEmojiSpans(text)
113
+ prepareImageSpansForMeasurement(content, widthPx)
114
+ return StaticLayout.Builder
115
+ .obtain(content, 0, content.length, paint, widthPx)
116
+ .setIncludePad(false)
117
+ .setLineSpacing(0f, 1f)
118
+ .apply {
119
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
120
+ @Suppress("WrongConstant")
121
+ setBreakStrategy(breakStrategy)
122
+ }
123
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
124
+ setUseLineSpacingFromFallbacks(true)
125
+ }
126
+ }.build()
127
+ }
128
+
129
+ private fun prepareImageSpansForMeasurement(
130
+ text: CharSequence?,
131
+ widthPx: Int,
132
+ ) {
133
+ if (widthPx <= 1) return
134
+ val spanned = text as? android.text.Spanned ?: return
135
+ spanned
136
+ .getSpans(0, spanned.length, com.swmansion.enriched.markdown.spans.ImageSpan::class.java)
137
+ .forEach { it.prepareForMeasurement(spanned, widthPx) }
138
+ }
139
+ }
@@ -1,4 +1,4 @@
1
- package com.swmansion.enriched.markdown.utils.common
1
+ package com.swmansion.enriched.markdown.segments
2
2
 
3
3
  import android.view.View
4
4
 
@@ -1,4 +1,4 @@
1
- package com.swmansion.enriched.markdown.utils.common
1
+ package com.swmansion.enriched.markdown.segments
2
2
 
3
3
  import com.swmansion.enriched.markdown.parser.MarkdownASTNode
4
4
 
@@ -12,6 +12,8 @@ object SegmentSignature {
12
12
  internal const val TABLE_KIND_SALT = 0x7461626C00000000L // "tabl"
13
13
  internal const val MATH_KIND_SALT = 0x6D61746800000000L // "math"
14
14
  internal const val CODE_BLOCK_KIND_SALT = 0x63626C6B00000000L // "cblk"
15
+ internal const val BLOCKQUOTE_KIND_SALT = 0x6271746500000000L // "bqte"
16
+ internal const val VIDEO_KIND_SALT = 0x7669646F00000000L // "video"
15
17
 
16
18
  private fun fnvMixByte(
17
19
  hash: Long,