react-native-enriched-markdown-scaffold 0.7.4-scaffold.7 → 0.7.4-scaffold.9

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 (88) hide show
  1. package/android/build.gradle +5 -0
  2. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextInputManagerDelegate.java +3 -0
  3. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextInputManagerInterface.java +1 -0
  4. package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.cpp +5 -0
  5. package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.h +37 -0
  6. package/android/src/main/java/com/swmansion/enriched/markdown/input/EnrichedMarkdownTextInputManager.kt +8 -0
  7. package/android/src/main/java/com/swmansion/enriched/markdown/input/EnrichedMarkdownTextInputView.kt +13 -1
  8. package/android/src/main/java/com/swmansion/enriched/markdown/input/formatting/BlockSyntaxSentinel.kt +69 -0
  9. package/android/src/main/java/com/swmansion/enriched/markdown/input/formatting/InputParser.kt +71 -12
  10. package/android/src/main/java/com/swmansion/enriched/markdown/input/layout/InputMeasurementStore.kt +4 -1
  11. package/android/src/main/java/com/swmansion/enriched/markdown/input/model/MathChipStyle.kt +3 -0
  12. package/android/src/main/java/com/swmansion/enriched/markdown/styles/InlineMathStyle.kt +3 -1
  13. package/android/src/main/java/com/swmansion/enriched/markdown/styles/MathFontWeight.kt +25 -0
  14. package/android/src/main/java/com/swmansion/enriched/markdown/styles/MathStyle.kt +12 -1
  15. package/android/src/main/java/com/swmansion/enriched/markdown/utils/input/MarkdownStyleParser.kt +10 -0
  16. package/android/src/math/java/com/swmansion/enriched/markdown/renderer/MathInlineRenderer.kt +1 -0
  17. package/android/src/math/java/com/swmansion/enriched/markdown/spans/MathChipSpan.kt +1 -1
  18. package/android/src/math/java/com/swmansion/enriched/markdown/spans/MathInlineSpan.kt +2 -2
  19. package/android/src/math/java/com/swmansion/enriched/markdown/spans/MathTypeface.kt +30 -0
  20. package/android/src/math/java/com/swmansion/enriched/markdown/views/MathContainerView.kt +3 -1
  21. package/docs/API_REFERENCE.md +9 -0
  22. package/docs/INPUT.md +48 -0
  23. package/docs/LATEX_MATH.md +49 -0
  24. package/docs/STYLES.md +2 -0
  25. package/ios/attachments/ENRMMathInlineAttachment+macOS.m +5 -1
  26. package/ios/attachments/ENRMMathInlineAttachment.h +3 -0
  27. package/ios/attachments/ENRMMathInlineAttachment.m +2 -1
  28. package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.cpp +5 -0
  29. package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.h +37 -0
  30. package/ios/input/ENRMBlockSyntaxSentinel.h +25 -0
  31. package/ios/input/ENRMBlockSyntaxSentinel.mm +80 -0
  32. package/ios/input/ENRMInputFormatter.h +4 -0
  33. package/ios/input/ENRMInputFormatter.mm +2 -0
  34. package/ios/input/ENRMInputParser.h +5 -0
  35. package/ios/input/ENRMInputParser.mm +79 -6
  36. package/ios/input/EnrichedMarkdownTextInput.mm +19 -2
  37. package/ios/input/InputStylePropsUtils.h +13 -0
  38. package/ios/math/ENRMRaTeXBridge.swift +52 -3
  39. package/ios/renderer/ENRMMathInlineRenderer.m +2 -0
  40. package/ios/styles/StyleConfig.h +4 -0
  41. package/ios/styles/StyleConfig.mm +24 -0
  42. package/ios/utils/ENRMMathFontWeight.h +18 -0
  43. package/ios/utils/StylePropsUtils.h +16 -0
  44. package/ios/views/ENRMMathContainerView.m +3 -1
  45. package/lib/module/EnrichedMarkdownNativeComponent.ts +2 -0
  46. package/lib/module/EnrichedMarkdownTextInput.js +2 -0
  47. package/lib/module/EnrichedMarkdownTextInput.js.map +1 -1
  48. package/lib/module/EnrichedMarkdownTextInputNativeComponent.ts +12 -0
  49. package/lib/module/EnrichedMarkdownTextNativeComponent.ts +2 -0
  50. package/lib/module/normalizeMarkdownStyle.js +4 -2
  51. package/lib/module/normalizeMarkdownStyle.js.map +1 -1
  52. package/lib/module/normalizeMarkdownStyle.web.js +4 -2
  53. package/lib/module/normalizeMarkdownStyle.web.js.map +1 -1
  54. package/lib/module/normalizeMarkdownTextInputStyle.js +7 -3
  55. package/lib/module/normalizeMarkdownTextInputStyle.js.map +1 -1
  56. package/lib/module/web/globalStyles.js +8 -1
  57. package/lib/module/web/globalStyles.js.map +1 -1
  58. package/lib/module/web/styles.js +3 -1
  59. package/lib/module/web/styles.js.map +1 -1
  60. package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts +2 -0
  61. package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts.map +1 -1
  62. package/lib/typescript/src/EnrichedMarkdownTextInput.d.ts +3 -1
  63. package/lib/typescript/src/EnrichedMarkdownTextInput.d.ts.map +1 -1
  64. package/lib/typescript/src/EnrichedMarkdownTextInputNativeComponent.d.ts +12 -0
  65. package/lib/typescript/src/EnrichedMarkdownTextInputNativeComponent.d.ts.map +1 -1
  66. package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts +2 -0
  67. package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts.map +1 -1
  68. package/lib/typescript/src/normalizeMarkdownStyle.d.ts.map +1 -1
  69. package/lib/typescript/src/normalizeMarkdownStyle.web.d.ts.map +1 -1
  70. package/lib/typescript/src/normalizeMarkdownTextInputStyle.d.ts +1 -0
  71. package/lib/typescript/src/normalizeMarkdownTextInputStyle.d.ts.map +1 -1
  72. package/lib/typescript/src/types/MarkdownStyle.d.ts +24 -0
  73. package/lib/typescript/src/types/MarkdownStyle.d.ts.map +1 -1
  74. package/lib/typescript/src/types/MarkdownStyleInternal.d.ts +2 -0
  75. package/lib/typescript/src/types/MarkdownStyleInternal.d.ts.map +1 -1
  76. package/lib/typescript/src/web/styles.d.ts.map +1 -1
  77. package/package.json +1 -1
  78. package/src/EnrichedMarkdownNativeComponent.ts +2 -0
  79. package/src/EnrichedMarkdownTextInput.tsx +4 -0
  80. package/src/EnrichedMarkdownTextInputNativeComponent.ts +12 -0
  81. package/src/EnrichedMarkdownTextNativeComponent.ts +2 -0
  82. package/src/normalizeMarkdownStyle.ts +6 -1
  83. package/src/normalizeMarkdownStyle.web.ts +6 -1
  84. package/src/normalizeMarkdownTextInputStyle.ts +5 -0
  85. package/src/types/MarkdownStyle.ts +24 -0
  86. package/src/types/MarkdownStyleInternal.ts +2 -0
  87. package/src/web/globalStyles.ts +7 -0
  88. package/src/web/styles.ts +5 -1
