react-native-enriched-markdown-scaffold 1.0.2-scaffold.1 → 1.0.2-scaffold.11

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 (168) hide show
  1. package/android/build.gradle +2 -0
  2. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerDelegate.java +18 -0
  3. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerInterface.java +4 -0
  4. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerDelegate.java +18 -0
  5. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerInterface.java +4 -0
  6. package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.cpp +148 -0
  7. package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.h +120 -0
  8. package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.cpp +30 -0
  9. package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.h +210 -0
  10. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdown.kt +180 -2
  11. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownInternalText.kt +45 -0
  12. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownManager.kt +35 -0
  13. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownText.kt +112 -0
  14. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownTextManager.kt +34 -0
  15. package/android/src/main/java/com/swmansion/enriched/markdown/MeasurementStore.kt +46 -8
  16. package/android/src/main/java/com/swmansion/enriched/markdown/events/CopyRequestEvent.kt +28 -0
  17. package/android/src/main/java/com/swmansion/enriched/markdown/events/LinkLayoutEvent.kt +36 -0
  18. package/android/src/main/java/com/swmansion/enriched/markdown/events/SelectionChangeEvent.kt +43 -0
  19. package/android/src/main/java/com/swmansion/enriched/markdown/input/EnrichedMarkdownTextInputView.kt +25 -3
  20. package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/InputConnectionWrapper.kt +7 -0
  21. package/android/src/main/java/com/swmansion/enriched/markdown/renderer/LinkRenderer.kt +37 -7
  22. package/android/src/main/java/com/swmansion/enriched/markdown/renderer/SpanStyleCache.kt +5 -1
  23. package/android/src/main/java/com/swmansion/enriched/markdown/spans/CodeBackgroundSpan.kt +13 -99
  24. package/android/src/main/java/com/swmansion/enriched/markdown/spans/InlineChipPainter.kt +140 -0
  25. package/android/src/main/java/com/swmansion/enriched/markdown/spans/LinkChipSpans.kt +177 -0
  26. package/android/src/main/java/com/swmansion/enriched/markdown/spans/LinkSpan.kt +1 -6
  27. package/android/src/main/java/com/swmansion/enriched/markdown/styles/InlineMathStyle.kt +16 -1
  28. package/android/src/main/java/com/swmansion/enriched/markdown/styles/LinkStyle.kt +36 -1
  29. package/android/src/main/java/com/swmansion/enriched/markdown/styles/LinkVariantEntry.kt +7 -3
  30. package/android/src/main/java/com/swmansion/enriched/markdown/styles/MathStyle.kt +3 -0
  31. package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/MarkdownViewManagerUtils.kt +51 -0
  32. package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/RenderedSegment.kt +5 -1
  33. package/android/src/main/java/com/swmansion/enriched/markdown/utils/input/PasteTextUtils.kt +34 -2
  34. package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/conversion/HTMLGenerator.kt +2 -1
  35. package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/conversion/MarkdownExtractor.kt +6 -0
  36. package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/HeadlessActionMode.kt +88 -0
  37. package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/LinkLayoutCollector.kt +100 -0
  38. package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/SelectionActionMode.kt +53 -14
  39. package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/SelectionChangeReporter.kt +232 -0
  40. package/android/src/main/java/com/swmansion/enriched/markdown/views/BlockMenuOptions.kt +64 -0
  41. package/android/src/main/java/com/swmansion/enriched/markdown/views/CodeBlockContainerView.kt +29 -3
  42. package/android/src/main/java/com/swmansion/enriched/markdown/views/TableContainerView.kt +30 -7
  43. package/android/src/math/java/com/swmansion/enriched/markdown/renderer/MathInlineRenderer.kt +1 -0
  44. package/android/src/math/java/com/swmansion/enriched/markdown/spans/MathInlineSpan.kt +13 -6
  45. package/android/src/math/java/com/swmansion/enriched/markdown/spans/MathMeasureHelper.kt +2 -1
  46. package/android/src/math/java/com/swmansion/enriched/markdown/views/MathContainerView.kt +35 -9
  47. package/cpp/parser/MD4CParser.cpp +24 -2
  48. package/docs/API_REFERENCE.md +183 -4
  49. package/docs/COPY_OPTIONS.md +40 -0
  50. package/docs/INPUT.md +3 -1
  51. package/docs/MENTIONS.md +8 -1
  52. package/docs/STYLES.md +27 -0
  53. package/docs/TEXT.md +2 -0
  54. package/docs/WEB.md +1 -0
  55. package/ios/EnrichedMarkdown.mm +326 -10
  56. package/ios/EnrichedMarkdownText.mm +203 -6
  57. package/ios/attachments/ENRMMathInlineAttachment+macOS.m +2 -1
  58. package/ios/attachments/ENRMMathInlineAttachment.h +3 -0
  59. package/ios/attachments/ENRMMathInlineAttachment.m +2 -1
  60. package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/EventEmitters.cpp +148 -0
  61. package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/EventEmitters.h +120 -0
  62. package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.cpp +30 -0
  63. package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.h +210 -0
  64. package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/RCTComponentViewHelpers.h +50 -2
  65. package/ios/internals/MeasurementCache.h +8 -2
  66. package/ios/math/ENRMRaTeXBridge.swift +23 -5
  67. package/ios/renderer/ENRMMathInlineRenderer.m +1 -0
  68. package/ios/renderer/LinkRenderer.m +47 -15
  69. package/ios/styles/StyleConfig.h +20 -0
  70. package/ios/styles/StyleConfig.mm +84 -0
  71. package/ios/utils/CodeBackground.m +3 -65
  72. package/ios/utils/ENRMBlockMenu.h +66 -0
  73. package/ios/utils/ENRMChipDrawing.h +24 -0
  74. package/ios/utils/ENRMChipDrawing.m +83 -0
  75. package/ios/utils/ENRMLinkChip.h +70 -0
  76. package/ios/utils/ENRMLinkChip.m +213 -0
  77. package/ios/utils/ENRMLinkLayout.h +50 -0
  78. package/ios/utils/ENRMLinkLayout.m +45 -0
  79. package/ios/utils/ENRMSelectionChange.h +120 -0
  80. package/ios/utils/ENRMSelectionChange.m +282 -0
  81. package/ios/utils/EditMenuUtils+macOS.m +4 -1
  82. package/ios/utils/EditMenuUtils.h +35 -6
  83. package/ios/utils/EditMenuUtils.m +171 -15
  84. package/ios/utils/HTMLGenerator.m +2 -1
  85. package/ios/utils/MarkdownAccessibilityElementBuilder.m +3 -1
  86. package/ios/utils/MarkdownExtractor.m +2 -1
  87. package/ios/utils/RTFExportUtils.m +2 -0
  88. package/ios/utils/RenderedMarkdownSegment.h +2 -1
  89. package/ios/utils/RenderedMarkdownSegment.m +2 -1
  90. package/ios/utils/SegmentRenderer.m +5 -1
  91. package/ios/utils/StylePropsUtils.h +47 -1
  92. package/ios/utils/TextViewLayoutManager.mm +3 -0
  93. package/ios/views/ENRMCodeBlockContainerView.h +16 -2
  94. package/ios/views/ENRMCodeBlockContainerView.m +22 -19
  95. package/ios/views/ENRMMathContainerView.h +14 -0
  96. package/ios/views/ENRMMathContainerView.m +23 -20
  97. package/ios/views/TableContainerView.h +14 -0
  98. package/ios/views/TableContainerView.m +34 -18
  99. package/lib/module/EnrichedMarkdownNativeComponent.ts +138 -1
  100. package/lib/module/EnrichedMarkdownTextNativeComponent.ts +138 -1
  101. package/lib/module/index.js.map +1 -1
  102. package/lib/module/jest/index.js +14 -0
  103. package/lib/module/jest/index.js.map +1 -1
  104. package/lib/module/native/EnrichedMarkdownText.js +169 -11
  105. package/lib/module/native/EnrichedMarkdownText.js.map +1 -1
  106. package/lib/module/normalizeMarkdownStyle.js +17 -4
  107. package/lib/module/normalizeMarkdownStyle.js.map +1 -1
  108. package/lib/module/normalizeMarkdownStyle.web.js +17 -4
  109. package/lib/module/normalizeMarkdownStyle.web.js.map +1 -1
  110. package/lib/module/web/EnrichedMarkdownText.js +6 -3
  111. package/lib/module/web/EnrichedMarkdownText.js.map +1 -1
  112. package/lib/module/web/renderers/InlineRenderers.js +96 -3
  113. package/lib/module/web/renderers/InlineRenderers.js.map +1 -1
  114. package/lib/module/web/styles.js +18 -0
  115. package/lib/module/web/styles.js.map +1 -1
  116. package/lib/module/web/utils.js +13 -0
  117. package/lib/module/web/utils.js.map +1 -1
  118. package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts +123 -2
  119. package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts.map +1 -1
  120. package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts +123 -2
  121. package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts.map +1 -1
  122. package/lib/typescript/src/index.d.ts +2 -2
  123. package/lib/typescript/src/index.d.ts.map +1 -1
  124. package/lib/typescript/src/index.web.d.ts +1 -1
  125. package/lib/typescript/src/index.web.d.ts.map +1 -1
  126. package/lib/typescript/src/jest/index.d.ts +1 -1
  127. package/lib/typescript/src/jest/index.d.ts.map +1 -1
  128. package/lib/typescript/src/native/EnrichedMarkdownText.d.ts +5 -5
  129. package/lib/typescript/src/native/EnrichedMarkdownText.d.ts.map +1 -1
  130. package/lib/typescript/src/normalizeMarkdownStyle.d.ts.map +1 -1
  131. package/lib/typescript/src/normalizeMarkdownStyle.web.d.ts.map +1 -1
  132. package/lib/typescript/src/types/MarkdownStyle.d.ts +50 -5
  133. package/lib/typescript/src/types/MarkdownStyle.d.ts.map +1 -1
  134. package/lib/typescript/src/types/MarkdownStyleInternal.d.ts +12 -0
  135. package/lib/typescript/src/types/MarkdownStyleInternal.d.ts.map +1 -1
  136. package/lib/typescript/src/types/MarkdownTextProps.d.ts +144 -11
  137. package/lib/typescript/src/types/MarkdownTextProps.d.ts.map +1 -1
  138. package/lib/typescript/src/types/MarkdownTextProps.web.d.ts +41 -1
  139. package/lib/typescript/src/types/MarkdownTextProps.web.d.ts.map +1 -1
  140. package/lib/typescript/src/types/events.d.ts +66 -0
  141. package/lib/typescript/src/types/events.d.ts.map +1 -1
  142. package/lib/typescript/src/web/EnrichedMarkdownText.d.ts +1 -1
  143. package/lib/typescript/src/web/EnrichedMarkdownText.d.ts.map +1 -1
  144. package/lib/typescript/src/web/renderers/InlineRenderers.d.ts.map +1 -1
  145. package/lib/typescript/src/web/styles.d.ts.map +1 -1
  146. package/lib/typescript/src/web/types.d.ts +4 -0
  147. package/lib/typescript/src/web/types.d.ts.map +1 -1
  148. package/lib/typescript/src/web/utils.d.ts +4 -0
  149. package/lib/typescript/src/web/utils.d.ts.map +1 -1
  150. package/package.json +1 -1
  151. package/src/EnrichedMarkdownNativeComponent.ts +138 -1
  152. package/src/EnrichedMarkdownTextNativeComponent.ts +138 -1
  153. package/src/index.tsx +6 -0
  154. package/src/index.web.tsx +5 -1
  155. package/src/jest/index.tsx +22 -1
  156. package/src/native/EnrichedMarkdownText.tsx +220 -9
  157. package/src/normalizeMarkdownStyle.ts +15 -0
  158. package/src/normalizeMarkdownStyle.web.ts +13 -0
  159. package/src/types/MarkdownStyle.ts +51 -5
  160. package/src/types/MarkdownStyleInternal.ts +12 -0
  161. package/src/types/MarkdownTextProps.ts +151 -11
  162. package/src/types/MarkdownTextProps.web.ts +43 -1
  163. package/src/types/events.ts +69 -0
  164. package/src/web/EnrichedMarkdownText.tsx +10 -3
  165. package/src/web/renderers/InlineRenderers.tsx +111 -3
  166. package/src/web/styles.ts +25 -0
  167. package/src/web/types.ts +4 -0
  168. package/src/web/utils.ts +8 -0
