react-native-nitro-markdown 0.2.1 → 0.3.0
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.
- package/README.md +217 -101
- package/lib/commonjs/MarkdownContext.js +3 -7
- package/lib/commonjs/MarkdownContext.js.map +1 -1
- package/lib/commonjs/default-markdown-renderer.js +4 -7
- package/lib/commonjs/default-markdown-renderer.js.map +1 -1
- package/lib/commonjs/headless.js +12 -1
- package/lib/commonjs/headless.js.map +1 -1
- package/lib/commonjs/index.js +35 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/markdown.js +88 -37
- package/lib/commonjs/markdown.js.map +1 -1
- package/lib/commonjs/renderers/blockquote.js +1 -1
- package/lib/commonjs/renderers/blockquote.js.map +1 -1
- package/lib/commonjs/renderers/code.js +15 -8
- package/lib/commonjs/renderers/code.js.map +1 -1
- package/lib/commonjs/renderers/heading.js +2 -1
- package/lib/commonjs/renderers/heading.js.map +1 -1
- package/lib/commonjs/renderers/horizontal-rule.js +4 -2
- package/lib/commonjs/renderers/horizontal-rule.js.map +1 -1
- package/lib/commonjs/renderers/image.js +13 -9
- package/lib/commonjs/renderers/image.js.map +1 -1
- package/lib/commonjs/renderers/link.js +1 -3
- package/lib/commonjs/renderers/link.js.map +1 -1
- package/lib/commonjs/renderers/list.js +11 -7
- package/lib/commonjs/renderers/list.js.map +1 -1
- package/lib/commonjs/renderers/math.js +23 -47
- package/lib/commonjs/renderers/math.js.map +1 -1
- package/lib/commonjs/renderers/paragraph.js +0 -5
- package/lib/commonjs/renderers/paragraph.js.map +1 -1
- package/lib/commonjs/renderers/table.js +127 -120
- package/lib/commonjs/renderers/table.js.map +1 -1
- package/lib/commonjs/theme.js +146 -13
- package/lib/commonjs/theme.js.map +1 -1
- package/lib/module/MarkdownContext.js +3 -8
- package/lib/module/MarkdownContext.js.map +1 -1
- package/lib/module/default-markdown-renderer.js +1 -4
- package/lib/module/default-markdown-renderer.js.map +1 -1
- package/lib/module/headless.js +10 -0
- package/lib/module/headless.js.map +1 -1
- package/lib/module/index.js +2 -20
- package/lib/module/index.js.map +1 -1
- package/lib/module/markdown.js +89 -38
- package/lib/module/markdown.js.map +1 -1
- package/lib/module/renderers/blockquote.js +1 -1
- package/lib/module/renderers/blockquote.js.map +1 -1
- package/lib/module/renderers/code.js +15 -8
- package/lib/module/renderers/code.js.map +1 -1
- package/lib/module/renderers/heading.js +2 -1
- package/lib/module/renderers/heading.js.map +1 -1
- package/lib/module/renderers/horizontal-rule.js +4 -2
- package/lib/module/renderers/horizontal-rule.js.map +1 -1
- package/lib/module/renderers/image.js +13 -9
- package/lib/module/renderers/image.js.map +1 -1
- package/lib/module/renderers/link.js +1 -3
- package/lib/module/renderers/link.js.map +1 -1
- package/lib/module/renderers/list.js +11 -7
- package/lib/module/renderers/list.js.map +1 -1
- package/lib/module/renderers/math.js +24 -48
- package/lib/module/renderers/math.js.map +1 -1
- package/lib/module/renderers/paragraph.js +0 -5
- package/lib/module/renderers/paragraph.js.map +1 -1
- package/lib/module/renderers/table.js +128 -121
- package/lib/module/renderers/table.js.map +1 -1
- package/lib/module/theme.js +144 -12
- package/lib/module/theme.js.map +1 -1
- package/lib/typescript/commonjs/MarkdownContext.d.ts +45 -6
- package/lib/typescript/commonjs/MarkdownContext.d.ts.map +1 -1
- package/lib/typescript/commonjs/default-markdown-renderer.d.ts +1 -1
- package/lib/typescript/commonjs/default-markdown-renderer.d.ts.map +1 -1
- package/lib/typescript/commonjs/headless.d.ts +8 -1
- package/lib/typescript/commonjs/headless.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +4 -16
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/markdown.d.ts +20 -2
- package/lib/typescript/commonjs/markdown.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/code.d.ts +6 -2
- package/lib/typescript/commonjs/renderers/code.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/heading.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/horizontal-rule.d.ts +6 -1
- package/lib/typescript/commonjs/renderers/horizontal-rule.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/image.d.ts +2 -0
- package/lib/typescript/commonjs/renderers/image.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/link.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/list.d.ts +4 -0
- package/lib/typescript/commonjs/renderers/list.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/math.d.ts +3 -4
- package/lib/typescript/commonjs/renderers/math.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/paragraph.d.ts +0 -5
- package/lib/typescript/commonjs/renderers/paragraph.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/table.d.ts +2 -0
- package/lib/typescript/commonjs/renderers/table.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme.d.ts +41 -28
- package/lib/typescript/commonjs/theme.d.ts.map +1 -1
- package/lib/typescript/module/MarkdownContext.d.ts +45 -6
- package/lib/typescript/module/MarkdownContext.d.ts.map +1 -1
- package/lib/typescript/module/default-markdown-renderer.d.ts +1 -1
- package/lib/typescript/module/default-markdown-renderer.d.ts.map +1 -1
- package/lib/typescript/module/headless.d.ts +8 -1
- package/lib/typescript/module/headless.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +4 -16
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/markdown.d.ts +20 -2
- package/lib/typescript/module/markdown.d.ts.map +1 -1
- package/lib/typescript/module/renderers/code.d.ts +6 -2
- package/lib/typescript/module/renderers/code.d.ts.map +1 -1
- package/lib/typescript/module/renderers/heading.d.ts.map +1 -1
- package/lib/typescript/module/renderers/horizontal-rule.d.ts +6 -1
- package/lib/typescript/module/renderers/horizontal-rule.d.ts.map +1 -1
- package/lib/typescript/module/renderers/image.d.ts +2 -0
- package/lib/typescript/module/renderers/image.d.ts.map +1 -1
- package/lib/typescript/module/renderers/link.d.ts.map +1 -1
- package/lib/typescript/module/renderers/list.d.ts +4 -0
- package/lib/typescript/module/renderers/list.d.ts.map +1 -1
- package/lib/typescript/module/renderers/math.d.ts +3 -4
- package/lib/typescript/module/renderers/math.d.ts.map +1 -1
- package/lib/typescript/module/renderers/paragraph.d.ts +0 -5
- package/lib/typescript/module/renderers/paragraph.d.ts.map +1 -1
- package/lib/typescript/module/renderers/table.d.ts +2 -0
- package/lib/typescript/module/renderers/table.d.ts.map +1 -1
- package/lib/typescript/module/theme.d.ts +41 -28
- package/lib/typescript/module/theme.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/MarkdownContext.ts +66 -9
- package/src/default-markdown-renderer.tsx +1 -6
- package/src/headless.ts +11 -1
- package/src/index.ts +24 -19
- package/src/markdown.tsx +125 -43
- package/src/renderers/blockquote.tsx +1 -2
- package/src/renderers/code.tsx +36 -12
- package/src/renderers/heading.tsx +1 -1
- package/src/renderers/horizontal-rule.tsx +7 -4
- package/src/renderers/image.tsx +24 -9
- package/src/renderers/link.tsx +1 -6
- package/src/renderers/list.tsx +11 -5
- package/src/renderers/math.tsx +20 -43
- package/src/renderers/paragraph.tsx +0 -6
- package/src/renderers/table.tsx +185 -160
- package/src/theme.ts +203 -12
package/README.md
CHANGED
|
@@ -100,38 +100,25 @@ export function MyComponent() {
|
|
|
100
100
|
}
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
-
### Option 2:
|
|
103
|
+
### Option 2: Light Theme / Theme Presets
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
The default theme is optimized for dark mode. For light backgrounds, use the provided `lightMarkdownTheme`:
|
|
106
106
|
|
|
107
107
|
```tsx
|
|
108
|
-
import {
|
|
109
|
-
Markdown,
|
|
110
|
-
Heading,
|
|
111
|
-
type CustomRenderers,
|
|
112
|
-
} from "react-native-nitro-markdown";
|
|
113
|
-
import MathJax from "react-native-mathjax-svg";
|
|
114
|
-
|
|
115
|
-
const renderers: CustomRenderers = {
|
|
116
|
-
// Custom styled heading
|
|
117
|
-
heading: ({ node, children }) => (
|
|
118
|
-
<Heading level={node.level ?? 1}>
|
|
119
|
-
<Text style={{ color: "pink" }}>{children}</Text>
|
|
120
|
-
</Heading>
|
|
121
|
-
),
|
|
122
|
-
// Custom math renderer
|
|
123
|
-
math_inline: ({ node }) => <MathJax fontSize={16}>{node.content}</MathJax>,
|
|
124
|
-
math_block: ({ node }) => <MathJax fontSize={20}>{node.content}</MathJax>,
|
|
125
|
-
};
|
|
108
|
+
import { Markdown, lightMarkdownTheme } from "react-native-nitro-markdown";
|
|
126
109
|
|
|
127
|
-
<Markdown
|
|
128
|
-
{markdown}
|
|
129
|
-
</Markdown>;
|
|
110
|
+
<Markdown theme={lightMarkdownTheme}>{"# Light Mode Markdown"}</Markdown>;
|
|
130
111
|
```
|
|
131
112
|
|
|
113
|
+
Available presets:
|
|
114
|
+
|
|
115
|
+
- `defaultMarkdownTheme` / `darkMarkdownTheme` - Modern dark theme
|
|
116
|
+
- `lightMarkdownTheme` - Clean light theme
|
|
117
|
+
- `minimalMarkdownTheme` - Bare minimum styling for a clean slate
|
|
118
|
+
|
|
132
119
|
### Option 3: Custom Theming
|
|
133
120
|
|
|
134
|
-
|
|
121
|
+
Customize the look and feel by passing a partial `theme` object:
|
|
135
122
|
|
|
136
123
|
```tsx
|
|
137
124
|
import { Markdown } from "react-native-nitro-markdown";
|
|
@@ -141,38 +128,152 @@ const myTheme = {
|
|
|
141
128
|
text: "#2D3748",
|
|
142
129
|
heading: "#1A202C",
|
|
143
130
|
link: "#3182CE",
|
|
144
|
-
tableBorder: "#E2E8F0",
|
|
145
|
-
tableHeader: "#F7FAFC",
|
|
146
131
|
},
|
|
147
|
-
|
|
148
|
-
|
|
132
|
+
fontFamilies: {
|
|
133
|
+
regular: "Inter",
|
|
134
|
+
heading: "Inter-Bold",
|
|
135
|
+
mono: "JetBrainsMono",
|
|
136
|
+
},
|
|
137
|
+
borderRadius: {
|
|
138
|
+
s: 4,
|
|
139
|
+
m: 8,
|
|
140
|
+
l: 16,
|
|
149
141
|
},
|
|
142
|
+
showCodeLanguage: true, // Toggle code language labels
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
<Markdown theme={myTheme}>{"# Custom Themed Markdown"}</Markdown>;
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**Theme Properties:**
|
|
149
|
+
|
|
150
|
+
- `colors` - All color tokens (text, heading, link, code, codeBackground, codeLanguage, etc.)
|
|
151
|
+
- `spacing` - Spacing tokens (xs, s, m, l, xl)
|
|
152
|
+
- `fontSizes` - Font sizes (xs, s, m, l, xl, h1-h6)
|
|
153
|
+
- `fontFamilies` - Font families for regular, heading, and mono text
|
|
154
|
+
- `borderRadius` - Border radius tokens (s, m, l)
|
|
155
|
+
- `showCodeLanguage` - Show/hide code block language labels
|
|
156
|
+
|
|
157
|
+
### Option 4: Style Overrides per Node Type
|
|
158
|
+
|
|
159
|
+
Apply quick style overrides to specific node types without writing custom renderers:
|
|
160
|
+
|
|
161
|
+
```tsx
|
|
162
|
+
<Markdown
|
|
163
|
+
styles={{
|
|
164
|
+
heading: { color: "red", fontWeight: "900" },
|
|
165
|
+
code_block: { backgroundColor: "#1a1a2e", borderRadius: 16 },
|
|
166
|
+
blockquote: { borderLeftColor: "#ff6b6b" },
|
|
167
|
+
}}
|
|
168
|
+
>
|
|
169
|
+
{markdown}
|
|
170
|
+
</Markdown>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Option 5: Minimal Styling Strategy
|
|
174
|
+
|
|
175
|
+
Start with a clean slate using the `stylingStrategy` prop:
|
|
176
|
+
|
|
177
|
+
```tsx
|
|
178
|
+
<Markdown stylingStrategy="minimal" theme={myLightTheme}>
|
|
179
|
+
{content}
|
|
180
|
+
</Markdown>
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
This zeros out all spacing and removes opinionated colors, letting you build up from scratch.
|
|
184
|
+
|
|
185
|
+
### Option 6: Custom Renderers
|
|
186
|
+
|
|
187
|
+
Override specific node types with full control. Custom renderers now receive **pre-mapped props** for common values:
|
|
188
|
+
|
|
189
|
+
```tsx
|
|
190
|
+
import {
|
|
191
|
+
Markdown,
|
|
192
|
+
CodeBlock,
|
|
193
|
+
type HeadingRendererProps,
|
|
194
|
+
type CodeBlockRendererProps,
|
|
195
|
+
} from "react-native-nitro-markdown";
|
|
196
|
+
|
|
197
|
+
const renderers = {
|
|
198
|
+
// Pre-mapped `level` prop - no need for node.level!
|
|
199
|
+
heading: ({ level, children }: HeadingRendererProps) => (
|
|
200
|
+
<MyHeading level={level}>{children}</MyHeading>
|
|
201
|
+
),
|
|
202
|
+
|
|
203
|
+
// Pre-mapped `content` and `language` - no getTextContent() needed!
|
|
204
|
+
code_block: ({ content, language }: CodeBlockRendererProps) => (
|
|
205
|
+
<CodeBlock
|
|
206
|
+
content={content}
|
|
207
|
+
language={language}
|
|
208
|
+
style={{ borderWidth: 2 }}
|
|
209
|
+
/>
|
|
210
|
+
),
|
|
150
211
|
};
|
|
151
212
|
|
|
152
|
-
<Markdown
|
|
213
|
+
<Markdown renderers={renderers} options={{ gfm: true }}>
|
|
214
|
+
{markdown}
|
|
215
|
+
</Markdown>;
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
**Pre-mapped Props by Node Type:**
|
|
219
|
+
|
|
220
|
+
- `heading` → `level` (1-6)
|
|
221
|
+
- `link` → `href`, `title`
|
|
222
|
+
- `image` → `url`, `alt`, `title`
|
|
223
|
+
- `code_block` → `content`, `language`
|
|
224
|
+
- `code_inline` → `content`
|
|
225
|
+
- `list` → `ordered`, `start`
|
|
226
|
+
- `task_list_item` → `checked`
|
|
227
|
+
|
|
228
|
+
### Option 7: Style Props on Individual Renderers
|
|
229
|
+
|
|
230
|
+
All built-in renderers accept a `style` prop for fine-grained overrides:
|
|
153
231
|
|
|
154
|
-
|
|
232
|
+
```tsx
|
|
233
|
+
import { Heading, CodeBlock, InlineCode } from "react-native-nitro-markdown";
|
|
234
|
+
|
|
235
|
+
// Works in custom renderers
|
|
236
|
+
<Heading level={1} style={{ color: "hotpink" }}>Title</Heading>
|
|
237
|
+
<CodeBlock content={code} style={{ borderRadius: 0 }} />
|
|
238
|
+
<InlineCode style={{ backgroundColor: "#ff0" }}>code</InlineCode>
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Option 8: Auto Content Extraction for Code
|
|
242
|
+
|
|
243
|
+
The `CodeBlock` and `InlineCode` components now accept a `node` prop for automatic content extraction:
|
|
244
|
+
|
|
245
|
+
```tsx
|
|
246
|
+
// Before: Manual extraction required
|
|
247
|
+
code_block: ({ node }) => (
|
|
248
|
+
<CodeBlock content={getTextContent(node)} language={node.language} />
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
// After: Just pass the node
|
|
252
|
+
code_block: ({ node }) => <CodeBlock node={node} />;
|
|
253
|
+
|
|
254
|
+
// Or use the pre-mapped content prop (recommended)
|
|
255
|
+
code_block: ({ content, language }) => (
|
|
256
|
+
<CodeBlock content={content} language={language} />
|
|
257
|
+
);
|
|
155
258
|
```
|
|
156
259
|
|
|
157
|
-
### Option
|
|
260
|
+
### Option 9: Headless (Minimal Bundle)
|
|
158
261
|
|
|
159
262
|
For maximum control, data processing, or minimal JS overhead:
|
|
160
263
|
|
|
161
264
|
```tsx
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
import { parseMarkdown } from "react-native-nitro-markdown/headless";
|
|
265
|
+
import {
|
|
266
|
+
parseMarkdown,
|
|
267
|
+
getTextContent,
|
|
268
|
+
} from "react-native-nitro-markdown/headless";
|
|
167
269
|
|
|
168
270
|
const ast = parseMarkdown("# Hello World");
|
|
271
|
+
const text = getTextContent(ast); // "Hello World"
|
|
169
272
|
```
|
|
170
273
|
|
|
171
|
-
### Option
|
|
274
|
+
### Option 10: High-Performance Streaming (LLMs)
|
|
172
275
|
|
|
173
|
-
When streaming text token-by-token (e.g., from ChatGPT or Gemini)
|
|
174
|
-
|
|
175
|
-
**Nitro Markdown** enables **Native Streaming** via JSI. The text buffer is maintained in C++ and updates are pushed directly to the native view, bypassing React completely.
|
|
276
|
+
When streaming text token-by-token (e.g., from ChatGPT or Gemini):
|
|
176
277
|
|
|
177
278
|
```tsx
|
|
178
279
|
import {
|
|
@@ -181,19 +282,13 @@ import {
|
|
|
181
282
|
} from "react-native-nitro-markdown";
|
|
182
283
|
|
|
183
284
|
export function AIResponseStream() {
|
|
184
|
-
// 1. Create a native session
|
|
185
285
|
const session = useMarkdownSession();
|
|
186
286
|
|
|
187
287
|
useEffect(() => {
|
|
188
|
-
// 2. Append chunks directly to C++ (Zero-Latency)
|
|
189
|
-
// Example: Socket.on('data', (chunk) => session.getSession().append(chunk));
|
|
190
|
-
|
|
191
288
|
session.getSession().append("Hello **Nitro**!");
|
|
192
|
-
|
|
193
289
|
return () => session.clear();
|
|
194
290
|
}, [session]);
|
|
195
291
|
|
|
196
|
-
// 3. Render the localized stream component
|
|
197
292
|
return (
|
|
198
293
|
<MarkdownStream session={session.getSession()} options={{ gfm: true }} />
|
|
199
294
|
);
|
|
@@ -202,6 +297,68 @@ export function AIResponseStream() {
|
|
|
202
297
|
|
|
203
298
|
---
|
|
204
299
|
|
|
300
|
+
## 🎨 Using Context in Custom Renderers
|
|
301
|
+
|
|
302
|
+
Access theme and context in custom renderers:
|
|
303
|
+
|
|
304
|
+
```tsx
|
|
305
|
+
import {
|
|
306
|
+
useMarkdownContext,
|
|
307
|
+
MarkdownContext,
|
|
308
|
+
} from "react-native-nitro-markdown";
|
|
309
|
+
|
|
310
|
+
const MyCustomRenderer = ({ children }) => {
|
|
311
|
+
const { theme, stylingStrategy } = useMarkdownContext();
|
|
312
|
+
|
|
313
|
+
return <View style={{ padding: theme.spacing.m }}>{children}</View>;
|
|
314
|
+
};
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
## 🛠️ Exported Utilities
|
|
320
|
+
|
|
321
|
+
```tsx
|
|
322
|
+
// Parser and utilities
|
|
323
|
+
export {
|
|
324
|
+
parseMarkdown,
|
|
325
|
+
parseMarkdownWithOptions,
|
|
326
|
+
getTextContent,
|
|
327
|
+
} from "./headless";
|
|
328
|
+
|
|
329
|
+
// Theme presets
|
|
330
|
+
export {
|
|
331
|
+
defaultMarkdownTheme,
|
|
332
|
+
lightMarkdownTheme,
|
|
333
|
+
darkMarkdownTheme,
|
|
334
|
+
minimalMarkdownTheme,
|
|
335
|
+
mergeThemes,
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
// Context
|
|
339
|
+
export { useMarkdownContext, MarkdownContext };
|
|
340
|
+
|
|
341
|
+
// Individual renderers
|
|
342
|
+
export {
|
|
343
|
+
Heading,
|
|
344
|
+
Paragraph,
|
|
345
|
+
Link,
|
|
346
|
+
Blockquote,
|
|
347
|
+
HorizontalRule,
|
|
348
|
+
CodeBlock,
|
|
349
|
+
InlineCode,
|
|
350
|
+
List,
|
|
351
|
+
ListItem,
|
|
352
|
+
TaskListItem,
|
|
353
|
+
TableRenderer,
|
|
354
|
+
Image,
|
|
355
|
+
MathInline,
|
|
356
|
+
MathBlock,
|
|
357
|
+
};
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
---
|
|
361
|
+
|
|
205
362
|
## 🛠️ Headless vs. Non-Headless
|
|
206
363
|
|
|
207
364
|
| Feature | **Headless** (`/headless`) | **Non-Headless** (`default`) |
|
|
@@ -214,7 +371,8 @@ export function AIResponseStream() {
|
|
|
214
371
|
---
|
|
215
372
|
|
|
216
373
|
### Basic Parsing API
|
|
217
|
-
|
|
374
|
+
|
|
375
|
+
The parsing is synchronous and instant. It returns a fully typed JSON AST:
|
|
218
376
|
|
|
219
377
|
```typescript
|
|
220
378
|
import { parseMarkdown } from "react-native-nitro-markdown/headless";
|
|
@@ -223,74 +381,33 @@ const ast = parseMarkdown(`
|
|
|
223
381
|
# Hello World
|
|
224
382
|
This is **bold** text and a [link](https://github.com).
|
|
225
383
|
`);
|
|
226
|
-
console.log(ast);
|
|
227
|
-
// Output: { type: "document", children: [...] }
|
|
228
384
|
```
|
|
229
385
|
|
|
230
386
|
### Options
|
|
231
387
|
|
|
232
|
-
| Option | Type
|
|
233
|
-
|
|
|
234
|
-
| `gfm`
|
|
235
|
-
| `math` | `boolean` | `false` | Enable LaTeX Math support (`$` and `$$`).
|
|
236
|
-
|
|
237
|
-
### Parser Options (GFM & Math)
|
|
238
|
-
|
|
239
|
-
Enable GitHub Flavored Markdown (Tables, TaskLists) or LaTeX Math support.
|
|
240
|
-
|
|
241
|
-
```typescript
|
|
242
|
-
import { parseMarkdownWithOptions } from "react-native-nitro-markdown/headless";
|
|
243
|
-
|
|
244
|
-
const ast = parseMarkdownWithOptions(markdown, {
|
|
245
|
-
gfm: true, // Tables (supports complex nested content!), Strikethrough, Autolinks, TaskLists
|
|
246
|
-
math: true, // $E=mc^2$ and $$block$$
|
|
247
|
-
});
|
|
248
|
-
```
|
|
388
|
+
| Option | Type | Default | Description |
|
|
389
|
+
| :----- | :-------- | :------ | :----------------------------------------------------------------------------- |
|
|
390
|
+
| `gfm` | `boolean` | `false` | Enable GitHub Flavored Markdown (Tables, Strikethrough, Autolinks, TaskLists). |
|
|
391
|
+
| `math` | `boolean` | `false` | Enable LaTeX Math support (`$` and `$$`). |
|
|
249
392
|
|
|
250
393
|
---
|
|
251
394
|
|
|
252
395
|
## 📐 AST Structure
|
|
253
396
|
|
|
254
|
-
The parser returns a `MarkdownNode` tree
|
|
397
|
+
The parser returns a `MarkdownNode` tree:
|
|
255
398
|
|
|
256
399
|
```typescript
|
|
257
400
|
export interface MarkdownNode {
|
|
258
401
|
type: NodeType;
|
|
259
|
-
// Content for Text/Code/Math
|
|
260
402
|
content?: string;
|
|
261
|
-
// Hierarchy
|
|
262
403
|
children?: MarkdownNode[];
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
language?: string; // Code Blocks
|
|
268
|
-
// Table Props
|
|
404
|
+
level?: number;
|
|
405
|
+
href?: string;
|
|
406
|
+
checked?: boolean;
|
|
407
|
+
language?: string;
|
|
269
408
|
align?: "left" | "center" | "right";
|
|
270
409
|
isHeader?: boolean;
|
|
271
410
|
}
|
|
272
|
-
|
|
273
|
-
export type NodeType =
|
|
274
|
-
| "document"
|
|
275
|
-
| "paragraph"
|
|
276
|
-
| "text"
|
|
277
|
-
| "heading"
|
|
278
|
-
| "bold"
|
|
279
|
-
| "italic"
|
|
280
|
-
| "strikethrough"
|
|
281
|
-
| "link"
|
|
282
|
-
| "image"
|
|
283
|
-
| "code_inline"
|
|
284
|
-
| "code_block"
|
|
285
|
-
| "blockquote"
|
|
286
|
-
| "list"
|
|
287
|
-
| "list_item"
|
|
288
|
-
| "task_list_item"
|
|
289
|
-
| "table"
|
|
290
|
-
| "table_row"
|
|
291
|
-
| "table_cell"
|
|
292
|
-
| "math_inline"
|
|
293
|
-
| "math_block";
|
|
294
411
|
```
|
|
295
412
|
|
|
296
413
|
---
|
|
@@ -299,16 +416,17 @@ export type NodeType =
|
|
|
299
416
|
|
|
300
417
|
We parse math delimiters (`$` and `$$`) natively using the `MD_FLAG_LATEXMATHSPANS` flag in `md4c`.
|
|
301
418
|
|
|
302
|
-
To render the math,
|
|
419
|
+
To render the math, use a library like `react-native-mathjax-svg`:
|
|
303
420
|
|
|
304
421
|
```tsx
|
|
305
|
-
// Inside your switch(node.type)
|
|
306
422
|
case 'math_inline':
|
|
307
423
|
return <MathView math={node.content} style={styles.math} />;
|
|
308
424
|
case 'math_block':
|
|
309
425
|
return <MathView math={node.content} style={styles.mathBlock} />;
|
|
310
426
|
```
|
|
311
427
|
|
|
428
|
+
---
|
|
429
|
+
|
|
312
430
|
## 📊 Package Size
|
|
313
431
|
|
|
314
432
|
| Metric | Size |
|
|
@@ -317,8 +435,6 @@ case 'math_block':
|
|
|
317
435
|
| **Unpacked** | ~325 kB |
|
|
318
436
|
| **Total files** | 55 |
|
|
319
437
|
|
|
320
|
-
> The package includes the [md4c](https://github.com/mity/md4c) C source code (~244 kB) which is compiled natively on iOS and Android. This is a one-time cost that enables the high-performance parsing.
|
|
321
|
-
|
|
322
438
|
---
|
|
323
439
|
|
|
324
440
|
## 🤝 Contributing
|
|
@@ -6,15 +6,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.useMarkdownContext = exports.MarkdownContext = void 0;
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _theme = require("./theme.js");
|
|
9
|
-
/**
|
|
10
|
-
* Object mapping node types to custom renderers.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
// Context for custom renderers and theme
|
|
14
|
-
|
|
15
9
|
const MarkdownContext = exports.MarkdownContext = /*#__PURE__*/(0, _react.createContext)({
|
|
16
10
|
renderers: {},
|
|
17
|
-
theme: _theme.defaultMarkdownTheme
|
|
11
|
+
theme: _theme.defaultMarkdownTheme,
|
|
12
|
+
styles: undefined,
|
|
13
|
+
stylingStrategy: "opinionated"
|
|
18
14
|
});
|
|
19
15
|
const useMarkdownContext = () => (0, _react.useContext)(MarkdownContext);
|
|
20
16
|
exports.useMarkdownContext = useMarkdownContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_theme","MarkdownContext","exports","createContext","renderers","theme","defaultMarkdownTheme","useMarkdownContext","useContext"],"sourceRoot":"../../src","sources":["MarkdownContext.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;
|
|
1
|
+
{"version":3,"names":["_react","require","_theme","MarkdownContext","exports","createContext","renderers","theme","defaultMarkdownTheme","styles","undefined","stylingStrategy","useMarkdownContext","useContext"],"sourceRoot":"../../src","sources":["MarkdownContext.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAMA,IAAAC,MAAA,GAAAD,OAAA;AAoFO,MAAME,eAAe,GAAAC,OAAA,CAAAD,eAAA,gBAAG,IAAAE,oBAAa,EAAuB;EACjEC,SAAS,EAAE,CAAC,CAAC;EACbC,KAAK,EAAEC,2BAAoB;EAC3BC,MAAM,EAAEC,SAAS;EACjBC,eAAe,EAAE;AACnB,CAAC,CAAC;AAEK,MAAMC,kBAAkB,GAAGA,CAAA,KAAM,IAAAC,iBAAU,EAACV,eAAe,CAAC;AAACC,OAAA,CAAAQ,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.DefaultMarkdownRenderer = void 0;
|
|
7
7
|
var _reactNative = require("react-native");
|
|
8
|
+
var _headless = require("./headless.js");
|
|
8
9
|
var _heading = require("./renderers/heading.js");
|
|
9
10
|
var _paragraph = require("./renderers/paragraph.js");
|
|
10
11
|
var _link = require("./renderers/link.js");
|
|
@@ -20,10 +21,6 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
20
21
|
const isInline = type => {
|
|
21
22
|
return type === "text" || type === "bold" || type === "italic" || type === "strikethrough" || type === "link" || type === "code_inline" || type === "soft_break" || type === "line_break" || type === "math_inline" || type === "html_inline";
|
|
22
23
|
};
|
|
23
|
-
const getTextContent = node => {
|
|
24
|
-
if (node.content) return node.content;
|
|
25
|
-
return node.children?.map(getTextContent).join("") ?? "";
|
|
26
|
-
};
|
|
27
24
|
const DefaultMarkdownRenderer = ({
|
|
28
25
|
node,
|
|
29
26
|
depth = 0,
|
|
@@ -116,7 +113,7 @@ const DefaultMarkdownRenderer = ({
|
|
|
116
113
|
case "code_block":
|
|
117
114
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_code.CodeBlock, {
|
|
118
115
|
language: node.language,
|
|
119
|
-
content: getTextContent(node)
|
|
116
|
+
content: (0, _headless.getTextContent)(node)
|
|
120
117
|
});
|
|
121
118
|
case "blockquote":
|
|
122
119
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockquote.Blockquote, {
|
|
@@ -134,7 +131,7 @@ const DefaultMarkdownRenderer = ({
|
|
|
134
131
|
});
|
|
135
132
|
case "math_inline":
|
|
136
133
|
{
|
|
137
|
-
let mathContent = getTextContent(node);
|
|
134
|
+
let mathContent = (0, _headless.getTextContent)(node);
|
|
138
135
|
if (!mathContent) return null;
|
|
139
136
|
mathContent = mathContent.replace(/^\$+|\$+$/g, "").trim();
|
|
140
137
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_math.MathInline, {
|
|
@@ -143,7 +140,7 @@ const DefaultMarkdownRenderer = ({
|
|
|
143
140
|
}
|
|
144
141
|
case "math_block":
|
|
145
142
|
{
|
|
146
|
-
let mathContent = getTextContent(node);
|
|
143
|
+
let mathContent = (0, _headless.getTextContent)(node);
|
|
147
144
|
if (!mathContent) return null;
|
|
148
145
|
mathContent = mathContent.replace(/^\$+|\$+$/g, "").trim();
|
|
149
146
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_math.MathBlock, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_heading","_paragraph","_link","_blockquote","_horizontalRule","_code","_list","_table","_image","_math","_theme","_jsxRuntime","isInline","type","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_headless","_heading","_paragraph","_link","_blockquote","_horizontalRule","_code","_list","_table","_image","_math","_theme","_jsxRuntime","isInline","type","DefaultMarkdownRenderer","node","depth","inListItem","renderChildren","children","childInListItem","length","elements","currentInlineGroup","flushInlineGroup","push","jsx","Text","style","styles","text","map","child","index","forEach","View","document","Heading","level","Paragraph","content","bold","italic","strikethrough","Link","href","Image","url","title","alt","Renderer","InlineCode","CodeBlock","language","getTextContent","Blockquote","HorizontalRule","mathContent","replace","trim","MathInline","MathBlock","List","ordered","start","ListItem","Fragment","TaskListItem","checked","TableRenderer","exports","StyleSheet","create","flex","color","defaultMarkdownTheme","colors","fontWeight","fontStyle","textDecorationLine"],"sourceRoot":"../../src","sources":["default-markdown-renderer.tsx"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,QAA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C,2BAAoB,CAACC,MAAM,CAAC9C;EACrC,CAAC;EACDW,IAAI,EAAE;IACJoC,UAAU,EAAE;EACd,CAAC;EACDnC,MAAM,EAAE;IACNoC,SAAS,EAAE;EACb,CAAC;EACDnC,aAAa,EAAE;IACboC,kBAAkB,EAAE;EACtB;AACF,CAAC,CAAC","ignoreList":[]}
|
package/lib/commonjs/headless.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.MarkdownParserModule = void 0;
|
|
6
|
+
exports.getTextContent = exports.MarkdownParserModule = void 0;
|
|
7
7
|
exports.parseMarkdown = parseMarkdown;
|
|
8
8
|
exports.parseMarkdownWithOptions = parseMarkdownWithOptions;
|
|
9
9
|
var _reactNativeNitroModules = require("react-native-nitro-modules");
|
|
@@ -47,4 +47,15 @@ function parseMarkdownWithOptions(text, options) {
|
|
|
47
47
|
const jsonStr = MarkdownParserModule.parseWithOptions(text, options);
|
|
48
48
|
return JSON.parse(jsonStr);
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Extract text content from a markdown node recursively.
|
|
52
|
+
* Useful for getting plain text from code blocks, headings, etc.
|
|
53
|
+
* @param node - The markdown node to extract text from
|
|
54
|
+
* @returns The concatenated text content
|
|
55
|
+
*/
|
|
56
|
+
const getTextContent = node => {
|
|
57
|
+
if (node.content) return node.content;
|
|
58
|
+
return node.children?.map(getTextContent).join("") ?? "";
|
|
59
|
+
};
|
|
60
|
+
exports.getTextContent = getTextContent;
|
|
50
61
|
//# sourceMappingURL=headless.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNativeNitroModules","require","MarkdownParserModule","exports","NitroModules","createHybridObject","parseMarkdown","text","jsonStr","parse","JSON","parseMarkdownWithOptions","options","parseWithOptions"],"sourceRoot":"../../src","sources":["headless.ts"],"mappings":";;;;;;;;AAYA,IAAAA,wBAAA,GAAAC,OAAA;AAZA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;;AAyDO,MAAMC,oBAAoB,GAAAC,OAAA,CAAAD,oBAAA,GAC/BE,qCAAY,CAACC,kBAAkB,CAAiB,gBAAgB,CAAC;;AAEnE;AACA;AACA;AACA;AACA;AACO,SAASC,aAAaA,CAACC,IAAY,EAAgB;EACxD,MAAMC,OAAO,GAAGN,oBAAoB,CAACO,KAAK,CAACF,IAAI,CAAC;EAChD,OAAOG,IAAI,CAACD,KAAK,CAACD,OAAO,CAAC;AAC5B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,wBAAwBA,CACtCJ,IAAY,EACZK,OAAsB,EACR;EACd,MAAMJ,OAAO,GAAGN,oBAAoB,CAACW,gBAAgB,CAACN,IAAI,EAAEK,OAAO,CAAC;EACpE,OAAOF,IAAI,CAACD,KAAK,CAACD,OAAO,CAAC;AAC5B","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_reactNativeNitroModules","require","MarkdownParserModule","exports","NitroModules","createHybridObject","parseMarkdown","text","jsonStr","parse","JSON","parseMarkdownWithOptions","options","parseWithOptions","getTextContent","node","content","children","map","join"],"sourceRoot":"../../src","sources":["headless.ts"],"mappings":";;;;;;;;AAYA,IAAAA,wBAAA,GAAAC,OAAA;AAZA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;;AAyDO,MAAMC,oBAAoB,GAAAC,OAAA,CAAAD,oBAAA,GAC/BE,qCAAY,CAACC,kBAAkB,CAAiB,gBAAgB,CAAC;;AAEnE;AACA;AACA;AACA;AACA;AACO,SAASC,aAAaA,CAACC,IAAY,EAAgB;EACxD,MAAMC,OAAO,GAAGN,oBAAoB,CAACO,KAAK,CAACF,IAAI,CAAC;EAChD,OAAOG,IAAI,CAACD,KAAK,CAACD,OAAO,CAAC;AAC5B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,wBAAwBA,CACtCJ,IAAY,EACZK,OAAsB,EACR;EACd,MAAMJ,OAAO,GAAGN,oBAAoB,CAACW,gBAAgB,CAACN,IAAI,EAAEK,OAAO,CAAC;EACpE,OAAOF,IAAI,CAACD,KAAK,CAACD,OAAO,CAAC;AAC5B;AAIA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMM,cAAc,GAAIC,IAAkB,IAAa;EAC5D,IAAIA,IAAI,CAACC,OAAO,EAAE,OAAOD,IAAI,CAACC,OAAO;EACrC,OAAOD,IAAI,CAACE,QAAQ,EAAEC,GAAG,CAACJ,cAAc,CAAC,CAACK,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE;AAC1D,CAAC;AAAChB,OAAA,CAAAW,cAAA,GAAAA,cAAA","ignoreList":[]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -8,7 +8,12 @@ var _exportNames = {
|
|
|
8
8
|
Markdown: true,
|
|
9
9
|
MarkdownStream: true,
|
|
10
10
|
useMarkdownContext: true,
|
|
11
|
+
MarkdownContext: true,
|
|
11
12
|
defaultMarkdownTheme: true,
|
|
13
|
+
lightMarkdownTheme: true,
|
|
14
|
+
darkMarkdownTheme: true,
|
|
15
|
+
minimalMarkdownTheme: true,
|
|
16
|
+
mergeThemes: true,
|
|
12
17
|
Heading: true,
|
|
13
18
|
Paragraph: true,
|
|
14
19
|
Link: true,
|
|
@@ -93,6 +98,12 @@ Object.defineProperty(exports, "Markdown", {
|
|
|
93
98
|
return _markdown.Markdown;
|
|
94
99
|
}
|
|
95
100
|
});
|
|
101
|
+
Object.defineProperty(exports, "MarkdownContext", {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
get: function () {
|
|
104
|
+
return _MarkdownContext.MarkdownContext;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
96
107
|
Object.defineProperty(exports, "MarkdownStream", {
|
|
97
108
|
enumerable: true,
|
|
98
109
|
get: function () {
|
|
@@ -135,12 +146,36 @@ Object.defineProperty(exports, "createMarkdownSession", {
|
|
|
135
146
|
return _MarkdownSession.createMarkdownSession;
|
|
136
147
|
}
|
|
137
148
|
});
|
|
149
|
+
Object.defineProperty(exports, "darkMarkdownTheme", {
|
|
150
|
+
enumerable: true,
|
|
151
|
+
get: function () {
|
|
152
|
+
return _theme.darkMarkdownTheme;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
138
155
|
Object.defineProperty(exports, "defaultMarkdownTheme", {
|
|
139
156
|
enumerable: true,
|
|
140
157
|
get: function () {
|
|
141
158
|
return _theme.defaultMarkdownTheme;
|
|
142
159
|
}
|
|
143
160
|
});
|
|
161
|
+
Object.defineProperty(exports, "lightMarkdownTheme", {
|
|
162
|
+
enumerable: true,
|
|
163
|
+
get: function () {
|
|
164
|
+
return _theme.lightMarkdownTheme;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
Object.defineProperty(exports, "mergeThemes", {
|
|
168
|
+
enumerable: true,
|
|
169
|
+
get: function () {
|
|
170
|
+
return _theme.mergeThemes;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
Object.defineProperty(exports, "minimalMarkdownTheme", {
|
|
174
|
+
enumerable: true,
|
|
175
|
+
get: function () {
|
|
176
|
+
return _theme.minimalMarkdownTheme;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
144
179
|
Object.defineProperty(exports, "useMarkdownContext", {
|
|
145
180
|
enumerable: true,
|
|
146
181
|
get: function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_headless","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_defaultMarkdownRenderer","_markdown","_markdownStream","_MarkdownContext","_theme","_heading","_paragraph","_link","_blockquote","_horizontalRule","_code","_list","_table","_image","_math","_MarkdownSession","_useMarkdownStream"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_headless","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_defaultMarkdownRenderer","_markdown","_markdownStream","_MarkdownContext","_theme","_heading","_paragraph","_link","_blockquote","_horizontalRule","_code","_list","_table","_image","_math","_MarkdownSession","_useMarkdownStream"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,SAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAL,SAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAb,SAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AAEA,IAAAS,wBAAA,GAAAb,OAAA;AACA,IAAAc,SAAA,GAAAd,OAAA;AACA,IAAAe,eAAA,GAAAf,OAAA;AAEA,IAAAgB,gBAAA,GAAAhB,OAAA;AAkBA,IAAAiB,MAAA,GAAAjB,OAAA;AAcA,IAAAkB,QAAA,GAAAlB,OAAA;AACA,IAAAmB,UAAA,GAAAnB,OAAA;AACA,IAAAoB,KAAA,GAAApB,OAAA;AACA,IAAAqB,WAAA,GAAArB,OAAA;AACA,IAAAsB,eAAA,GAAAtB,OAAA;AACA,IAAAuB,KAAA,GAAAvB,OAAA;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