@@ -0,0 +1,30 @@
1
+ package com.swmansion.enriched.markdown.spans
2
+
3
+ import android.graphics.Typeface
4
+ import com.swmansion.enriched.markdown.styles.MathFontWeight
5
+ import io.ratex.RaTeXFontLoader
6
+
7
+ /**
8
+ * Typeface supplier for [io.ratex.RaTeXRenderer]. RaTeX resolves every glyph to
9
+ * a KaTeX font id and asks us for the face to draw it with.
10
+ *
11
+ * Takes the raw `fontWeight` string the style model carries — the same shape
12
+ * every other `fontWeight` prop keeps — and is the single place on Android that
13
+ * narrows it to a weight we can draw. Consumers pass the style through; nothing
14
+ * upstream has to know that only two weights are reachable today.
15
+ *
16
+ * Bold is SYNTHETIC: asking for [Typeface.BOLD] on a single-weight asset makes
17
+ * the platform embolden it, which preserves the advances RaTeX already laid the
18
+ * glyphs out with. Substituting the bundled KaTeX bold faces instead would not
19
+ * — their advances run up to 15% wider than the regular ones the layout
20
+ * reserved, so glyphs would collide. iOS reaches the same result by stroking
21
+ * the glyph outline; see ENRMRaTeXBridge.
22
+ */
23
+ internal fun ratexTypefaceLoader(fontWeight: String): (String) -> Typeface? =
24
+ when (MathFontWeight.fromString(fontWeight)) {
25
+ MathFontWeight.NORMAL -> { fontId -> RaTeXFontLoader.getTypeface(fontId) }
26
+
27
+ MathFontWeight.BOLD -> { fontId ->
28
+ RaTeXFontLoader.getTypeface(fontId)?.let { Typeface.create(it, Typeface.BOLD) }
29
+ }
30
+ }
@@ -15,6 +15,7 @@ import com.swmansion.enriched.markdown.accessibility.AccessibilityLabels
15
15
  import com.swmansion.enriched.markdown.spans.MathMeasureHelper
16
16
  import com.swmansion.enriched.markdown.spans.MathMeasureRequest
17
17
  import com.swmansion.enriched.markdown.spans.MathRenderMode
18
+ import com.swmansion.enriched.markdown.spans.ratexTypefaceLoader
18
19
  import com.swmansion.enriched.markdown.styles.MathStyle
19
20
  import com.swmansion.enriched.markdown.styles.StyleConfig
20
21
  import io.ratex.RaTeXEngine