@@ -1,6 +1,7 @@
1
1
  #import "RTFExportUtils.h"
2
2
  #import "BlockquoteBorder.h"
3
3
  #import "CodeBackground.h"
4
+ #import "ENRMLinkChip.h"
4
5
  #import "LastElementUtils.h"
5
6
  #import "ListItemRenderer.h"
6
7
  #import "RenderContext.h"
@@ -288,6 +289,7 @@ NSAttributedString *prepareAttributedStringForRTFExport(NSAttributedString *attr
288
289
  RCTUIColor *blockquoteBgColor = [styleConfig blockquoteBackgroundColor];
289
290
 
290
291
  processThematicBreaks(prepared);
292
+ ENRMApplyLinkChipBackgroundsAsTextBackground(prepared);
291
293
  processCodes(prepared, codeBgColor);
292
294
  processCodeBlocks(prepared, codeBlockBgColor);
293
295
  processBlockquotes(prepared, blockquoteBgColor);
@@ -26,7 +26,8 @@ typedef NS_ENUM(NSInteger, ENRMSegmentKind) {
26
26
 
27
27
  @interface ENRMMathSegment : NSObject
28
28
  @property (nonatomic, strong) NSString *latex;
29
- + (instancetype)segmentWithLatex:(NSString *)latex;
29
+ @property (nonatomic, assign) BOOL highlighted;
30
+ + (instancetype)segmentWithLatex:(NSString *)latex highlighted:(BOOL)highlighted;
30
31
  @end
31
32
 
32
33
  @interface ENRMCodeBlockSegment : NSObject
@@ -22,11 +22,12 @@
22
22
  @end
23
23
 
24
24
  @implementation ENRMMathSegment
25
- + (instancetype)segmentWithLatex:(NSString *)latex
25
+ + (instancetype)segmentWithLatex:(NSString *)latex highlighted:(BOOL)highlighted
26
26
  {
27
27
  NSParameterAssert(latex != nil);
28
28
  ENRMMathSegment *segment = [[ENRMMathSegment alloc] init];
29
29
  segment.latex = latex;
30
+ segment.highlighted = highlighted;
30
31
  return segment;
31
32
  }
32
33
  @end
@@ -26,7 +26,8 @@ static NSArray *ENRMSplitASTIntoSegments(MarkdownASTNode *root)
26
26
  [currentTextNodes removeAllObjects];
27
27
  }
28
28
  NSString *latex = child.children.count > 0 ? child.children.firstObject.content : child.content;
29
- [segments addObject:[ENRMMathSegment segmentWithLatex:latex ?: @""]];
29
+ BOOL highlighted = [child.attributes[@"highlight"] isEqualToString:@"true"];
30
+ [segments addObject:[ENRMMathSegment segmentWithLatex:latex ?: @"" highlighted:highlighted]];
30
31
  #else
31
32
  // TODO: Fix block math rendering on macOS. Adding ENRMMathContainerView as a
32
33
  // segment causes all preceding text segments to become invisible.
@@ -86,6 +87,9 @@ NSArray<ENRMRenderedSegment *> *ENRMRenderSegmentsFromAST(MarkdownASTNode *ast,
86
87
  signature ^= (uint8_t)*utf8++;
87
88
  signature *= 1099511628211ULL;
88
89
  }
90
+ // A highlight toggle keeps the latex, so it must change the signature or the view is skipped.
91
+ signature ^= mathSegment.highlighted ? 1ULL : 0ULL;
92
+ signature *= 1099511628211ULL;
89
93
  [renderedSegments addObject:[ENRMRenderedSegment mathSegmentWithSegment:mathSegment signature:signature]];
90
94
  }
