@intlayer/docs 8.10.0-canary.0 → 8.10.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.
@@ -47,6 +47,7 @@ You can declare Markdown content using the `md` function or simply as a string (
47
47
 
48
48
  <Tabs>
49
49
  <Tab label=".content.md" value=".content.md">
50
+
50
51
  Since version `8.10.0`, you can declare Markdown content directly in `.content.md` files. Intlayer will
51
52
  automatically detect and parse the Markdown content.
52
53
 
@@ -96,50 +97,58 @@ You can declare Markdown content using the `md` function or simply as a string (
96
97
  ```
97
98
 
98
99
  </Tab>
99
- <Tab label="Automatic Detection" value="automatic-detection">
100
- If the string contains common Markdown indicators (like headers, lists, links, etc.), Intlayer will automatically transform it.
100
+
101
+ <Tab label="External Files" value="external-files">
102
+ Import `.md` files directly using the `file` function.
101
103
 
102
104
  ```typescript fileName="markdownDictionary.content.ts"
105
+ import { md, file, t } from "intlayer";
106
+
103
107
  export default {
104
108
  key: "app",
105
- contentAutoTransformation: true, // Enable automatic detection of Markdown content - Can be set globally in intlayer.config.ts
106
109
  content: {
107
- myMarkdownContent: "## My title \n\nLorem Ipsum",
110
+ content: t({
111
+ en: md(file("./myMarkdown.en.md")),
112
+ fr: md(file("./myMarkdown.fr.md")),
113
+ }),
108
114
  },
109
115
  };
110
116
  ```
111
117
 
112
118
  </Tab>
113
119
 
114
- <Tab label="External Files" value="external-files">
115
- Import `.md` files directly using the `file` function.
120
+ <Tab label="Automatic Detection" value="automatic-detection">
121
+ If the string contains common Markdown indicators (like headers, lists, links, etc.), Intlayer will automatically transform it.
116
122
 
117
123
  ```typescript fileName="markdownDictionary.content.ts"
118
- import { md, file, t } from "intlayer";
119
-
120
124
  export default {
121
125
  key: "app",
126
+ contentAutoTransformation: true, // Enable automatic detection of Markdown content - Can be set globally in intlayer.config.ts
122
127
  content: {
123
- content: t({
124
- en: md(file("./myMarkdown.en.md")),
125
- fr: md(file("./myMarkdown.fr.md")),
126
- }),
128
+ myMarkdownContent: "## My title \n\nLorem Ipsum",
127
129
  },
128
130
  };
129
131
  ```
130
132
 
131
133
  </Tab>
134
+
132
135
  </Tabs>
133
136
 
134
137
  ---
135
138
 
136
139
  ## Rendering Markdown
137
140
 
138
- Rendering can be handled automatically by Intlayer's content system or manually using specialized tools.
141
+ Intlayer provides two independent ways to render Markdown:
142
+
143
+ 1. **Via `useIntlayer`**
144
+ — Intlayer automatically transforms the `md` node into the framework's native output (JSX, VNode, HTML string).
145
+ - Frontmatter is parsed and exposed as `.metadata`. You can override rendering at two levels — globally with `MarkdownProvider` (or the framework equivalent) and locally per-node with `.use()`. Both can be combined; `.use()` takes priority over `MarkdownProvider`, which takes priority over the default.
139
146
 
140
- ### 1. Automatic Rendering (using `useIntlayer`)
147
+ 2. **Helper utilities** — `<MarkdownRenderer />`, `useMarkdownRenderer()`, and `renderMarkdown()` are standalone tools that accept **raw Markdown strings only**. They are independent of `useIntlayer` and do not work with the decorated nodes it returns.
141
148
 
142
- When you access content via `useIntlayer`, Markdown nodes are already prepared for rendering.
149
+ Markdown rendering supports **MDX** use any JSX/framework component by name directly in your Markdown.
150
+
151
+ ### 1. Automatic Rendering (via `useIntlayer`)
143
152
 
144
153
  <Tabs group="framework">
145
154
  <Tab label="React / Next.js" value="react">
@@ -147,21 +156,51 @@ When you access content via `useIntlayer`, Markdown nodes are already prepared f
147
156
 
148
157
  ```tsx fileName="App.tsx"
149
158
  import { useIntlayer } from "react-intlayer";
159
+ import { MarkdownProvider } from "react-intlayer/markdown";
150
160
 
151
161
  const AppContent = () => {
152
162
  const { myMarkdownContent } = useIntlayer("app");
163
+
153
164
  return <div>{myMarkdownContent}</div>;
154
165
  };
166
+
167
+ const App = () => (
168
+ <MarkdownProvider
169
+ components={{
170
+ h1: ({ children }) => <h1 style={{ color: "red" }}>{children}</h1>,
171
+ MyButton: (props) => <button {...props} />, // MDX component
172
+ }}
173
+ >
174
+ <AppContent />
175
+ </MarkdownProvider>
176
+ );
155
177
  ```
156
178
 
179
+ > If `MarkdownProvider` not present, intlayer will render the markdown using the default Markdown to JSX parser.
180
+
157
181
  You can also provide local overrides for specific nodes using the `.use()` method:
158
182
 
159
183
  ```tsx
160
184
  {myMarkdownContent.use({
161
- h1: ({ children }) => <h1 className="text-3xl font-bold">{children}</h1>,
185
+ h1: ({ children }) => <h1 style={{ color: "red" }}>{children}</h1>,
162
186
  })}
163
187
  ```
164
188
 
189
+ You can retrieve the Markdown as string:
190
+
191
+ ```tsx
192
+ {myMarkdownContent.value}
193
+ {String(myMarkdownContent)}
194
+ {myMarkdownContent.toString()}
195
+ ```
196
+
197
+ And you can access your markdown metadata like :
198
+
199
+ ```tsx
200
+ {myMarkdownContent.metadata}
201
+ {myMarkdownContent.metadata.title}
202
+ ```
203
+
165
204
  </Tab>
166
205
  <Tab label="Vue" value="vue">
167
206
  In Vue, Markdown content can be rendered using the `component` built-in or directly as a node.
@@ -177,43 +216,183 @@ When you access content via `useIntlayer`, Markdown nodes are already prepared f
177
216
  </template>
178
217
  ```
179
218
 
219
+ Configure globally via the `intlayerMarkdown` plugin (supports MDX custom components):
220
+
221
+ ```ts fileName="main.ts"
222
+ import { intlayerMarkdown } from "vue-intlayer/markdown";
223
+
224
+ app.use(intlayerMarkdown, {
225
+ components: {
226
+ h1: (props) => h('h1', { style: { color: 'green' } }, props.children),
227
+ MyButton: (props) => h('button', props), // MDX component
228
+ },
229
+ });
230
+ ```
231
+
232
+ > If the `intlayerMarkdown` plugin is not installed, Intlayer will render using the default compiler.
233
+
234
+ You can also provide local overrides for specific nodes using the `.use()` method:
235
+
236
+ ```vue
237
+ <component :is="myMarkdownContent.use({
238
+ h1: (props) => h('h1', { style: { color: 'red' } }, props.children),
239
+ })" />
240
+ ```
241
+
242
+ You can retrieve the Markdown as string:
243
+
244
+ ```vue
245
+ {{ myMarkdownContent.value }}
246
+ {{ String(myMarkdownContent) }}
247
+ {{ myMarkdownContent.toString() }}
248
+ ```
249
+
250
+ And you can access your markdown metadata like :
251
+
252
+ ```vue
253
+ <component :is="myMarkdownContent.metadata" />
254
+ <component :is="myMarkdownContent.metadata.title" />
255
+ ```
256
+
180
257
  </Tab>
181
258
  <Tab label="Svelte" value="svelte">
182
259
  Svelte renders Markdown as an HTML string by default. Use `{@html}` to render it.
183
260
 
184
- ```svelte
261
+ ```svelte fileName="App.svelte"
185
262
  <script lang="ts">
186
263
  import { useIntlayer } from "svelte-intlayer";
264
+ import { MarkdownProvider } from "svelte-intlayer/markdown";
265
+ import MyHeading from "./MyHeading.svelte";
266
+
187
267
  const content = useIntlayer("app");
188
268
  </script>
189
269
 
190
- {@html $content.myMarkdownContent}
270
+ <MarkdownProvider components={{ h1: MyHeading }}>
271
+ {@html $content.myMarkdownContent}
272
+ </MarkdownProvider>
273
+ ```
274
+
275
+ > If `MarkdownProvider` is not present, Intlayer will render the markdown using the default compiler.
276
+
277
+ You can also provide local overrides for specific nodes using the `.use()` method:
278
+
279
+ ```svelte
280
+ {@html $content.myMarkdownContent.use({ ... })}
281
+ ```
282
+
283
+ You can retrieve the Markdown as string:
284
+
285
+ ```svelte
286
+ {$content.myMarkdownContent.value}
287
+ {String($content.myMarkdownContent)}
288
+ {$content.myMarkdownContent.toString()}
289
+ ```
290
+
291
+ And you can access your markdown metadata like :
292
+
293
+ ```svelte
294
+ {$content.myMarkdownContent.metadata}
295
+ {$content.myMarkdownContent.metadata.title}
191
296
  ```
192
297
 
193
298
  </Tab>
194
299
  <Tab label="Preact" value="preact">
195
- Preact supports Markdown nodes directly in the JSX.
300
+ Preact supports Markdown nodes directly in JSX.
196
301
 
197
302
  ```tsx fileName="App.tsx"
198
303
  import { useIntlayer } from "preact-intlayer";
304
+ import { MarkdownProvider } from "preact-intlayer/markdown";
199
305
 
200
306
  const AppContent = () => {
201
307
  const { myMarkdownContent } = useIntlayer("app");
202
308
  return <div>{myMarkdownContent}</div>;
203
309
  };
310
+
311
+ const App = () => (
312
+ <MarkdownProvider
313
+ components={{
314
+ h1: ({ children }) => <h1 style={{ color: "red" }}>{children}</h1>,
315
+ MyButton: (props) => <button {...props} />, // MDX component
316
+ }}
317
+ >
318
+ <AppContent />
319
+ </MarkdownProvider>
320
+ );
321
+ ```
322
+
323
+ > If `MarkdownProvider` not present, intlayer will render the markdown using the default Markdown to JSX parser.
324
+
325
+ You can also provide local overrides for specific nodes using the `.use()` method:
326
+
327
+ ```tsx
328
+ {myMarkdownContent.use({
329
+ h1: ({ children }) => <h1 style={{ color: "red" }}>{children}</h1>,
330
+ })}
331
+ ```
332
+
333
+ You can retrieve the Markdown as string:
334
+
335
+ ```tsx
336
+ {myMarkdownContent.value}
337
+ {String(myMarkdownContent)}
338
+ {myMarkdownContent.toString()}
339
+ ```
340
+
341
+ And you can access your markdown metadata like :
342
+
343
+ ```tsx
344
+ {myMarkdownContent.metadata}
345
+ {myMarkdownContent.metadata.title}
204
346
  ```
205
347
 
206
348
  </Tab>
207
349
  <Tab label="Solid" value="solid">
208
- Solid supports Markdown nodes directly in the JSX.
350
+ Solid supports Markdown nodes directly in JSX.
209
351
 
210
352
  ```tsx fileName="App.tsx"
211
353
  import { useIntlayer } from "solid-intlayer";
354
+ import { MarkdownProvider } from "solid-intlayer/markdown";
212
355
 
213
356
  const AppContent = () => {
214
357
  const { myMarkdownContent } = useIntlayer("app");
215
358
  return <div>{myMarkdownContent}</div>;
216
359
  };
360
+
361
+ const App = () => (
362
+ <MarkdownProvider
363
+ components={{
364
+ h1: (props) => <h1 style={{ color: "red" }}>{props.children}</h1>,
365
+ MyButton: (props) => <button {...props} />, // MDX component
366
+ }}
367
+ >
368
+ <AppContent />
369
+ </MarkdownProvider>
370
+ );
371
+ ```
372
+
373
+ > If `MarkdownProvider` not present, intlayer will render the markdown using the default Markdown to JSX parser.
374
+
375
+ You can also provide local overrides for specific nodes using the `.use()` method:
376
+
377
+ ```tsx
378
+ {myMarkdownContent.use({
379
+ h1: (props) => <h1 style={{ color: "red" }}>{props.children}</h1>,
380
+ })}
381
+ ```
382
+
383
+ You can retrieve the Markdown as string:
384
+
385
+ ```tsx
386
+ {myMarkdownContent.value}
387
+ {String(myMarkdownContent)}
388
+ {myMarkdownContent.toString()}
389
+ ```
390
+
391
+ And you can access your markdown metadata like :
392
+
393
+ ```tsx
394
+ {myMarkdownContent.metadata}
395
+ {myMarkdownContent.metadata.title}
217
396
  ```
218
397
 
219
398
  </Tab>
@@ -233,6 +412,8 @@ When you access content via `useIntlayer`, Markdown nodes are already prepared f
233
412
  }
234
413
  ```
235
414
 
415
+ > If the IntlayerMarkdown provider is not configured, Intlayer will render using the default compiler.
416
+
236
417
  You can also provide local overrides for specific nodes using the `.use()` method:
237
418
 
238
419
  ```typescript
@@ -241,12 +422,27 @@ When you access content via `useIntlayer`, Markdown nodes are already prepared f
241
422
  })
242
423
  ```
243
424
 
425
+ You can retrieve the Markdown as string:
426
+
427
+ ```typescript
428
+ content().myMarkdownContent.value
429
+ String(content().myMarkdownContent)
430
+ content().myMarkdownContent.toString()
431
+ ```
432
+
433
+ And you can access your markdown metadata like :
434
+
435
+ ```typescript
436
+ content().myMarkdownContent.metadata
437
+ content().myMarkdownContent.metadata.title
438
+ ```
439
+
244
440
  </Tab>
245
441
  </Tabs>
246
442
 
247
- ### 2. Manual Rendering & Advanced Tools
443
+ ### 2. Helper Utilities (Markdown Strings Only)
248
444
 
249
- If you need to render raw Markdown strings or have more control over the rendering process, use the following tools.
445
+ These utilities render **raw Markdown strings** and are independent of `useIntlayer`. Use them when you need to render Markdown from sources other than your dictionaries.
250
446
 
251
447
  <Tabs group="framework">
252
448
  <Tab label="React / Next.js" value="react">
@@ -420,7 +616,7 @@ If you need to render raw Markdown strings or have more control over the renderi
420
616
 
421
617
  ## Global Configuration with `MarkdownProvider`
422
618
 
423
- You can configure Markdown rendering globally for your entire application. This avoids passing the same props to every renderer.
619
+ `MarkdownProvider` (or its framework equivalent) configures the Markdown rendering pipeline for your entire application. It applies to both the automatic `useIntlayer` rendering and the helper utilities. Options set here are the defaults — `.use()` overrides them at the node level.
424
620
 
425
621
  <Tabs group="framework">
426
622
  <Tab label="React / Next.js" value="react">
@@ -431,8 +627,9 @@ You can configure Markdown rendering globally for your entire application. This
431
627
  export const AppProvider = ({ children }) => (
432
628
  <MarkdownProvider
433
629
  components={{
434
- h1: ({ children }) => <h1 className="text-2xl font-bold">{children}</h1>,
435
- a: ({ href, children }) => <Link to={href}>{children}</Link>,
630
+ h1: (props) => <h1 style={{color: 'green'}} {...props} />,
631
+ a: ({ href, ...props }) => <a style={{color: 'red'}} {...props} />,
632
+ MyCustomJSXComponent: (props) => <span style={{color: 'red'}} {...props} />,
436
633
  }}
437
634
  >
438
635
  {children}
@@ -440,6 +637,8 @@ You can configure Markdown rendering globally for your entire application. This
440
637
  );
441
638
  ```
442
639
 
640
+ > MDX is supported — any component name used inside your Markdown (e.g. `<MyCustomJSXComponent />`) is resolved against the `components` map.
641
+
443
642
  You can also use your own markdown renderer:
444
643
 
445
644
  ```tsx fileName="AppProvider.tsx"
@@ -448,8 +647,9 @@ You can configure Markdown rendering globally for your entire application. This
448
647
  export const AppProvider = ({ children }) => (
449
648
  <MarkdownProvider
450
649
  renderMarkdown={async (md) => {
451
- const { compileMarkdown } = await import('react-intlayer/markdown');
452
- return compileMarkdown(md);
650
+ // Use dynamic import to reduce the bundle size of your application
651
+ const { renderMarkdown } = await import('react-intlayer/markdown');
652
+ return renderMarkdown(md);
453
653
  }}
454
654
  >
455
655
  {children}
@@ -497,8 +697,8 @@ You can configure Markdown rendering globally for your entire application. This
497
697
  app.use(intlayer);
498
698
  app.use(intlayerMarkdown, {
499
699
  renderMarkdown: async (md) => {
500
- const { compileMarkdown } = await import('vue-intlayer/markdown');
501
- return compileMarkdown(md);
700
+ const { renderMarkdown } = await import('vue-intlayer/markdown');
701
+ return renderMarkdown(md);
502
702
  },
503
703
  });
504
704
 
@@ -534,8 +734,8 @@ You can configure Markdown rendering globally for your entire application. This
534
734
 
535
735
  <MarkdownProvider
536
736
  renderMarkdown={async (md) => {
537
- const { compileMarkdown } = await import('svelte-intlayer/markdown');
538
- return compileMarkdown(md);
737
+ const { renderMarkdown } = await import('svelte-intlayer/markdown');
738
+ return renderMarkdown(md);
539
739
  }}
540
740
  >
541
741
  <slot />
@@ -569,8 +769,8 @@ You can configure Markdown rendering globally for your entire application. This
569
769
  export const AppProvider = ({ children }) => (
570
770
  <MarkdownProvider
571
771
  renderMarkdown={async (md) => {
572
- const { compileMarkdown } = await import('preact-intlayer/markdown');
573
- return compileMarkdown(md);
772
+ const { renderMarkdown } = await import('preact-intlayer/markdown');
773
+ return renderMarkdown(md);
574
774
  }}
575
775
  >
576
776
  {children}
@@ -605,8 +805,8 @@ You can configure Markdown rendering globally for your entire application. This
605
805
  export const AppProvider = (props) => (
606
806
  <MarkdownProvider
607
807
  renderMarkdown={async (md) => {
608
- const { compileMarkdown } = await import('solid-intlayer/markdown');
609
- return compileMarkdown(md);
808
+ const { renderMarkdown } = await import('solid-intlayer/markdown');
809
+ return renderMarkdown(md);
610
810
  }}
611
811
  >
612
812
  {props.children}
@@ -642,8 +842,8 @@ You can configure Markdown rendering globally for your entire application. This
642
842
  providers: [
643
843
  createIntlayerMarkdownProvider({
644
844
  renderMarkdown: async (md) => {
645
- const { compileMarkdown } = await import('angular-intlayer/markdown');
646
- return compileMarkdown(md);
845
+ const { renderMarkdown } = await import('angular-intlayer/markdown');
846
+ return renderMarkdown(md);
647
847
  },
648
848
  }),
649
849
  ],