@intlayer/docs 8.10.0-canary.0 → 8.10.0-canary.1
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/docs/ar/dictionary/markdown.md +402 -82
- package/docs/de/dictionary/markdown.md +269 -98
- package/docs/en/dictionary/markdown.md +221 -25
- package/docs/en-GB/dictionary/markdown.md +351 -67
- package/docs/es/dictionary/markdown.md +286 -115
- package/docs/fr/dictionary/markdown.md +292 -121
- package/docs/hi/dictionary/markdown.md +366 -81
- package/docs/id/dictionary/markdown.md +368 -83
- package/docs/it/dictionary/markdown.md +288 -122
- package/docs/ko/dictionary/markdown.md +297 -126
- package/docs/pl/dictionary/markdown.md +276 -106
- package/docs/pt/dictionary/markdown.md +276 -106
- package/docs/ru/dictionary/markdown.md +70 -505
- package/docs/tr/dictionary/markdown.md +291 -122
- package/docs/uk/dictionary/markdown.md +377 -92
- package/docs/vi/dictionary/markdown.md +377 -92
- package/docs/zh/dictionary/markdown.md +284 -117
- package/package.json +7 -7
- package/docs/ja/dictionary/markdown.md +0 -666
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
createdAt: 2025-02-07
|
|
3
3
|
updatedAt: 2026-05-19
|
|
4
4
|
title: Markdown
|
|
5
|
-
description:
|
|
5
|
+
description: 了解如何使用 Intlayer 在您的多语言网站中声明和使用 Markdown 内容。按照本在线文档中的步骤将 Markdown 无缝集成到您的项目中。
|
|
6
6
|
keywords:
|
|
7
7
|
- Markdown
|
|
8
8
|
- 国际化
|
|
@@ -19,49 +19,49 @@ slugs:
|
|
|
19
19
|
history:
|
|
20
20
|
- version: 8.10.0
|
|
21
21
|
date: 2026-05-19
|
|
22
|
-
changes: "
|
|
22
|
+
changes: "添加对 `.content.md` 文件的支持"
|
|
23
23
|
- version: 8.5.0
|
|
24
24
|
date: 2026-03-24
|
|
25
|
-
changes: "
|
|
25
|
+
changes: "添加 `intlayerMarkdown` 插件对象;使用 `app.use(intlayerMarkdown)` 代替 `app.use(installIntlayerMarkdown)`"
|
|
26
26
|
- version: 8.5.0
|
|
27
27
|
date: 2026-03-24
|
|
28
|
-
changes: "将导入从 {{framework}}-intlayer 移动到 {{framework}}-intlayer/markdown"
|
|
28
|
+
changes: "将导入从 `{{framework}}-intlayer` 移动到 `{{framework}}-intlayer/markdown`"
|
|
29
29
|
- version: 8.0.0
|
|
30
30
|
date: 2026-01-22
|
|
31
|
-
changes: "添加 MarkdownRenderer / useMarkdownRenderer / renderMarkdown
|
|
31
|
+
changes: "添加 MarkdownRenderer / useMarkdownRenderer / renderMarkdown 实用程序和 forceInline 选项"
|
|
32
32
|
- version: 8.0.0
|
|
33
33
|
date: 2026-01-18
|
|
34
|
-
changes: "
|
|
34
|
+
changes: "Markdown 内容的自动装饰,MDX 和 SSR 支持"
|
|
35
35
|
- version: 5.5.10
|
|
36
36
|
date: 2025-06-29
|
|
37
|
-
changes: "
|
|
37
|
+
changes: "初始化历史"
|
|
38
38
|
---
|
|
39
39
|
|
|
40
40
|
# Markdown / 富文本内容
|
|
41
41
|
|
|
42
|
-
Intlayer 支持使用 Markdown
|
|
42
|
+
Intlayer 支持使用 Markdown 语法定义的富文本内容。这使您可以轻松编写和维护具有丰富格式的内容,例如博客、文章等。
|
|
43
43
|
|
|
44
44
|
## 声明 Markdown 内容
|
|
45
45
|
|
|
46
|
-
您可以使用 `md` 函数声明 Markdown
|
|
46
|
+
您可以使用 `md` 函数声明 Markdown 内容,或简单地将其作为字符串声明(如果它包含 Markdown 语法)。
|
|
47
47
|
|
|
48
48
|
<Tabs>
|
|
49
49
|
<Tab label=".content.md" value=".content.md">
|
|
50
|
-
|
|
50
|
+
从 `8.10.0` 版本开始,您可以在 `.content.md` 文件中直接声明 Markdown 内容。Intlayer 会自动检测并解析 Markdown 内容。
|
|
51
51
|
|
|
52
|
-
```md fileName="markdown-file.
|
|
52
|
+
```md fileName="markdown-file.en.content.md"
|
|
53
53
|
---
|
|
54
54
|
key: my-markdown-content
|
|
55
55
|
description: 我的内容
|
|
56
|
-
locale:
|
|
56
|
+
locale: en
|
|
57
57
|
---
|
|
58
58
|
|
|
59
59
|
# 我的内容
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
这里是一个 Markdown 内容示例
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
`locale`
|
|
64
|
+
`locale` front-matter 字段是定义内容语言环境的字段。它是可选的。如果没有提供,Intlayer 会使用默认语言环境,如果没有提供特定语言环境的翻译,这也将作为后备语言环境。
|
|
65
65
|
|
|
66
66
|
文件结构示例:
|
|
67
67
|
|
|
@@ -75,11 +75,11 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
75
75
|
└── markdown-file.es.content.md
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
您可以在 front-matter 中添加任何在[字典定义](https://github.com/aymericzip/intlayer/blob/main/docs/docs/zh/dictionary/content_file.md)中定义的属性。
|
|
79
79
|
|
|
80
80
|
</Tab>
|
|
81
|
-
<Tab label="
|
|
82
|
-
使用 `md` 函数显式声明 Markdown
|
|
81
|
+
<Tab label="手动包装" value="manual-wrapping">
|
|
82
|
+
使用 `md` 函数显式声明 Markdown 内容。如果您想确保即使字符串不包含明显的语法也被视为 Markdown,这将非常有用。
|
|
83
83
|
|
|
84
84
|
```typescript fileName="markdownDictionary.content.ts"
|
|
85
85
|
import { md, type Dictionary } from "intlayer";
|
|
@@ -96,12 +96,12 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
96
96
|
|
|
97
97
|
</Tab>
|
|
98
98
|
<Tab label="自动检测" value="automatic-detection">
|
|
99
|
-
如果字符串包含常见的 Markdown
|
|
99
|
+
如果字符串包含常见的 Markdown 指示符(如标题、列表、链接等),Intlayer 会自动转换它。
|
|
100
100
|
|
|
101
101
|
```typescript fileName="markdownDictionary.content.ts"
|
|
102
102
|
export default {
|
|
103
103
|
key: "app",
|
|
104
|
-
contentAutoTransformation: true, // 启用 Markdown 内容的自动检测 -
|
|
104
|
+
contentAutoTransformation: true, // 启用 Markdown 内容的自动检测 - 可以在 intlayer.config.ts 中全局设置
|
|
105
105
|
content: {
|
|
106
106
|
myMarkdownContent: "## 我的标题 \n\nLorem Ipsum",
|
|
107
107
|
},
|
|
@@ -109,7 +109,8 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
109
109
|
```
|
|
110
110
|
|
|
111
111
|
</Tab>
|
|
112
|
-
|
|
112
|
+
|
|
113
|
+
<Tab label="外部文件" value="external-files">
|
|
113
114
|
使用 `file` 函数直接导入 `.md` 文件。
|
|
114
115
|
|
|
115
116
|
```typescript fileName="markdownDictionary.content.ts"
|
|
@@ -120,7 +121,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
120
121
|
content: {
|
|
121
122
|
content: t({
|
|
122
123
|
en: md(file("./myMarkdown.en.md")),
|
|
123
|
-
|
|
124
|
+
zh: md(file("./myMarkdown.zh.md")),
|
|
124
125
|
}),
|
|
125
126
|
},
|
|
126
127
|
};
|
|
@@ -131,38 +132,74 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
131
132
|
|
|
132
133
|
---
|
|
133
134
|
|
|
134
|
-
##
|
|
135
|
+
## 渲染 Markdown
|
|
136
|
+
|
|
137
|
+
Intlayer 提供两种独立的方式来渲染 Markdown:
|
|
138
|
+
|
|
139
|
+
1. **通过 `useIntlayer`**
|
|
140
|
+
— Intlayer 会自动将 `md` 节点转换为框架的原生输出(JSX,VNode,HTML 字符串)。
|
|
141
|
+
- Frontmatter 被解析并作为 `.metadata` 暴露。您可以在两个级别上覆盖渲染 — 使用 `MarkdownProvider`(或框架等效物)进行全局覆盖,或使用 `.use()` 针对每个节点进行局部覆盖。两者可以结合使用;`.use()` 优先于 `MarkdownProvider`,而 `MarkdownProvider` 优先于默认渲染。
|
|
135
142
|
|
|
136
|
-
|
|
143
|
+
2. **辅助实用程序** — `<MarkdownRenderer />`,`useMarkdownRenderer()` 和 `renderMarkdown()` 是独立的工具,**仅接受原始 Markdown 字符串**。它们独立于 `useIntlayer`,不与它返回的修饰节点一起工作。
|
|
137
144
|
|
|
138
|
-
|
|
145
|
+
Markdown 渲染支持 **MDX** — 在您的 Markdown 中直接按名称使用任何 JSX/框架组件。
|
|
139
146
|
|
|
140
|
-
|
|
147
|
+
### 1. 自动渲染(通过 `useIntlayer`)
|
|
141
148
|
|
|
142
149
|
<Tabs group="framework">
|
|
143
150
|
<Tab label="React / Next.js" value="react">
|
|
144
|
-
Markdown
|
|
151
|
+
Markdown 节点可以直接呈现为 JSX。
|
|
145
152
|
|
|
146
153
|
```tsx fileName="App.tsx"
|
|
147
154
|
import { useIntlayer } from "react-intlayer";
|
|
155
|
+
import { MarkdownProvider } from "react-intlayer/markdown";
|
|
148
156
|
|
|
149
157
|
const AppContent = () => {
|
|
150
158
|
const { myMarkdownContent } = useIntlayer("app");
|
|
159
|
+
|
|
151
160
|
return <div>{myMarkdownContent}</div>;
|
|
152
161
|
};
|
|
162
|
+
|
|
163
|
+
const App = () => (
|
|
164
|
+
<MarkdownProvider
|
|
165
|
+
components={{
|
|
166
|
+
h1: ({ children }) => <h1 style={{ color: "red" }}>{children}</h1>,
|
|
167
|
+
MyButton: (props) => <button {...props} />, // MDX 组件
|
|
168
|
+
}}
|
|
169
|
+
>
|
|
170
|
+
<AppContent />
|
|
171
|
+
</MarkdownProvider>
|
|
172
|
+
);
|
|
153
173
|
```
|
|
154
174
|
|
|
155
|
-
|
|
175
|
+
> 如果没有提供 `MarkdownProvider`,Intlayer 将使用默认的 Markdown 转 JSX 解析器渲染 markdown。
|
|
176
|
+
|
|
177
|
+
您还可以使用 `.use()` 方法提供特定节点的局部覆盖:
|
|
156
178
|
|
|
157
179
|
```tsx
|
|
158
180
|
{myMarkdownContent.use({
|
|
159
|
-
h1: ({ children }) => <h1
|
|
181
|
+
h1: ({ children }) => <h1 style={{ color: "red" }}>{children}</h1>,
|
|
160
182
|
})}
|
|
161
183
|
```
|
|
162
184
|
|
|
185
|
+
您可以以字符串形式检索 Markdown:
|
|
186
|
+
|
|
187
|
+
```tsx
|
|
188
|
+
{myMarkdownContent.value}
|
|
189
|
+
{String(myMarkdownContent)}
|
|
190
|
+
{myMarkdownContent.toString()}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
您可以像这样访问您的 markdown 元数据:
|
|
194
|
+
|
|
195
|
+
```tsx
|
|
196
|
+
{myMarkdownContent.metadata}
|
|
197
|
+
{myMarkdownContent.metadata.title}
|
|
198
|
+
```
|
|
199
|
+
|
|
163
200
|
</Tab>
|
|
164
201
|
<Tab label="Vue" value="vue">
|
|
165
|
-
在 Vue 中,Markdown 内容可以使用内置的 `component`
|
|
202
|
+
在 Vue 中,Markdown 内容可以使用内置的 `component` 或直接作为节点来呈现。
|
|
166
203
|
|
|
167
204
|
```vue fileName="App.vue"
|
|
168
205
|
<script setup>
|
|
@@ -175,48 +212,188 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
175
212
|
</template>
|
|
176
213
|
```
|
|
177
214
|
|
|
215
|
+
通过 `intlayerMarkdown` 插件进行全局配置(支持 MDX 自定义组件):
|
|
216
|
+
|
|
217
|
+
```ts fileName="main.ts"
|
|
218
|
+
import { intlayerMarkdown } from "vue-intlayer/markdown";
|
|
219
|
+
|
|
220
|
+
app.use(intlayerMarkdown, {
|
|
221
|
+
components: {
|
|
222
|
+
h1: (props) => h('h1', { style: { color: 'green' } }, props.children),
|
|
223
|
+
MyButton: (props) => h('button', props), // MDX 组件
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
> 如果未安装 `intlayerMarkdown` 插件,Intlayer 将使用默认编译器进行渲染。
|
|
229
|
+
|
|
230
|
+
您还可以使用 `.use()` 方法提供特定节点的局部覆盖:
|
|
231
|
+
|
|
232
|
+
```vue
|
|
233
|
+
<component :is="myMarkdownContent.use({
|
|
234
|
+
h1: (props) => h('h1', { style: { color: 'red' } }, props.children),
|
|
235
|
+
})" />
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
您可以以字符串形式检索 Markdown:
|
|
239
|
+
|
|
240
|
+
```vue
|
|
241
|
+
{{ myMarkdownContent.value }}
|
|
242
|
+
{{ String(myMarkdownContent) }}
|
|
243
|
+
{{ myMarkdownContent.toString() }}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
您可以像这样访问您的 markdown 元数据:
|
|
247
|
+
|
|
248
|
+
```vue
|
|
249
|
+
<component :is="myMarkdownContent.metadata" />
|
|
250
|
+
<component :is="myMarkdownContent.metadata.title" />
|
|
251
|
+
```
|
|
252
|
+
|
|
178
253
|
</Tab>
|
|
179
254
|
<Tab label="Svelte" value="svelte">
|
|
180
|
-
Svelte
|
|
255
|
+
默认情况下,Svelte 将 Markdown 呈现为 HTML 字符串。使用 `{@html}` 来渲染它。
|
|
181
256
|
|
|
182
|
-
```svelte
|
|
257
|
+
```svelte fileName="App.svelte"
|
|
183
258
|
<script lang="ts">
|
|
184
259
|
import { useIntlayer } from "svelte-intlayer";
|
|
260
|
+
import { MarkdownProvider } from "svelte-intlayer/markdown";
|
|
261
|
+
import MyHeading from "./MyHeading.svelte";
|
|
262
|
+
|
|
185
263
|
const content = useIntlayer("app");
|
|
186
264
|
</script>
|
|
187
265
|
|
|
188
|
-
{
|
|
266
|
+
<MarkdownProvider components={{ h1: MyHeading }}>
|
|
267
|
+
{@html $content.myMarkdownContent}
|
|
268
|
+
</MarkdownProvider>
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
> 如果未提供 `MarkdownProvider`,Intlayer 将使用默认编译器渲染 markdown。
|
|
272
|
+
|
|
273
|
+
您还可以使用 `.use()` 方法提供特定节点的局部覆盖:
|
|
274
|
+
|
|
275
|
+
```svelte
|
|
276
|
+
{@html $content.myMarkdownContent.use({ ... })}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
您可以以字符串形式检索 Markdown:
|
|
280
|
+
|
|
281
|
+
```svelte
|
|
282
|
+
{$content.myMarkdownContent.value}
|
|
283
|
+
{String($content.myMarkdownContent)}
|
|
284
|
+
{$content.myMarkdownContent.toString()}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
您可以像这样访问您的 markdown 元数据:
|
|
288
|
+
|
|
289
|
+
```svelte
|
|
290
|
+
{$content.myMarkdownContent.metadata}
|
|
291
|
+
{$content.myMarkdownContent.metadata.title}
|
|
189
292
|
```
|
|
190
293
|
|
|
191
294
|
</Tab>
|
|
192
295
|
<Tab label="Preact" value="preact">
|
|
193
|
-
Preact
|
|
296
|
+
Preact 直接支持 JSX 中的 Markdown 节点。
|
|
194
297
|
|
|
195
298
|
```tsx fileName="App.tsx"
|
|
196
299
|
import { useIntlayer } from "preact-intlayer";
|
|
300
|
+
import { MarkdownProvider } from "preact-intlayer/markdown";
|
|
197
301
|
|
|
198
302
|
const AppContent = () => {
|
|
199
303
|
const { myMarkdownContent } = useIntlayer("app");
|
|
200
304
|
return <div>{myMarkdownContent}</div>;
|
|
201
305
|
};
|
|
306
|
+
|
|
307
|
+
const App = () => (
|
|
308
|
+
<MarkdownProvider
|
|
309
|
+
components={{
|
|
310
|
+
h1: ({ children }) => <h1 style={{ color: "red" }}>{children}</h1>,
|
|
311
|
+
MyButton: (props) => <button {...props} />, // MDX 组件
|
|
312
|
+
}}
|
|
313
|
+
>
|
|
314
|
+
<AppContent />
|
|
315
|
+
</MarkdownProvider>
|
|
316
|
+
);
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
> 如果未提供 `MarkdownProvider`,Intlayer 将使用默认的 Markdown 转 JSX 解析器渲染 markdown。
|
|
320
|
+
|
|
321
|
+
您还可以使用 `.use()` 方法提供特定节点的局部覆盖:
|
|
322
|
+
|
|
323
|
+
```tsx
|
|
324
|
+
{myMarkdownContent.use({
|
|
325
|
+
h1: ({ children }) => <h1 style={{ color: "red" }}>{children}</h1>,
|
|
326
|
+
})}
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
您可以以字符串形式检索 Markdown:
|
|
330
|
+
|
|
331
|
+
```tsx
|
|
332
|
+
{myMarkdownContent.value}
|
|
333
|
+
{String(myMarkdownContent)}
|
|
334
|
+
{myMarkdownContent.toString()}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
您可以像这样访问您的 markdown 元数据:
|
|
338
|
+
|
|
339
|
+
```tsx
|
|
340
|
+
{myMarkdownContent.metadata}
|
|
341
|
+
{myMarkdownContent.metadata.title}
|
|
202
342
|
```
|
|
203
343
|
|
|
204
344
|
</Tab>
|
|
205
345
|
<Tab label="Solid" value="solid">
|
|
206
|
-
Solid
|
|
346
|
+
Solid 直接支持 JSX 中的 Markdown 节点。
|
|
207
347
|
|
|
208
348
|
```tsx fileName="App.tsx"
|
|
209
349
|
import { useIntlayer } from "solid-intlayer";
|
|
350
|
+
import { MarkdownProvider } from "solid-intlayer/markdown";
|
|
210
351
|
|
|
211
352
|
const AppContent = () => {
|
|
212
353
|
const { myMarkdownContent } = useIntlayer("app");
|
|
213
354
|
return <div>{myMarkdownContent}</div>;
|
|
214
355
|
};
|
|
356
|
+
|
|
357
|
+
const App = () => (
|
|
358
|
+
<MarkdownProvider
|
|
359
|
+
components={{
|
|
360
|
+
h1: (props) => <h1 style={{ color: "red" }}>{props.children}</h1>,
|
|
361
|
+
MyButton: (props) => <button {...props} />, // MDX 组件
|
|
362
|
+
}}
|
|
363
|
+
>
|
|
364
|
+
<AppContent />
|
|
365
|
+
</MarkdownProvider>
|
|
366
|
+
);
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
> 如果未提供 `MarkdownProvider`,Intlayer 将使用默认的 Markdown 转 JSX 解析器渲染 markdown。
|
|
370
|
+
|
|
371
|
+
您还可以使用 `.use()` 方法提供特定节点的局部覆盖:
|
|
372
|
+
|
|
373
|
+
```tsx
|
|
374
|
+
{myMarkdownContent.use({
|
|
375
|
+
h1: (props) => <h1 style={{ color: "red" }}>{props.children}</h1>,
|
|
376
|
+
})}
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
您可以以字符串形式检索 Markdown:
|
|
380
|
+
|
|
381
|
+
```tsx
|
|
382
|
+
{myMarkdownContent.value}
|
|
383
|
+
{String(myMarkdownContent)}
|
|
384
|
+
{myMarkdownContent.toString()}
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
您可以像这样访问您的 markdown 元数据:
|
|
388
|
+
|
|
389
|
+
```tsx
|
|
390
|
+
{myMarkdownContent.metadata}
|
|
391
|
+
{myMarkdownContent.metadata.title}
|
|
215
392
|
```
|
|
216
393
|
|
|
217
394
|
</Tab>
|
|
218
395
|
<Tab label="Angular" value="angular">
|
|
219
|
-
Angular 使用 `[innerHTML]`
|
|
396
|
+
Angular 使用 `[innerHTML]` 指令来呈现 Markdown 内容。
|
|
220
397
|
|
|
221
398
|
```typescript fileName="app.component.ts"
|
|
222
399
|
import { Component } from "@angular/core";
|
|
@@ -231,7 +408,9 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
231
408
|
}
|
|
232
409
|
```
|
|
233
410
|
|
|
234
|
-
|
|
411
|
+
> 如果未配置 IntlayerMarkdown 提供程序,Intlayer 将使用默认编译器进行渲染。
|
|
412
|
+
|
|
413
|
+
您还可以使用 `.use()` 方法提供特定节点的局部覆盖:
|
|
235
414
|
|
|
236
415
|
```typescript
|
|
237
416
|
content().myMarkdownContent.use({
|
|
@@ -239,12 +418,27 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
239
418
|
})
|
|
240
419
|
```
|
|
241
420
|
|
|
421
|
+
您可以以字符串形式检索 Markdown:
|
|
422
|
+
|
|
423
|
+
```typescript
|
|
424
|
+
content().myMarkdownContent.value
|
|
425
|
+
String(content().myMarkdownContent)
|
|
426
|
+
content().myMarkdownContent.toString()
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
您可以像这样访问您的 markdown 元数据:
|
|
430
|
+
|
|
431
|
+
```typescript
|
|
432
|
+
content().myMarkdownContent.metadata
|
|
433
|
+
content().myMarkdownContent.metadata.title
|
|
434
|
+
```
|
|
435
|
+
|
|
242
436
|
</Tab>
|
|
243
437
|
</Tabs>
|
|
244
438
|
|
|
245
|
-
### 2.
|
|
439
|
+
### 2. 辅助实用程序(仅限 Markdown 字符串)
|
|
246
440
|
|
|
247
|
-
|
|
441
|
+
这些实用程序渲染 **仅限原始 Markdown 字符串** 且独立于 `useIntlayer`。当您需要从词典以外的来源渲染 Markdown 时使用它们。
|
|
248
442
|
|
|
249
443
|
<Tabs group="framework">
|
|
250
444
|
<Tab label="React / Next.js" value="react">
|
|
@@ -261,7 +455,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
261
455
|
</MarkdownRenderer>
|
|
262
456
|
```
|
|
263
457
|
|
|
264
|
-
#### `useMarkdownRenderer()`
|
|
458
|
+
#### `useMarkdownRenderer()` 钩子
|
|
265
459
|
|
|
266
460
|
获取预配置的渲染器函数。
|
|
267
461
|
|
|
@@ -276,8 +470,8 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
276
470
|
return renderMarkdown("# 我的标题");
|
|
277
471
|
```
|
|
278
472
|
|
|
279
|
-
#### `renderMarkdown()`
|
|
280
|
-
|
|
473
|
+
#### `renderMarkdown()` 实用程序
|
|
474
|
+
组件外部渲染的独立实用程序。
|
|
281
475
|
|
|
282
476
|
```tsx
|
|
283
477
|
import { renderMarkdown } from "react-intlayer/markdown";
|
|
@@ -313,7 +507,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
313
507
|
<MarkdownRenderer forceBlock={true} value="# 我的标题" />
|
|
314
508
|
```
|
|
315
509
|
|
|
316
|
-
#### `useMarkdownRenderer()`
|
|
510
|
+
#### `useMarkdownRenderer()` 钩子
|
|
317
511
|
|
|
318
512
|
```svelte
|
|
319
513
|
<script lang="ts">
|
|
@@ -324,7 +518,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
324
518
|
{@html render("# 我的标题")}
|
|
325
519
|
```
|
|
326
520
|
|
|
327
|
-
#### `renderMarkdown()`
|
|
521
|
+
#### `renderMarkdown()` 实用程序
|
|
328
522
|
|
|
329
523
|
```svelte
|
|
330
524
|
<script lang="ts">
|
|
@@ -346,7 +540,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
346
540
|
</MarkdownRenderer>
|
|
347
541
|
```
|
|
348
542
|
|
|
349
|
-
#### `useMarkdownRenderer()`
|
|
543
|
+
#### `useMarkdownRenderer()` 钩子
|
|
350
544
|
|
|
351
545
|
```tsx
|
|
352
546
|
import { useMarkdownRenderer } from "preact-intlayer/markdown";
|
|
@@ -356,7 +550,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
356
550
|
return <div>{render("# 我的标题")}</div>;
|
|
357
551
|
```
|
|
358
552
|
|
|
359
|
-
#### `renderMarkdown()`
|
|
553
|
+
#### `renderMarkdown()` 实用程序
|
|
360
554
|
|
|
361
555
|
```tsx
|
|
362
556
|
import { renderMarkdown } from "preact-intlayer/markdown";
|
|
@@ -376,7 +570,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
376
570
|
</MarkdownRenderer>
|
|
377
571
|
```
|
|
378
572
|
|
|
379
|
-
#### `useMarkdownRenderer()`
|
|
573
|
+
#### `useMarkdownRenderer()` 钩子
|
|
380
574
|
|
|
381
575
|
```tsx
|
|
382
576
|
import { useMarkdownRenderer } from "solid-intlayer/markdown";
|
|
@@ -386,7 +580,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
386
580
|
return <div>{render("# 我的标题")}</div>;
|
|
387
581
|
```
|
|
388
582
|
|
|
389
|
-
#### `renderMarkdown()`
|
|
583
|
+
#### `renderMarkdown()` 实用程序
|
|
390
584
|
|
|
391
585
|
```tsx
|
|
392
586
|
import { renderMarkdown } from "solid-intlayer/markdown";
|
|
@@ -397,7 +591,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
397
591
|
</Tab>
|
|
398
592
|
<Tab label="Angular" value="angular">
|
|
399
593
|
#### `IntlayerMarkdownService` 服务
|
|
400
|
-
|
|
594
|
+
使用服务呈现 Markdown 字符串。
|
|
401
595
|
|
|
402
596
|
```typescript
|
|
403
597
|
import { IntlayerMarkdownService } from "angular-intlayer/markdown";
|
|
@@ -416,9 +610,9 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
416
610
|
|
|
417
611
|
---
|
|
418
612
|
|
|
419
|
-
## 使用 `MarkdownProvider`
|
|
613
|
+
## 使用 `MarkdownProvider` 进行全局配置
|
|
420
614
|
|
|
421
|
-
|
|
615
|
+
`MarkdownProvider`(或其框架对应的组件)为整个应用程序配置 Markdown 渲染管道。它适用于自动 `useIntlayer` 渲染和辅助实用程序。此处设置的选项为默认值 — `.use()` 在节点级别将其覆盖。
|
|
422
616
|
|
|
423
617
|
<Tabs group="framework">
|
|
424
618
|
<Tab label="React / Next.js" value="react">
|
|
@@ -429,8 +623,9 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
429
623
|
export const AppProvider = ({ children }) => (
|
|
430
624
|
<MarkdownProvider
|
|
431
625
|
components={{
|
|
432
|
-
h1: (
|
|
433
|
-
a: ({ href,
|
|
626
|
+
h1: (props) => <h1 style={{color: 'green'}} {...props} />,
|
|
627
|
+
a: ({ href, ...props }) => <a style={{color: 'red'}} {...props} />,
|
|
628
|
+
MyCustomJSXComponent: (props) => <span style={{color: 'red'}} {...props} />,
|
|
434
629
|
}}
|
|
435
630
|
>
|
|
436
631
|
{children}
|
|
@@ -438,7 +633,9 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
438
633
|
);
|
|
439
634
|
```
|
|
440
635
|
|
|
441
|
-
|
|
636
|
+
> 支持 MDX — Markdown 内部使用的任何组件名称(例如 `<MyCustomJSXComponent />`)都会根据 `components` 映射进行解析。
|
|
637
|
+
|
|
638
|
+
您还可以使用自己的 markdown 渲染器:
|
|
442
639
|
|
|
443
640
|
```tsx fileName="AppProvider.tsx"
|
|
444
641
|
import { MarkdownProvider } from "react-intlayer/markdown";
|
|
@@ -446,8 +643,8 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
446
643
|
export const AppProvider = ({ children }) => (
|
|
447
644
|
<MarkdownProvider
|
|
448
645
|
renderMarkdown={async (md) => {
|
|
449
|
-
const {
|
|
450
|
-
return
|
|
646
|
+
const { renderMarkdown } = await import('react-intlayer/markdown');
|
|
647
|
+
return renderMarkdown(md);
|
|
451
648
|
}}
|
|
452
649
|
>
|
|
453
650
|
{children}
|
|
@@ -455,7 +652,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
455
652
|
);
|
|
456
653
|
```
|
|
457
654
|
|
|
458
|
-
>
|
|
655
|
+
> 动态导入您的 Markdown 渲染器是减少应用程序包大小的好方法。
|
|
459
656
|
|
|
460
657
|
</Tab>
|
|
461
658
|
<Tab label="Vue" value="vue">
|
|
@@ -472,7 +669,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
472
669
|
app.use(intlayerMarkdown, {
|
|
473
670
|
components: {
|
|
474
671
|
h1: (props) =>
|
|
475
|
-
|
|
672
|
+
h('h1', { style: { color: 'orange' }, ...props }, props.children),
|
|
476
673
|
ComponentDemo: () => h('div', { style: { background: 'grey' } }, 'DEMO'),
|
|
477
674
|
bold: (props) => h('strong', props),
|
|
478
675
|
code: (props) => h('code', props),
|
|
@@ -482,7 +679,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
482
679
|
app.mount("#app");
|
|
483
680
|
```
|
|
484
681
|
|
|
485
|
-
|
|
682
|
+
您还可以使用自己的 markdown 渲染器:
|
|
486
683
|
|
|
487
684
|
```typescript fileName="main.ts"
|
|
488
685
|
import { createApp } from "vue";
|
|
@@ -495,15 +692,15 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
495
692
|
app.use(intlayer);
|
|
496
693
|
app.use(intlayerMarkdown, {
|
|
497
694
|
renderMarkdown: async (md) => {
|
|
498
|
-
const {
|
|
499
|
-
return
|
|
695
|
+
const { renderMarkdown } = await import('vue-intlayer/markdown');
|
|
696
|
+
return renderMarkdown(md);
|
|
500
697
|
},
|
|
501
698
|
});
|
|
502
699
|
|
|
503
700
|
app.mount("#app");
|
|
504
701
|
```
|
|
505
702
|
|
|
506
|
-
>
|
|
703
|
+
> 动态导入您的 Markdown 渲染器是减少应用程序包大小的好方法。
|
|
507
704
|
|
|
508
705
|
</Tab>
|
|
509
706
|
<Tab label="Svelte" value="svelte">
|
|
@@ -523,7 +720,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
523
720
|
</MarkdownProvider>
|
|
524
721
|
```
|
|
525
722
|
|
|
526
|
-
|
|
723
|
+
您还可以使用自己的 markdown 渲染器:
|
|
527
724
|
|
|
528
725
|
```svelte fileName="App.svelte"
|
|
529
726
|
<script lang="ts">
|
|
@@ -532,15 +729,15 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
532
729
|
|
|
533
730
|
<MarkdownProvider
|
|
534
731
|
renderMarkdown={async (md) => {
|
|
535
|
-
const {
|
|
536
|
-
return
|
|
732
|
+
const { renderMarkdown } = await import('svelte-intlayer/markdown');
|
|
733
|
+
return renderMarkdown(md);
|
|
537
734
|
}}
|
|
538
735
|
>
|
|
539
736
|
<slot />
|
|
540
737
|
</MarkdownProvider>
|
|
541
738
|
```
|
|
542
739
|
|
|
543
|
-
>
|
|
740
|
+
> 动态导入您的 Markdown 渲染器是减少应用程序包大小的好方法。
|
|
544
741
|
|
|
545
742
|
</Tab>
|
|
546
743
|
<Tab label="Preact" value="preact">
|
|
@@ -559,7 +756,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
559
756
|
);
|
|
560
757
|
```
|
|
561
758
|
|
|
562
|
-
|
|
759
|
+
您还可以使用自己的 markdown 渲染器:
|
|
563
760
|
|
|
564
761
|
```tsx fileName="AppProvider.tsx"
|
|
565
762
|
import { MarkdownProvider } from "preact-intlayer/markdown";
|
|
@@ -567,8 +764,8 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
567
764
|
export const AppProvider = ({ children }) => (
|
|
568
765
|
<MarkdownProvider
|
|
569
766
|
renderMarkdown={async (md) => {
|
|
570
|
-
const {
|
|
571
|
-
return
|
|
767
|
+
const { renderMarkdown } = await import('preact-intlayer/markdown');
|
|
768
|
+
return renderMarkdown(md);
|
|
572
769
|
}}
|
|
573
770
|
>
|
|
574
771
|
{children}
|
|
@@ -576,7 +773,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
576
773
|
);
|
|
577
774
|
```
|
|
578
775
|
|
|
579
|
-
>
|
|
776
|
+
> 动态导入您的 Markdown 渲染器是减少应用程序包大小的好方法。
|
|
580
777
|
|
|
581
778
|
</Tab>
|
|
582
779
|
<Tab label="Solid" value="solid">
|
|
@@ -595,7 +792,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
595
792
|
);
|
|
596
793
|
```
|
|
597
794
|
|
|
598
|
-
|
|
795
|
+
您还可以使用自己的 markdown 渲染器:
|
|
599
796
|
|
|
600
797
|
```tsx fileName="AppProvider.tsx"
|
|
601
798
|
import { MarkdownProvider } from "solid-intlayer/markdown";
|
|
@@ -603,8 +800,8 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
603
800
|
export const AppProvider = (props) => (
|
|
604
801
|
<MarkdownProvider
|
|
605
802
|
renderMarkdown={async (md) => {
|
|
606
|
-
const {
|
|
607
|
-
return
|
|
803
|
+
const { renderMarkdown } = await import('solid-intlayer/markdown');
|
|
804
|
+
return renderMarkdown(md);
|
|
608
805
|
}}
|
|
609
806
|
>
|
|
610
807
|
{props.children}
|
|
@@ -612,59 +809,29 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
612
809
|
);
|
|
613
810
|
```
|
|
614
811
|
|
|
615
|
-
>
|
|
812
|
+
> 动态导入您的 Markdown 渲染器是减少应用程序包大小的好方法。
|
|
616
813
|
|
|
617
814
|
</Tab>
|
|
618
815
|
<Tab label="Angular" value="angular">
|
|
619
816
|
|
|
620
|
-
```typescript fileName="app.
|
|
621
|
-
import {
|
|
622
|
-
|
|
623
|
-
export const appConfig: ApplicationConfig = {
|
|
624
|
-
providers: [
|
|
625
|
-
createIntlayerMarkdownProvider({
|
|
626
|
-
components: {
|
|
627
|
-
h1: { class: "text-2xl font-bold" },
|
|
628
|
-
},
|
|
629
|
-
}),
|
|
630
|
-
],
|
|
631
|
-
};
|
|
632
|
-
```
|
|
633
|
-
|
|
634
|
-
您也可以使用自己的 Markdown 渲染器:
|
|
635
|
-
|
|
636
|
-
```typescript fileName="app.config.ts"
|
|
637
|
-
import { createIntlayerMarkdownProvider } from "angular-intlayer/markdown";
|
|
817
|
+
```typescript fileName="app.module.ts"
|
|
818
|
+
import { NgModule } from '@angular/core';
|
|
819
|
+
import { IntlayerMarkdownModule } from 'angular-intlayer/markdown';
|
|
638
820
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
821
|
+
@NgModule({
|
|
822
|
+
imports: [
|
|
823
|
+
IntlayerMarkdownModule.forRoot({
|
|
642
824
|
renderMarkdown: async (md) => {
|
|
643
|
-
const {
|
|
644
|
-
return
|
|
645
|
-
}
|
|
646
|
-
})
|
|
647
|
-
]
|
|
648
|
-
}
|
|
825
|
+
const { renderMarkdown } = await import('angular-intlayer/markdown');
|
|
826
|
+
return renderMarkdown(md);
|
|
827
|
+
}
|
|
828
|
+
})
|
|
829
|
+
]
|
|
830
|
+
})
|
|
831
|
+
export class AppModule {}
|
|
649
832
|
```
|
|
650
833
|
|
|
651
|
-
>
|
|
834
|
+
> 动态导入您的 Markdown 渲染器是减少应用程序包大小的好方法。
|
|
652
835
|
|
|
653
836
|
</Tab>
|
|
654
837
|
</Tabs>
|
|
655
|
-
|
|
656
|
-
---
|
|
657
|
-
|
|
658
|
-
## 选项参考
|
|
659
|
-
|
|
660
|
-
这些选项可以传递给 `MarkdownProvider`、`MarkdownRenderer`、`useMarkdownRenderer` 和 `renderMarkdown`。
|
|
661
|
-
|
|
662
|
-
| 选项 | 类型 | 默认 | 说明 |
|
|
663
|
-
| :-------------------- | :---------- | :------ | :-------------------------------------------------------------- |
|
|
664
|
-
| `forceBlock` | `boolean` | `false` | 强制将输出包裹在块级元素中(例如 `<div>`)。 |
|
|
665
|
-
| `forceInline` | `boolean` | `false` | 强制将输出包裹在内联元素中(例如 `<span>`)。 |
|
|
666
|
-
| `tagfilter` | `boolean` | `true` | 启用 GitHub 标签过滤器,通过剥离危险的 HTML 标签来提高安全性。 |
|
|
667
|
-
| `preserveFrontmatter` | `boolean` | `false` | 如果为 `true`,Markdown 字符串开头的 frontmatter 将不会被剥离。 |
|
|
668
|
-
| `components` | `Overrides` | `{}` | HTML 标签到自定义组件的映射(例如 `{ h1: MyHeading }`)。 |
|
|
669
|
-
| `wrapper` | `Component` | `null` | 用于包裹渲染后的 Markdown 的自定义组件。 |
|
|
670
|
-
| `renderMarkdown` | `Function` | `null` | 一个自定义渲染函数,用于完全替换默认的 Markdown 编译器。 |
|