@@ -100,7 +101,8 @@ class MathContainerView(
100
101
  cachedLatex = latex
101
102
  try {
102
103
  val displayList = RaTeXEngine.parseBlocking(latex, displayMode = true, color = mathStyle.color)
103
- mathView.renderer = RaTeXRenderer(displayList, mathStyle.fontSize) { RaTeXFontLoader.getTypeface(it) }
104
+ mathView.renderer =
105
+ RaTeXRenderer(displayList, mathStyle.fontSize, ratexTypefaceLoader(mathStyle.fontWeight))
104
106
  } catch (e: Exception) {
105
107
  Log.e(TAG, "Failed to render LaTeX", e)
106
108
  mathView.renderer = null
@@ -515,6 +515,15 @@ Whether the input is scrollable when content exceeds the visible area.
515
515
  | --------- | ------------- | -------- |
516
516
  | `boolean` | `true` | Both |
517
517
 
518
+ ### `blockSyntax`
519
+
520
+ Whether block-level Markdown syntax is interpreted. See
521
+ [Preserving block syntax](./INPUT.md#preserving-block-syntax).
522
+
523
+ | Type | Default Value | Platform |
524
+ | --------- | ------------- | -------- |
525
+ | `boolean` | `true` | Both |
526
+
518
527
  ### `autoCapitalize`
519
528
 
520
529
  Auto-capitalization behavior.
package/docs/INPUT.md CHANGED
@@ -122,6 +122,50 @@ The callback fires only for newly detected links — not for links that were alr
122
122
 
123
123
  When a manual link is applied (via `setLink` or `insertLink`) over an auto-detected link, the auto-detected link is replaced by the manual one. Auto-link detection skips ranges that already contain a manual link.
124
124
 
125
+ ## Preserving block syntax
126
+
127
+ By default the input interprets block-level Markdown: a line starting with `1) `, `- `,
128
+ `# ` or `> ` is consumed as list, heading or quote *structure*, and the marker itself is
129
+ not part of the text. The editor has no block styles to render that structure with and
130
+ the serializer has no way to write the marker back, so the marker is lost on save. Two
131
+ adjacent list items can end up with their formulas touching — `1) $a+b$` and `2) $c+d$`
132
+ save as `$a+b$$c+d$`, where the `$$` now reads as display math.
133
+
134
+ Set `blockSyntax={false}` when the text must survive the round trip unchanged:
135
+
136
+ ```tsx
137
+ <EnrichedMarkdownTextInput
138
+ blockSyntax={false}
139
+ defaultValue={markdown}
140
+ onChangeMarkdown={setMarkdown}
141
+ />
142
+ ```
143
+
144
+ In this mode the parser never sees block structure, so markers stay in the text verbatim
145
+ and `onChangeMarkdown` returns what was loaded, byte for byte. Inline syntax is unaffected:
146
+ `**bold**`, `*italic*`, `~~strike~~`, `||spoiler||`, links and `$math$` all still parse and
147
+ style as usual.
148
+
149
+ What changes:
150
+
151
+ - **Typing `3) ` no longer starts a list**, and `# ` no longer makes a heading. Nothing
152
+ block-level is interpreted while typing either — that is the point of the mode.
153
+ - The text is displayed with its markers showing, so an editor with `blockSyntax={false}`
154
+ and a `EnrichedMarkdownText` rendering the same source look different, even though the
155
+ stored string is identical.
156
+ - `\r\n` and `\r` are normalized to `\n`, and `U+000B` (vertical tab) is stripped from the
157
+ input. `U+000B` is used internally to hide line structure from the Markdown parser, so it
158
+ cannot be carried through as content.
159
+
160
+ Three inline constructs are still lossy in this mode, exactly as they are with
161
+ `blockSyntax={true}` — they are not regressions introduced by the flag:
162
+
163
+ | Input | Saved as | Why |
164
+ | --- | --- | --- |
165
+ | `` gõ `x` vào `` | `gõ x vào` | The editor has no inline code style, so the backticks have nothing to round-trip through |
166
+ | `Giá 5\$` | `Giá 5$` | The serializer does not re-escape `\$`, which can leave an unpaired `$` |
167
+ | `A &amp;amp; B` | `A B` | HTML entity nodes are dropped. A raw `&` is safe |
168
+
125
169
  ## Caret Position Tracking
126
170
 
127
171
  `EnrichedMarkdownTextInput` can report the caret's pixel position relative to the input, which is useful when the input is embedded in a scrollable container with `scrollEnabled={false}` and you need to keep the caret visible.
@@ -231,3 +275,7 @@ Available style properties:
231
275
  - `link.underline` — whether links are underlined (defaults to `true`).
232
276
  - `spoiler.color` — text color for spoiler text.
233
277
  - `spoiler.backgroundColor` — background color for spoiler text.
278
+ - `math.fontWeight` — `'bold'` | `'normal'` (default `'normal'`); typesets inline formula chips
279
+ (`$...$`) at bold weight. See [LATEX_MATH.md](./LATEX_MATH.md#bold-formulas).
280
+ - `mathBlock.fontWeight` — same for block formula chips (`$$...$$`); inherits from
281
+ `math.fontWeight` when unset.
@@ -47,6 +47,50 @@ what pushes those lines apart. It affects only lines that actually contain inlin
47
47
  the line height they had. Set it to `0` to get the old flush behaviour back. Block math (`$$...$$`) has its own
48
48
  `math.padding` instead.
49
49
 
50
+ ### Bold formulas
51
+
52
+ `math.fontWeight` / `inlineMath.fontWeight` (`'normal'` | `'bold'`, default `'normal'`) typeset a
53
+ formula at bold weight. Set it wherever the surrounding text is bold so the formula follows it.
54
+
55
+ The embolden is **synthetic on every platform** — no real bold face is ever used.
56
+
57
+ On **iOS and Android** it is a stroke on the glyph outline and the platform's fake-bold
58
+ respectively, rather than a switch to the bundled KaTeX bold faces. That is deliberate. The native
59
+ engine has no weight parameter, and by the time a style applies, glyph positions are already laid
60
+ out: the bold faces' advances run up to 15% wider than the regular ones the layout reserved, so
61
+ swapping them in would make glyphs collide. Stroking and fake-bold both preserve every advance.
62
+
63
+ Two consequences worth knowing:
64
+
65
+ - Fraction bars and rules keep their own thickness, so they do not thicken with the glyphs.
66
+ - On iOS the stroke width also applies to the handful of decorations the engine strokes itself
67
+ (`\cancel`, `\textcircled`, `\corresponds`, `\imageof`). Prefer turning bold on per surface
68
+ rather than globally.
69
+
70
+ On **web** the prop is a plain CSS declaration on the KaTeX output — but the library renders in
71
+ [MathML output mode](#web) and loads no KaTeX stylesheet or fonts, so `font-weight` is resolved by
72
+ the browser's own math font (STIX Two Math, Latin Modern Math, Cambria Math). Most of those ship no
73
+ bold face, so the browser synthesizes one there too. Treat web as synthetic as well, not as a
74
+ reference for how heavy bold "should" look.
75
+
76
+ `EnrichedMarkdownTextInput` honours the same prop for the formula chips typed into the editor, under
77
+ its own style keys — `math.fontWeight` for inline chips (`$...$`) and `mathBlock.fontWeight` for
78
+ block chips (`$$...$$`). `mathBlock` inherits the weight from `math` when it does not set one of its
79
+ own, the way it already inherits `color` and the border props:
80
+
81
+ ```tsx
82
+ <EnrichedMarkdownTextInput
83
+ markdownStyle={{
84
+ math: { fontWeight: 'bold' }, // inline chips bold…
85
+ mathBlock: { fontWeight: 'normal' }, // …block chips opt back out
86
+ }}
87
+ />
88
+ ```
89
+
90
+ The caveats above apply unchanged — the embolden is the same synthetic one, and the chip keeps its
91
+ measured width because fake-bold and stroking both preserve the glyph advances. Editor chips are
92
+ iOS + Android only; there is no web or macOS chip surface.
93
+
50
94
  > [!IMPORTANT]
51
95
  > LaTeX commands use backslashes (e.g. `\frac`, `\alpha`). In regular JS strings and template literals, backslashes are escape characters. Use `String.raw` or double backslashes (`\\frac`) to preserve them. Block math (`$$...$$`) must be on its own line to render as a display element.
52
96
 
@@ -66,6 +110,11 @@ yarn add katex
66
110
 
67
111
  KaTeX is loaded lazily the first time a LaTeX node is encountered, so it has no impact on pages that do not render math. No stylesheet or `<link>` tag is needed.
68
112
 
113
+ If you load `katex/dist/katex.min.css` anyway — some setups do — its `.katex` rule opens with the
114
+ `font` shorthand, which resets `font-weight` and would drop [`fontWeight`](#bold-formulas) on the
115
+ way down to the formula. The library injects `.katex { font-weight: inherit; }` to keep the prop
116
+ working in that case; nothing is required of you.
117
+
69
118
  > [!NOTE]
70
119
  > MathML is supported natively in Chrome 109+, Firefox, and Safari. Older browsers will display the raw LaTeX source as a text fallback.
71
120
 
package/docs/STYLES.md CHANGED
@@ -179,10 +179,12 @@ The library provides sensible default styles for all Markdown elements out of th
179
179
  padding: 12,
180
180
  marginBottom: 16,
181
181
  textAlign: 'center',
182
+ fontWeight: 'normal',
182
183
  },
183
184
  inlineMath: {
184
185
  color: '#1F2937',
185
186
  paddingVertical: 4,
187
+ fontWeight: 'normal',
186
188
  },
187
189
  spoiler: {
188
190
  color: '#6B7280',
@@ -25,7 +25,11 @@
25
25
  - (void)renderForMacOS
26
26
  {
27
27
  RCTUIColor *color = self.mathTextColor ?: [RCTUIColor blackColor];
28
- ENRMRaTeXRenderResult *result = [ENRMRaTeXBridge parse:self.latex displayMode:NO fontSize:self.fontSize color:color];
28
+ ENRMRaTeXRenderResult *result = [ENRMRaTeXBridge parse:self.latex
29
+ displayMode:NO
30
+ fontSize:self.fontSize
31
+ color:color
32
+ bold:self.bold];
29
33
  if (!result)
30
34
  return;
31
35
 
@@ -9,6 +9,9 @@ NS_ASSUME_NONNULL_BEGIN
9
9
  @property (nonatomic, assign) CGFloat fontSize;
10
10
  @property (nonatomic, strong, nullable) RCTUIColor *mathTextColor;
11
11
 
12
+ /// Typeset the glyphs at bold weight (synthetic — see ENRMRaTeXBridge).
13
+ @property (nonatomic, assign) BOOL bold;
14
+
12
15
  /// YES if block math (`$$...$$`), NO for inline (`$...$`).
13
16
  @property (nonatomic, assign) BOOL displayMode;
14
17
 
@@ -21,7 +21,8 @@
21
21
  ENRMRaTeXRenderResult *result = [ENRMRaTeXBridge parse:self.latex
22
22
  displayMode:self.displayMode
23
23
  fontSize:self.fontSize
24
- color:color];
24
+ color:color
25
+ bold:self.bold];
25
26
  if (!result)
26
27
  return;
27
28
 
@@ -144,6 +144,7 @@ EnrichedMarkdownTextInputProps::EnrichedMarkdownTextInputProps(
144
144
  editable(convertRawProp(context, rawProps, "editable", sourceProps.editable, {false})),
145
145
  autoFocus(convertRawProp(context, rawProps, "autoFocus", sourceProps.autoFocus, {false})),
146
146
  scrollEnabled(convertRawProp(context, rawProps, "scrollEnabled", sourceProps.scrollEnabled, {false})),
147
+ blockSyntax(convertRawProp(context, rawProps, "blockSyntax", sourceProps.blockSyntax, {false})),
147
148
  autoCapitalize(convertRawProp(context, rawProps, "autoCapitalize", sourceProps.autoCapitalize, {})),
148
149
  multiline(convertRawProp(context, rawProps, "multiline", sourceProps.multiline, {false})),
149
150
  cursorColor(convertRawProp(context, rawProps, "cursorColor", sourceProps.cursorColor, {})),
@@ -202,6 +203,10 @@ folly::dynamic EnrichedMarkdownTextInputProps::getDiffProps(
202
203
  result["scrollEnabled"] = scrollEnabled;
203
204
  }
204
205
 
206
+ if (blockSyntax != oldProps->blockSyntax) {
207
+ result["blockSyntax"] = blockSyntax;
208
+ }
209
+
205
210
  if (autoCapitalize != oldProps->autoCapitalize) {
206
211
  result["autoCapitalize"] = autoCapitalize;
207
212
  }
@@ -1534,6 +1534,7 @@ struct EnrichedMarkdownMarkdownStyleMathStruct {
1534
1534
  Float marginTop{0.0};
1535
1535
  Float marginBottom{0.0};
1536
1536
  std::string textAlign{};
1537
+ std::string fontWeight{};
1537
1538
 
1538
1539
 
1539
1540
  #ifdef RN_SERIALIZABLE_STATE
@@ -1548,6 +1549,7 @@ struct EnrichedMarkdownMarkdownStyleMathStruct {
1548
1549
  result["marginTop"] = marginTop;
1549
1550
  result["marginBottom"] = marginBottom;
1550
1551
  result["textAlign"] = textAlign;
1552
+ result["fontWeight"] = fontWeight;
1551
1553
  return result;
1552
1554
  }
1553
1555
  #endif
@@ -1584,6 +1586,10 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu
1584
1586
  if (tmp_textAlign != map.end()) {
1585
1587
  fromRawValue(context, tmp_textAlign->second, result.textAlign);
1586
1588
  }
1589
+ auto tmp_fontWeight = map.find("fontWeight");
1590
+ if (tmp_fontWeight != map.end()) {
1591
+ fromRawValue(context, tmp_fontWeight->second, result.fontWeight);
1592
+ }
1587
1593
  }
1588
1594
 
1589
1595
  static inline std::string toString(const EnrichedMarkdownMarkdownStyleMathStruct &value) {
@@ -1599,6 +1605,7 @@ static inline folly::dynamic toDynamic(const EnrichedMarkdownMarkdownStyleMathSt
1599
1605
  struct EnrichedMarkdownMarkdownStyleInlineMathStruct {
1600
1606
  SharedColor color{};
1601
1607
  Float paddingVertical{0.0};
1608
+ std::string fontWeight{};
1602
1609
 
1603
1610
 
1604
1611
  #ifdef RN_SERIALIZABLE_STATE
@@ -1608,6 +1615,7 @@ struct EnrichedMarkdownMarkdownStyleInlineMathStruct {
1608
1615
  folly::dynamic result = folly::dynamic::object();
1609
1616
  result["color"] = ::facebook::react::toDynamic(color);
1610
1617
  result["paddingVertical"] = paddingVertical;
1618
+ result["fontWeight"] = fontWeight;
1611
1619
  return result;
1612
1620
  }
1613
1621
  #endif
@@ -1624,6 +1632,10 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu
1624
1632
  if (tmp_paddingVertical != map.end()) {
1625
1633
  fromRawValue(context, tmp_paddingVertical->second, result.paddingVertical);
1626
1634
  }
1635
+ auto tmp_fontWeight = map.find("fontWeight");
1636
+ if (tmp_fontWeight != map.end()) {
1637
+ fromRawValue(context, tmp_fontWeight->second, result.fontWeight);
1638
+ }
1627
1639
  }
1628
1640
 
1629
1641
  static inline std::string toString(const EnrichedMarkdownMarkdownStyleInlineMathStruct &value) {
@@ -2810,6 +2822,7 @@ struct EnrichedMarkdownTextInputMarkdownStyleMathStruct {
2810
2822
  Float paddingVertical{0.0};
2811
2823
  SharedColor selectedBackgroundColor{};
2812
2824
  SharedColor selectedBorderColor{};
2825
+ std::string fontWeight{};
2813
2826
 
2814
2827
 
2815
2828
  #ifdef RN_SERIALIZABLE_STATE
@@ -2827,6 +2840,7 @@ struct EnrichedMarkdownTextInputMarkdownStyleMathStruct {
2827
2840
  result["paddingVertical"] = paddingVertical;
2828
2841
  result["selectedBackgroundColor"] = ::facebook::react::toDynamic(selectedBackgroundColor);
2829
2842
  result["selectedBorderColor"] = ::facebook::react::toDynamic(selectedBorderColor);
2843
+ result["fontWeight"] = fontWeight;
2830
2844
  return result;
2831
2845
  }
2832
2846
  #endif
@@ -2875,6 +2889,10 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu
2875
2889
  if (tmp_selectedBorderColor != map.end()) {
2876
2890
  fromRawValue(context, tmp_selectedBorderColor->second, result.selectedBorderColor);
2877
2891
  }
2892
+ auto tmp_fontWeight = map.find("fontWeight");
2893
+ if (tmp_fontWeight != map.end()) {
2894
+ fromRawValue(context, tmp_fontWeight->second, result.fontWeight);
2895
+ }
2878
2896
  }
2879
2897
 
2880
2898
  static inline std::string toString(const EnrichedMarkdownTextInputMarkdownStyleMathStruct &value) {
@@ -2898,6 +2916,7 @@ struct EnrichedMarkdownTextInputMarkdownStyleMathBlockStruct {
2898
2916
  Float paddingVertical{0.0};
2899
2917
  SharedColor selectedBackgroundColor{};
2900
2918
  SharedColor selectedBorderColor{};
2919
+ std::string fontWeight{};
2901
2920
  Float marginTop{0.0};
2902
2921
  Float marginBottom{0.0};
2903
2922
  std::string alignment{};
@@ -2918,6 +2937,7 @@ struct EnrichedMarkdownTextInputMarkdownStyleMathBlockStruct {
2918
2937
  result["paddingVertical"] = paddingVertical;
2919
2938
  result["selectedBackgroundColor"] = ::facebook::react::toDynamic(selectedBackgroundColor);
2920
2939
  result["selectedBorderColor"] = ::facebook::react::toDynamic(selectedBorderColor);
2940
+ result["fontWeight"] = fontWeight;
2921
2941
  result["marginTop"] = marginTop;
2922
2942
  result["marginBottom"] = marginBottom;
2923
2943
  result["alignment"] = alignment;
@@ -2969,6 +2989,10 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu
2969
2989
  if (tmp_selectedBorderColor != map.end()) {
2970
2990
  fromRawValue(context, tmp_selectedBorderColor->second, result.selectedBorderColor);
2971
2991
  }
2992
+ auto tmp_fontWeight = map.find("fontWeight");
2993
+ if (tmp_fontWeight != map.end()) {
2994
+ fromRawValue(context, tmp_fontWeight->second, result.fontWeight);
2995
+ }
2972
2996
  auto tmp_marginTop = map.find("marginTop");
2973
2997
  if (tmp_marginTop != map.end()) {
2974
2998
  fromRawValue(context, tmp_marginTop->second, result.marginTop);
@@ -3335,6 +3359,7 @@ class EnrichedMarkdownTextInputProps final : public ViewProps {
3335
3359
  bool editable{false};
3336
3360
  bool autoFocus{false};
3337
3361
  bool scrollEnabled{false};
3362
+ bool blockSyntax{false};
3338
3363
  std::string autoCapitalize{};
3339
3364
  bool multiline{false};
3340
3365
  SharedColor cursorColor{};
@@ -4878,6 +4903,7 @@ struct EnrichedMarkdownTextMarkdownStyleMathStruct {
4878
4903
  Float marginTop{0.0};
4879
4904
  Float marginBottom{0.0};
4880
4905
  std::string textAlign{};
4906
+ std::string fontWeight{};
4881
4907
 
4882
4908
 
4883
4909
  #ifdef RN_SERIALIZABLE_STATE
@@ -4892,6 +4918,7 @@ struct EnrichedMarkdownTextMarkdownStyleMathStruct {
4892
4918
  result["marginTop"] = marginTop;
4893
4919
  result["marginBottom"] = marginBottom;
4894
4920
  result["textAlign"] = textAlign;
4921
+ result["fontWeight"] = fontWeight;
4895
4922
  return result;
4896
4923
  }
4897
4924
  #endif
@@ -4928,6 +4955,10 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu
4928
4955
  if (tmp_textAlign != map.end()) {
4929
4956
  fromRawValue(context, tmp_textAlign->second, result.textAlign);
4930
4957
  }
4958
+ auto tmp_fontWeight = map.find("fontWeight");
4959
+ if (tmp_fontWeight != map.end()) {
4960
+ fromRawValue(context, tmp_fontWeight->second, result.fontWeight);
4961
+ }
4931
4962
  }
4932
4963
 
4933
4964
  static inline std::string toString(const EnrichedMarkdownTextMarkdownStyleMathStruct &value) {
@@ -4943,6 +4974,7 @@ static inline folly::dynamic toDynamic(const EnrichedMarkdownTextMarkdownStyleMa
4943
4974
  struct EnrichedMarkdownTextMarkdownStyleInlineMathStruct {
4944
4975
  SharedColor color{};
4945
4976
  Float paddingVertical{0.0};
4977
+ std::string fontWeight{};
4946
4978
 
4947
4979
 
4948
4980
  #ifdef RN_SERIALIZABLE_STATE
@@ -4952,6 +4984,7 @@ struct EnrichedMarkdownTextMarkdownStyleInlineMathStruct {
4952
4984
  folly::dynamic result = folly::dynamic::object();
4953
4985
  result["color"] = ::facebook::react::toDynamic(color);
4954
4986
  result["paddingVertical"] = paddingVertical;
4987
+ result["fontWeight"] = fontWeight;
4955
4988
  return result;
4956
4989
  }
4957
4990
  #endif
@@ -4968,6 +5001,10 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu
4968
5001
  if (tmp_paddingVertical != map.end()) {
4969
5002
  fromRawValue(context, tmp_paddingVertical->second, result.paddingVertical);
4970
5003
  }
5004
+ auto tmp_fontWeight = map.find("fontWeight");
5005
+ if (tmp_fontWeight != map.end()) {
5006
+ fromRawValue(context, tmp_fontWeight->second, result.fontWeight);
5007
+ }
4971
5008
  }
4972
5009
 
4973
5010
  static inline std::string toString(const EnrichedMarkdownTextMarkdownStyleInlineMathStruct &value) {
@@ -0,0 +1,25 @@
1
+ #pragma once
2
+
3
+ #import <Foundation/Foundation.h>
4
+
5
+ NS_ASSUME_NONNULL_BEGIN
6
+
7
+ /// Vertical tab. md4c treats it as ordinary whitespace, never as a line break.
8
+ extern const unichar ENRMBlockSyntaxSentinelChar;
9
+
10
+ /// Collapses `\r\n` / `\r` to `\n` and drops any `0x0B` already in the input.
11
+ /// Dropping is deliberate: a pre-existing `0x0B` would come back out of
12
+ /// `ENRMBlockSyntaxDecode` as a newline and silently corrupt the text.
13
+ NSString *ENRMBlockSyntaxCanonicalize(NSString *markdown);
14
+
15
+ /// Prepends one sentinel and replaces every `\n` with one. Grows the string by
16
+ /// exactly one character and one UTF-8 byte, which is what keeps the parser's
17
+ /// byte-to-UTF16 map valid and the offset correction a flat -1.
18
+ NSString *ENRMBlockSyntaxEncode(NSString *canonical);
19
+
20
+ /// Reverses `ENRMBlockSyntaxEncode`. Returns nil when the leading sentinel is
21
+ /// missing, so the caller can fall back instead of shifting offsets that no
22
+ /// longer hold.
23
+ NSString *_Nullable ENRMBlockSyntaxDecode(NSString *plainText);
24
+
25
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,80 @@
1
+ #import "ENRMBlockSyntaxSentinel.h"
2
+
3
+ #import <vector>
4
+
5
+ const unichar ENRMBlockSyntaxSentinelChar = 0x000B;
6
+
7
+ NSString *ENRMBlockSyntaxCanonicalize(NSString *markdown)
8
+ {
9
+ NSUInteger length = markdown.length;
10
+ if (length == 0) {
11
+ return @"";
12
+ }
13
+
14
+ std::vector<unichar> source(length);
15
+ [markdown getCharacters:source.data() range:NSMakeRange(0, length)];
16
+
17
+ std::vector<unichar> out;
18
+ out.reserve(length);
19
+
20
+ for (NSUInteger i = 0; i < length; i++) {
21
+ unichar c = source[i];
22
+ if (c == '\r') {
23
+ out.push_back('\n');
24
+ if (i + 1 < length && source[i + 1] == '\n') {
25
+ i++;
26
+ }
27
+ } else if (c != ENRMBlockSyntaxSentinelChar) {
28
+ out.push_back(c);
29
+ }
30
+ }
31
+
32
+ // `out.data()` on an empty vector may be null, which -stringWithCharacters: rejects.
33
+ if (out.empty()) {
34
+ return @"";
35
+ }
36
+
37
+ return [NSString stringWithCharacters:out.data() length:out.size()];
38
+ }
39
+
40
+ NSString *ENRMBlockSyntaxEncode(NSString *canonical)
41
+ {
42
+ NSUInteger length = canonical.length;
43
+
44
+ std::vector<unichar> out;
45
+ out.reserve(length + 1);
46
+ out.push_back(ENRMBlockSyntaxSentinelChar);
47
+
48
+ if (length > 0) {
49
+ std::vector<unichar> source(length);
50
+ [canonical getCharacters:source.data() range:NSMakeRange(0, length)];
51
+ for (NSUInteger i = 0; i < length; i++) {
52
+ out.push_back(source[i] == '\n' ? ENRMBlockSyntaxSentinelChar : source[i]);
53
+ }
54
+ }
55
+
56
+ return [NSString stringWithCharacters:out.data() length:out.size()];
57
+ }
58
+
59
+ NSString *ENRMBlockSyntaxDecode(NSString *plainText)
60
+ {
61
+ NSUInteger length = plainText.length;
62
+ if (length == 0 || [plainText characterAtIndex:0] != ENRMBlockSyntaxSentinelChar) {
63
+ return nil;
64
+ }
65
+
66
+ std::vector<unichar> source(length);
67
+ [plainText getCharacters:source.data() range:NSMakeRange(0, length)];
68
+
69
+ std::vector<unichar> out;
70
+ out.reserve(length - 1);
71
+ for (NSUInteger i = 1; i < length; i++) {
72
+ out.push_back(source[i] == ENRMBlockSyntaxSentinelChar ? '\n' : source[i]);
73
+ }
74
+
75
+ if (out.empty()) {
76
+ return @"";
77
+ }
78
+
79
+ return [NSString stringWithCharacters:out.data() length:out.size()];
80
+ }
@@ -50,6 +50,8 @@ NS_ASSUME_NONNULL_BEGIN
50
50
  @property (nonatomic, assign) CGFloat mathPaddingVertical;
51
51
  @property (nonatomic, strong, nullable) RCTUIColor *mathSelectedBackgroundColor;
52
52
  @property (nonatomic, strong, nullable) RCTUIColor *mathSelectedBorderColor;
53
+ /// Raw `fontWeight` string; narrowed at the draw site (see ENRMMathFontWeight.h).
54
+ @property (nonatomic, copy, nullable) NSString *mathFontWeight;
53
55
 
54
56
  /// Math block (`$$...$$`)
55
57
  @property (nonatomic, strong, nullable) RCTUIColor *mathBlockColor;
@@ -65,6 +67,8 @@ NS_ASSUME_NONNULL_BEGIN
65
67
  @property (nonatomic, assign) CGFloat mathBlockMarginTop;
66
68
  @property (nonatomic, assign) CGFloat mathBlockMarginBottom;
67
69
  @property (nonatomic, assign) NSTextAlignment mathBlockAlignment;
70
+ /// Raw `fontWeight` string; narrowed at the draw site (see ENRMMathFontWeight.h).
71
+ @property (nonatomic, copy, nullable) NSString *mathBlockFontWeight;
68
72
 
69
73
  - (UIFont *)fontForTraits:(UIFontDescriptorSymbolicTraits)traits;
70
74
  - (void)invalidateFontCache;
@@ -56,6 +56,7 @@
56
56
  copy.mathPaddingVertical = _mathPaddingVertical;
57
57
  copy.mathSelectedBackgroundColor = _mathSelectedBackgroundColor;
58
58
  copy.mathSelectedBorderColor = _mathSelectedBorderColor;
59
+ copy.mathFontWeight = _mathFontWeight;
59
60
  copy.mathBlockColor = _mathBlockColor;
60
61
  copy.mathBlockFontSize = _mathBlockFontSize;
61
62
  copy.mathBlockBackgroundColor = _mathBlockBackgroundColor;
@@ -69,6 +70,7 @@
69
70
  copy.mathBlockMarginTop = _mathBlockMarginTop;
70
71
  copy.mathBlockMarginBottom = _mathBlockMarginBottom;
71
72
  copy.mathBlockAlignment = _mathBlockAlignment;
73
+ copy.mathBlockFontWeight = _mathBlockFontWeight;
72
74
  return copy;
73
75
  }
74
76
 
@@ -22,6 +22,11 @@ NS_ASSUME_NONNULL_BEGIN
22
22
 
23
23
  - (ENRMParseResult *)parseToPlainTextAndRanges:(NSString *)markdown;
24
24
 
25
+ /// `blockSyntax = NO` hides block structure from md4c (see ENRMBlockSyntaxSentinel)
26
+ /// and skips `ENRMInputRemendComplete`, so list markers, headings and blockquotes
27
+ /// survive as text and the markdown round-trips byte-for-byte.
28
+ - (ENRMParseResult *)parseToPlainTextAndRanges:(NSString *)markdown blockSyntax:(BOOL)blockSyntax;
29
+
25
30
  @end
26
31
 
27
32
  NS_ASSUME_NONNULL_END