91
95
  #endif
@@ -523,6 +523,32 @@ BOOL applyMarkdownStyleToConfig(StyleConfig *config, const MarkdownStyle &newSty
523
523
  changed = YES;
524
524
  }
525
525
 
526
+ if (newStyle.link.borderRadius != oldStyle.link.borderRadius) {
527
+ [config setLinkBorderRadius:newStyle.link.borderRadius];
528
+ changed = YES;
529
+ }
530
+
531
+ if (newStyle.link.paddingHorizontal != oldStyle.link.paddingHorizontal) {
532
+ [config setLinkPaddingHorizontal:newStyle.link.paddingHorizontal];
533
+ changed = YES;
534
+ }
535
+
536
+ if (newStyle.link.paddingVertical != oldStyle.link.paddingVertical) {
537
+ [config setLinkPaddingVertical:newStyle.link.paddingVertical];
538
+ changed = YES;
539
+ }
540
+
541
+ if (newStyle.link.borderColor != oldStyle.link.borderColor) {
542
+ RCTUIColor *color = RCTUIColorFromSharedColor(newStyle.link.borderColor);
543
+ [config setLinkBorderColor:CGColorGetAlpha(color.CGColor) > 0 ? color : nil];
544
+ changed = YES;
545
+ }
546
+
547
+ if (newStyle.link.borderWidth != oldStyle.link.borderWidth) {
548
+ [config setLinkBorderWidth:newStyle.link.borderWidth];
549
+ changed = YES;
550
+ }
551
+
526
552
  {
527
553
  BOOL linkVariantsChanged = newStyle.linkVariants.size() != oldStyle.linkVariants.size();
528
554
  if (!linkVariantsChanged) {
@@ -530,7 +556,11 @@ BOOL applyMarkdownStyleToConfig(StyleConfig *config, const MarkdownStyle &newSty
530
556
  const auto &newVariant = newStyle.linkVariants[i];
531
557
  const auto &oldVariant = oldStyle.linkVariants[i];
532
558
  if (newVariant.pattern != oldVariant.pattern || newVariant.color != oldVariant.color ||
533
- newVariant.underline != oldVariant.underline || newVariant.backgroundColor != oldVariant.backgroundColor) {
559
+ newVariant.underline != oldVariant.underline || newVariant.backgroundColor != oldVariant.backgroundColor ||
560
+ newVariant.borderRadius != oldVariant.borderRadius ||
561
+ newVariant.paddingHorizontal != oldVariant.paddingHorizontal ||
562
+ newVariant.paddingVertical != oldVariant.paddingVertical ||
563
+ newVariant.borderColor != oldVariant.borderColor || newVariant.borderWidth != oldVariant.borderWidth) {
534
564
  linkVariantsChanged = YES;
535
565
  break;
536
566
  }
@@ -545,6 +575,12 @@ BOOL applyMarkdownStyleToConfig(StyleConfig *config, const MarkdownStyle &newSty
545
575
  variant.underline = entry.underline;
546
576
  RCTUIColor *backgroundColor = RCTUIColorFromSharedColor(entry.backgroundColor);
547
577
  variant.backgroundColor = CGColorGetAlpha(backgroundColor.CGColor) > 0 ? backgroundColor : nil;
578
+ variant.borderRadius = entry.borderRadius;
579
+ variant.paddingHorizontal = entry.paddingHorizontal;
580
+ variant.paddingVertical = entry.paddingVertical;
581
+ RCTUIColor *borderColor = RCTUIColorFromSharedColor(entry.borderColor);
582
+ variant.borderColor = CGColorGetAlpha(borderColor.CGColor) > 0 ? borderColor : nil;
583
+ variant.borderWidth = entry.borderWidth;
548
584
  [variants addObject:variant];
549
585
  }
550
586
  [config setLinkVariants:variants];
@@ -1131,6 +1167,11 @@ BOOL applyMarkdownStyleToConfig(StyleConfig *config, const MarkdownStyle &newSty
1131
1167
  changed = YES;
1132
1168
  }
1133
1169
 
1170
+ if (newStyle.math.glyphOverflow != oldStyle.math.glyphOverflow) {
1171
+ [config setMathGlyphOverflow:newStyle.math.glyphOverflow];
1172
+ changed = YES;
1173
+ }
1174
+
1134
1175
  if (newStyle.math.marginTop != oldStyle.math.marginTop) {
1135
1176
  [config setMathMarginTop:newStyle.math.marginTop];
1136
1177
  changed = YES;
@@ -1179,6 +1220,11 @@ BOOL applyMarkdownStyleToConfig(StyleConfig *config, const MarkdownStyle &newSty
1179
1220
  changed = YES;
1180
1221
  }
1181
1222
 
1223
+ if (newStyle.inlineMath.glyphOverflow != oldStyle.inlineMath.glyphOverflow) {
1224
+ [config setInlineMathGlyphOverflow:newStyle.inlineMath.glyphOverflow];
1225
+ changed = YES;
1226
+ }
1227
+
1182
1228
  // ── Spoiler ─────────────────────────────────────────────────────────────
1183
1229
 
1184
1230
  if (newStyle.spoiler.color != oldStyle.spoiler.color) {
@@ -2,6 +2,7 @@
2
2
  #import "BlockquoteBorder.h"
3
3
  #import "CodeBackground.h"
4
4
  #import "CodeBlockBackground.h"
5
+ #import "ENRMLinkChip.h"
5
6
  #import "ListMarkerDrawer.h"
6
7
  #import "RuntimeKeys.h"
7
8
  #import "StyleConfig.h"
@@ -31,6 +32,8 @@
31
32
  // We fetch the objects into local variables FIRST to ensure they don't
32
33
  // disappear mid-method if setConfig: is called on another thread.
33
34
 
35
+ ENRMDrawLinkChipsForGlyphRange(self, textContainer, glyphsToShow, origin);
36
+
34
37
  CodeBackground *codeBg = [self getCodeBackgroundWithConfig:config];
35
38
  [codeBg drawBackgroundsForGlyphRange:glyphsToShow layoutManager:self textContainer:textContainer atPoint:origin];
36
39
 
@@ -1,4 +1,5 @@
1
1
  #pragma once
2
+ #import "ENRMBlockMenu.h"
2
3
  #import "ENRMUIKit.h"
3
4
  #import "StyleConfig.h"
4
5
 
@@ -33,12 +34,25 @@ typedef void (^ENRMCodeBlockCopyBlock)(NSString *code, NSString *language);
33
34
 
34
35
  /// Suppresses the long-press copy menu on this block. Mirrors the
35
36
  /// `contextMenuHidden` prop; the header copy button is a visible control, not a
36
- /// context menu, and stays.
37
+ /// context menu, and stays (hide it with `menuOptions.copyButtonHidden`).
37
38
  @property (nonatomic, assign) BOOL contextMenuHidden;
38
39
 
40
+ /// Copy / Copy as Markdown visibility, Copy format and the header copy button
41
+ /// from `selectionMenuConfig`. `copyHidden` also drops the VoiceOver copy action;
42
+ /// the header button and VoiceOver action always copy the raw code.
43
+ @property (nonatomic, assign) ENRMBlockMenuOptions menuOptions;
44
+
45
+ /// Set by the host; receives the Copy item's content when
46
+ /// `menuOptions.interceptCopy` is set.
47
+ @property (nonatomic, copy, nullable) ENRMBlockCopyRequestBlock onCopyRequest;
48
+ /// Called instead of the menu on long press while `contextMenuHidden` is on, so
49
+ /// the owner can report the block (`onSelectionChange`) and show its own UI.
50
+ @property (nonatomic, copy, nullable) ENRMBlockCopyRequestBlock onMenuSuppressed;
51
+
39
52
  // Fired when the code is copied (header button, context-menu Copy, or the
40
53
  // VoiceOver copy action); set by the host to bridge up to the JS onCopyPress
41
- // event. Not fired for "Copy as Markdown".
54
+ // event. Not fired for "Copy as Markdown", nor for the context-menu Copy when
55
+ // `menuOptions.copyWritesMarkdown` is set.
42
56
  @property (nonatomic, copy, nullable) ENRMCodeBlockCopyBlock onCopyPress;
43
57
 
44
58
  @end
@@ -175,6 +175,13 @@ static BOOL ENRMColorIsDark(RCTUIColor *color)
175
175
  _copyButton.accessibilityLabel = _copyLabel;
176
176
  }
177
177
 
178
+ - (void)setMenuOptions:(ENRMBlockMenuOptions)menuOptions
179
+ {
180
+ _menuOptions = menuOptions;
181
+ // Hiding the button leaves the header (and its height) untouched.
182
+ _copyButton.hidden = menuOptions.copyButtonHidden;
183
+ }
184
+
178
185
  - (void)setPending:(BOOL)pending
179
186
  {
180
187
  if (_pending == pending) {
@@ -488,26 +495,22 @@ static BOOL ENRMColorIsDark(RCTUIColor *color)
488
495
  {
489
496
  // Returning nil is the UIKit-sanctioned way to suppress a context menu.
490
497
  if (_pending || self.contextMenuHidden) {
498
+ if (!_pending && self.onMenuSuppressed) {
499
+ self.onMenuSuppressed([self fencedMarkdown], _cachedCode ?: @"");
500
+ }
491
501
  return nil;
492
502
  }
493
- return [UIContextMenuConfiguration
494
- configurationWithIdentifier:nil
495
- previewProvider:nil
496
- actionProvider:^UIMenu *(NSArray<UIMenuElement *> *suggestedActions) {
497
- UIAction *copyCode =
498
- [UIAction actionWithTitle:self.copyLabel
499
- image:[RCTUIImage systemImageNamed:@"doc.on.doc"]
500
- identifier:nil
501
- handler:^(__kindof UIAction *action) { [self copyCodeToPasteboard]; }];
502
-
503
- UIAction *copyMarkdown =
504
- [UIAction actionWithTitle:self.copyAsMarkdownLabel
505
- image:[RCTUIImage systemImageNamed:@"doc.text"]
506
- identifier:nil
507
- handler:^(__kindof UIAction *action) { [self copyMarkdownToPasteboard]; }];
508
-
509
- return [UIMenu menuWithTitle:@"" children:@[ copyCode, copyMarkdown ]];
510
- }];
503
+ __weak __typeof(self) weakSelf = self;
504
+ return ENRMBlockContextMenuConfiguration(
505
+ self.menuOptions, self.copyLabel, self.copyAsMarkdownLabel, ^{ [weakSelf copyCodeToPasteboard]; },
506
+ ^{ [weakSelf copyMarkdownToPasteboard]; }, ^{ [weakSelf requestCopy]; });
507
+ }
508
+
509
+ - (void)requestCopy
510
+ {
511
+ if (self.onCopyRequest) {
512
+ self.onCopyRequest([self fencedMarkdown], _cachedCode ?: @"");
513
+ }
511
514
  }
512
515
  #endif
513
516
 
@@ -546,7 +549,7 @@ static BOOL ENRMColorIsDark(RCTUIColor *color)
546
549
  // button subview from VoiceOver; expose the copy action explicitly instead.
547
550
  - (NSArray<UIAccessibilityCustomAction *> *)accessibilityCustomActions
548
551
  {
549
- if (_pending || self.copyLabel.length == 0) {
552
+ if (_pending || self.menuOptions.copyHidden || self.copyLabel.length == 0) {
550
553
  return @[];
551
554
  }
552
555
  UIAccessibilityCustomAction *copyAction =
@@ -1,4 +1,5 @@
1
1
  #pragma once
2
+ #import "ENRMBlockMenu.h"
2
3
  #import "ENRMUIKit.h"
3
4
  #import "StyleConfig.h"
4
5
 
@@ -23,6 +24,9 @@ NS_ASSUME_NONNULL_BEGIN
23
24
  + (CGFloat)measureHeightForLatex:(NSString *)latex config:(StyleConfig *)config maxWidth:(CGFloat)maxWidth;
24
25
 
25
26
  @property (nonatomic, strong) StyleConfig *config;
27
+
28
+ /// Washes the formula's own frame in the highlight background (a `==$$…$$==` block).
29
+ @property (nonatomic, assign) BOOL highlighted;
26
30
  @property (nonatomic, copy, readonly) NSString *cachedLatex;
27
31
  @property (nonatomic, strong, nullable) ENRMAccessibilityLabels *accessibilityLabels;
28
32
 
@@ -35,6 +39,16 @@ NS_ASSUME_NONNULL_BEGIN
35
39
  /// `contextMenuHidden` prop; selection and link handling are unaffected.
36
40
  @property (nonatomic, assign) BOOL contextMenuHidden;
37
41
 
42
+ /// Copy / Copy as Markdown visibility and Copy format from `selectionMenuConfig`.
43
+ @property (nonatomic, assign) ENRMBlockMenuOptions menuOptions;
44
+
45
+ /// Set by the host; receives the Copy item's content when
46
+ /// `menuOptions.interceptCopy` is set.
47
+ @property (nonatomic, copy, nullable) ENRMBlockCopyRequestBlock onCopyRequest;
48
+ /// Called instead of the menu on long press while `contextMenuHidden` is on, so
49
+ /// the owner can report the block (`onSelectionChange`) and show its own UI.
50
+ @property (nonatomic, copy, nullable) ENRMBlockCopyRequestBlock onMenuSuppressed;
51
+
38
52
  @end
39
53
 
40
54
  NS_ASSUME_NONNULL_END
@@ -94,6 +94,12 @@
94
94
  return self;
95
95
  }
96
96
 
97
+ - (void)setHighlighted:(BOOL)highlighted
98
+ {
99
+ _highlighted = highlighted;
100
+ _mathView.backgroundColor = highlighted ? self.config.highlightBackgroundColor : [RCTUIColor clearColor];
101
+ }
102
+
97
103
  - (void)applyLatex:(NSString *)latex
98
104
  {
99
105
  _cachedLatex = [latex copy];
@@ -104,7 +110,8 @@
104
110
  displayMode:YES
105
111
  fontSize:config.mathFontSize
106
112
  color:config.mathColor
107
- bold:ENRMMathFontWeightIsBold(config.mathFontWeight)];
113
+ bold:ENRMMathFontWeightIsBold(config.mathFontWeight)
114
+ glyphOverflow:config.mathGlyphOverflow];
108
115
  _mathView.renderResult = result;
109
116
  _mathView.fallbackSource = result ? nil : ENRMMathFallbackString(latex, @"$$", config.mathFontSize, config.mathColor);
110
117
 
@@ -128,27 +135,22 @@
128
135
  {
129
136
  // Returning nil is the UIKit-sanctioned way to suppress a context menu.
130
137
  if (self.contextMenuHidden) {
138
+ if (self.onMenuSuppressed) {
139
+ self.onMenuSuppressed([NSString stringWithFormat:@"$$\n%@\n$$", _cachedLatex ?: @""], _cachedLatex ?: @"");
140
+ }
131
141
  return nil;
132
142
  }
143
+ __weak __typeof(self) weakSelf = self;
144
+ return ENRMBlockContextMenuConfiguration(
145
+ self.menuOptions, self.copyLabel, self.copyAsMarkdownLabel, ^{ [weakSelf copyLatexToPasteboard]; },
146
+ ^{ [weakSelf copyMarkdownToPasteboard]; }, ^{ [weakSelf requestCopy]; });
147
+ }
133
148
 
134
- return [UIContextMenuConfiguration
135
- configurationWithIdentifier:nil
136
- previewProvider:nil
137
- actionProvider:^UIMenu *(NSArray<UIMenuElement *> *suggestedActions) {
138
- UIAction *copyPlainText =
139
- [UIAction actionWithTitle:self.copyLabel
140
- image:[RCTUIImage systemImageNamed:@"doc.on.doc"]
141
- identifier:nil
142
- handler:^(__kindof UIAction *action) { [self copyLatexToPasteboard]; }];
143
-
144
- UIAction *copyMarkdown =
145
- [UIAction actionWithTitle:self.copyAsMarkdownLabel
146
- image:[RCTUIImage systemImageNamed:@"doc.text"]
147
- identifier:nil
148
- handler:^(__kindof UIAction *action) { [self copyMarkdownToPasteboard]; }];
149
-
150
- return [UIMenu menuWithTitle:@"" children:@[ copyPlainText, copyMarkdown ]];
151
- }];
149
+ - (void)requestCopy
150
+ {
151
+ if (self.onCopyRequest) {
152
+ self.onCopyRequest([NSString stringWithFormat:@"$$\n%@\n$$", _cachedLatex ?: @""], _cachedLatex ?: @"");
153
+ }
152
154
  }
153
155
  #endif
154
156
 
@@ -204,7 +206,8 @@
204
206
  displayMode:YES
205
207
  fontSize:config.mathFontSize
206
208
  color:config.mathColor
207
- bold:ENRMMathFontWeightIsBold(config.mathFontWeight)];
209
+ bold:ENRMMathFontWeightIsBold(config.mathFontWeight)
210
+ glyphOverflow:config.mathGlyphOverflow];
208
211
  if (result) {
209
212
  return ceil(result.totalHeight) + padding * 2;
210
213
  }
@@ -1,4 +1,5 @@
1
1
  #pragma once
2
+ #import "ENRMBlockMenu.h"
2
3
  #import "ENRMUIKit.h"
3
4
  #import "ParagraphStyleUtils.h"
4
5
  #import "StyleConfig.h"
@@ -56,7 +57,20 @@ typedef void (^TableLinkPressBlock)(NSString *url);
56
57
  /// `contextMenuHidden` prop; selection and link handling are unaffected.
57
58
  @property (nonatomic, assign) BOOL contextMenuHidden;
58
59
 
60
+ /// Copy / Copy as Markdown visibility and Copy format from `selectionMenuConfig`.
61
+ @property (nonatomic, assign) ENRMBlockMenuOptions menuOptions;
62
+
63
+ /// Set by the host; receives the Copy item's content when
64
+ /// `menuOptions.interceptCopy` is set.
65
+ @property (nonatomic, copy, nullable) ENRMBlockCopyRequestBlock onCopyRequest;
66
+ /// Called instead of the menu on long press while `contextMenuHidden` is on, so
67
+ /// the owner can report the block (`onSelectionChange`) and show its own UI.
68
+ @property (nonatomic, copy, nullable) ENRMBlockCopyRequestBlock onMenuSuppressed;
69
+
59
70
  @property (nonatomic, readonly) NSUInteger rowCount;
71
+ /// Number of links across all cells. Tables are not reported by `onLinkLayout`,
72
+ /// but their links still count so later link indices stay in document order.
73
+ @property (nonatomic, readonly) NSInteger linkCount;
60
74
 
61
75
  - (void)animateNewRowsFromPreviousCount:(NSUInteger)previousRowCount duration:(NSTimeInterval)duration;
62
76
 
@@ -1,6 +1,7 @@
1
1
  #import "TableContainerView.h"
2
2
  #import "AttributedRenderer.h"
3
3
  #import "ENRMAccessibilityLabels.h"
4
+ #import "ENRMLinkChip.h"
4
5
  #import "HTMLGenerator.h"
5
6
  #import "LinkTapUtils.h"
6
7
  #import "MarkdownASTNode.h"
@@ -90,6 +91,8 @@ static NSMutableAttributedString *ENRMTableRenderCellNode(MarkdownASTNode *cellN
90
91
  NSMutableAttributedString *attributedText = [renderer renderRoot:temporaryRoot context:context];
91
92
 
92
93
  [context applyLinkAttributesToString:attributedText];
94
+ // Cells draw with -drawWithRect:, which bypasses the layout manager that paints link chips.
95
+ ENRMApplyLinkChipBackgroundsAsTextBackground(attributedText);
93
96
 
94
97
  ENRMApplyWritingDirectionMode(attributedText, writingDirectionMode, resolvedLayoutDirection);
95
98
 
@@ -302,6 +305,24 @@ static void ENRMTableComputeLayout(NSArray<NSArray<TableCellData *> *> *rows, NS
302
305
  return _rows.count;
303
306
  }
304
307
 
308
+ - (NSInteger)linkCount
309
+ {
310
+ __block NSInteger count = 0;
311
+ for (NSArray<TableCellData *> *row in _rows) {
312
+ for (TableCellData *cell in row) {
313
+ // LinkRenderer attaches one ENRMLinkChip instance per link.
314
+ [cell.attributedText enumerateAttribute:ENRMLinkChipAttributeName
315
+ inRange:NSMakeRange(0, cell.attributedText.length)
316
+ options:0
317
+ usingBlock:^(id chip, NSRange range, BOOL *stop) {
318
+ if (chip)
319
+ count++;
320
+ }];
321
+ }
322
+ }
323
+ return count;
324
+ }
325
+
305
326
  #if !TARGET_OS_OSX
306
327
  - (void)animateNewRowsFromPreviousCount:(NSUInteger)previousRowCount duration:(NSTimeInterval)duration
307
328
  {
@@ -465,27 +486,22 @@ static void ENRMTableComputeLayout(NSArray<NSArray<TableCellData *> *> *rows, NS
465
486
  {
466
487
  // Returning nil is the UIKit-sanctioned way to suppress a context menu.
467
488
  if (self.contextMenuHidden) {
489
+ if (self.onMenuSuppressed) {
490
+ self.onMenuSuppressed(_cachedMarkdown ?: @"", [self buildPlainTextFromRows] ?: @"");
491
+ }
468
492
  return nil;
469
493
  }
494
+ __weak __typeof(self) weakSelf = self;
495
+ return ENRMBlockContextMenuConfiguration(
496
+ self.menuOptions, self.copyLabel, self.copyAsMarkdownLabel, ^{ [weakSelf copyTableToPasteboard]; },
497
+ ^{ [weakSelf copyMarkdownToPasteboard]; }, ^{ [weakSelf requestCopy]; });
498
+ }
470
499
 
471
- return [UIContextMenuConfiguration
472
- configurationWithIdentifier:nil
473
- previewProvider:nil
474
- actionProvider:^UIMenu *(NSArray<UIMenuElement *> *suggestedActions) {
475
- UIAction *copyMarkdown =
476
- [UIAction actionWithTitle:self.copyAsMarkdownLabel
477
- image:[RCTUIImage systemImageNamed:@"doc.text"]
478
- identifier:nil
479
- handler:^(__kindof UIAction *action) { [self copyMarkdownToPasteboard]; }];
480
-
481
- UIAction *copyPlainText =
482
- [UIAction actionWithTitle:self.copyLabel
483
- image:[RCTUIImage systemImageNamed:@"doc.on.doc"]
484
- identifier:nil
485
- handler:^(__kindof UIAction *action) { [self copyTableToPasteboard]; }];
486
-
487
- return [UIMenu menuWithTitle:@"" children:@[ copyPlainText, copyMarkdown ]];
488
- }];
500
+ - (void)requestCopy
501
+ {
502
+ if (self.onCopyRequest) {
503
+ self.onCopyRequest(_cachedMarkdown ?: @"", [self buildPlainTextFromRows] ?: @"");
504
+ }
489
505
  }
490
506
  #endif // !TARGET_OS_OSX
491
507