@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.
- package/docs/ar/dictionary/markdown.md +409 -88
- package/docs/de/dictionary/markdown.md +279 -107
- package/docs/en/dictionary/markdown.md +237 -37
- package/docs/en-GB/dictionary/markdown.md +361 -76
- package/docs/es/dictionary/markdown.md +295 -123
- package/docs/fr/dictionary/markdown.md +301 -129
- package/docs/hi/dictionary/markdown.md +376 -90
- package/docs/id/dictionary/markdown.md +377 -91
- package/docs/it/dictionary/markdown.md +296 -129
- package/docs/ko/dictionary/markdown.md +306 -134
- package/docs/pl/dictionary/markdown.md +287 -116
- package/docs/pt/dictionary/markdown.md +287 -116
- package/docs/ru/dictionary/markdown.md +78 -513
- package/docs/tr/dictionary/markdown.md +300 -130
- package/docs/uk/dictionary/markdown.md +386 -100
- package/docs/vi/dictionary/markdown.md +383 -97
- package/docs/zh/dictionary/markdown.md +293 -125
- 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";
|
|
@@ -95,33 +95,34 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
95
95
|
```
|
|
96
96
|
|
|
97
97
|
</Tab>
|
|
98
|
-
<Tab label="
|
|
99
|
-
|
|
98
|
+
<Tab label="外部文件" value="external-files">
|
|
99
|
+
使用 `file` 函数直接导入 `.md` 文件。
|
|
100
100
|
|
|
101
101
|
```typescript fileName="markdownDictionary.content.ts"
|
|
102
|
+
import { md, file, t } from "intlayer";
|
|
103
|
+
|
|
102
104
|
export default {
|
|
103
105
|
key: "app",
|
|
104
|
-
contentAutoTransformation: true, // 启用 Markdown 内容的自动检测 - 可在 intlayer.config.ts 中全局设置
|
|
105
106
|
content: {
|
|
106
|
-
|
|
107
|
+
content: t({
|
|
108
|
+
en: md(file("./myMarkdown.en.md")),
|
|
109
|
+
zh: md(file("./myMarkdown.zh.md")),
|
|
110
|
+
}),
|
|
107
111
|
},
|
|
108
112
|
};
|
|
109
113
|
```
|
|
110
114
|
|
|
111
115
|
</Tab>
|
|
112
|
-
<Tab label="外部文件">
|
|
113
|
-
使用 `file` 函数直接导入 `.md` 文件。
|
|
114
116
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
<Tab label="自动检测" value="automatic-detection">
|
|
118
|
+
如果字符串包含常见的 Markdown 指示符(如标题、列表、链接等),Intlayer 会自动转换它。
|
|
117
119
|
|
|
120
|
+
```typescript fileName="markdownDictionary.content.ts"
|
|
118
121
|
export default {
|
|
119
122
|
key: "app",
|
|
123
|
+
contentAutoTransformation: true, // 启用 Markdown 内容的自动检测 - 可以在 intlayer.config.ts 中全局设置
|
|
120
124
|
content: {
|
|
121
|
-
|
|
122
|
-
en: md(file("./myMarkdown.en.md")),
|
|
123
|
-
fr: md(file("./myMarkdown.fr.md")),
|
|
124
|
-
}),
|
|
125
|
+
myMarkdownContent: "## 我的标题 \n\nLorem Ipsum",
|
|
125
126
|
},
|
|
126
127
|
};
|
|
127
128
|
```
|
|
@@ -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,9 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
446
643
|
export const AppProvider = ({ children }) => (
|
|
447
644
|
<MarkdownProvider
|
|
448
645
|
renderMarkdown={async (md) => {
|
|
449
|
-
|
|
450
|
-
|
|
646
|
+
// Use dynamic import to reduce the bundle size of your application
|
|
647
|
+
const { renderMarkdown } = await import('react-intlayer/markdown');
|
|
648
|
+
return renderMarkdown(md);
|
|
451
649
|
}}
|
|
452
650
|
>
|
|
453
651
|
{children}
|
|
@@ -455,7 +653,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
455
653
|
);
|
|
456
654
|
```
|
|
457
655
|
|
|
458
|
-
>
|
|
656
|
+
> 动态导入您的 Markdown 渲染器是减少应用程序包大小的好方法。
|
|
459
657
|
|
|
460
658
|
</Tab>
|
|
461
659
|
<Tab label="Vue" value="vue">
|
|
@@ -472,7 +670,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
472
670
|
app.use(intlayerMarkdown, {
|
|
473
671
|
components: {
|
|
474
672
|
h1: (props) =>
|
|
475
|
-
|
|
673
|
+
h('h1', { style: { color: 'orange' }, ...props }, props.children),
|
|
476
674
|
ComponentDemo: () => h('div', { style: { background: 'grey' } }, 'DEMO'),
|
|
477
675
|
bold: (props) => h('strong', props),
|
|
478
676
|
code: (props) => h('code', props),
|
|
@@ -482,7 +680,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
482
680
|
app.mount("#app");
|
|
483
681
|
```
|
|
484
682
|
|
|
485
|
-
|
|
683
|
+
您还可以使用自己的 markdown 渲染器:
|
|
486
684
|
|
|
487
685
|
```typescript fileName="main.ts"
|
|
488
686
|
import { createApp } from "vue";
|
|
@@ -495,15 +693,15 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
495
693
|
app.use(intlayer);
|
|
496
694
|
app.use(intlayerMarkdown, {
|
|
497
695
|
renderMarkdown: async (md) => {
|
|
498
|
-
const {
|
|
499
|
-
return
|
|
696
|
+
const { renderMarkdown } = await import('vue-intlayer/markdown');
|
|
697
|
+
return renderMarkdown(md);
|
|
500
698
|
},
|
|
501
699
|
});
|
|
502
700
|
|
|
503
701
|
app.mount("#app");
|
|
504
702
|
```
|
|
505
703
|
|
|
506
|
-
>
|
|
704
|
+
> 动态导入您的 Markdown 渲染器是减少应用程序包大小的好方法。
|
|
507
705
|
|
|
508
706
|
</Tab>
|
|
509
707
|
<Tab label="Svelte" value="svelte">
|
|
@@ -523,7 +721,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
523
721
|
</MarkdownProvider>
|
|
524
722
|
```
|
|
525
723
|
|
|
526
|
-
|
|
724
|
+
您还可以使用自己的 markdown 渲染器:
|
|
527
725
|
|
|
528
726
|
```svelte fileName="App.svelte"
|
|
529
727
|
<script lang="ts">
|
|
@@ -532,15 +730,15 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
532
730
|
|
|
533
731
|
<MarkdownProvider
|
|
534
732
|
renderMarkdown={async (md) => {
|
|
535
|
-
const {
|
|
536
|
-
return
|
|
733
|
+
const { renderMarkdown } = await import('svelte-intlayer/markdown');
|
|
734
|
+
return renderMarkdown(md);
|
|
537
735
|
}}
|
|
538
736
|
>
|
|
539
737
|
<slot />
|
|
540
738
|
</MarkdownProvider>
|
|
541
739
|
```
|
|
542
740
|
|
|
543
|
-
>
|
|
741
|
+
> 动态导入您的 Markdown 渲染器是减少应用程序包大小的好方法。
|
|
544
742
|
|
|
545
743
|
</Tab>
|
|
546
744
|
<Tab label="Preact" value="preact">
|
|
@@ -559,7 +757,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
559
757
|
);
|
|
560
758
|
```
|
|
561
759
|
|
|
562
|
-
|
|
760
|
+
您还可以使用自己的 markdown 渲染器:
|
|
563
761
|
|
|
564
762
|
```tsx fileName="AppProvider.tsx"
|
|
565
763
|
import { MarkdownProvider } from "preact-intlayer/markdown";
|
|
@@ -567,8 +765,8 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
567
765
|
export const AppProvider = ({ children }) => (
|
|
568
766
|
<MarkdownProvider
|
|
569
767
|
renderMarkdown={async (md) => {
|
|
570
|
-
const {
|
|
571
|
-
return
|
|
768
|
+
const { renderMarkdown } = await import('preact-intlayer/markdown');
|
|
769
|
+
return renderMarkdown(md);
|
|
572
770
|
}}
|
|
573
771
|
>
|
|
574
772
|
{children}
|
|
@@ -576,7 +774,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
576
774
|
);
|
|
577
775
|
```
|
|
578
776
|
|
|
579
|
-
>
|
|
777
|
+
> 动态导入您的 Markdown 渲染器是减少应用程序包大小的好方法。
|
|
580
778
|
|
|
581
779
|
</Tab>
|
|
582
780
|
<Tab label="Solid" value="solid">
|
|
@@ -595,7 +793,7 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
595
793
|
);
|
|
596
794
|
```
|
|
597
795
|
|
|
598
|
-
|
|
796
|
+
您还可以使用自己的 markdown 渲染器:
|
|
599
797
|
|
|
600
798
|
```tsx fileName="AppProvider.tsx"
|
|
601
799
|
import { MarkdownProvider } from "solid-intlayer/markdown";
|
|
@@ -603,8 +801,8 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
603
801
|
export const AppProvider = (props) => (
|
|
604
802
|
<MarkdownProvider
|
|
605
803
|
renderMarkdown={async (md) => {
|
|
606
|
-
const {
|
|
607
|
-
return
|
|
804
|
+
const { renderMarkdown } = await import('solid-intlayer/markdown');
|
|
805
|
+
return renderMarkdown(md);
|
|
608
806
|
}}
|
|
609
807
|
>
|
|
610
808
|
{props.children}
|
|
@@ -612,59 +810,29 @@ Intlayer 支持使用 Markdown 语法定义的富文本内容。这允许您轻
|
|
|
612
810
|
);
|
|
613
811
|
```
|
|
614
812
|
|
|
615
|
-
>
|
|
813
|
+
> 动态导入您的 Markdown 渲染器是减少应用程序包大小的好方法。
|
|
616
814
|
|
|
617
815
|
</Tab>
|
|
618
816
|
<Tab label="Angular" value="angular">
|
|
619
817
|
|
|
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 渲染器:
|
|
818
|
+
```typescript fileName="app.module.ts"
|
|
819
|
+
import { NgModule } from '@angular/core';
|
|
820
|
+
import { IntlayerMarkdownModule } from 'angular-intlayer/markdown';
|
|
635
821
|
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
export const appConfig: ApplicationConfig = {
|
|
640
|
-
providers: [
|
|
641
|
-
createIntlayerMarkdownProvider({
|
|
822
|
+
@NgModule({
|
|
823
|
+
imports: [
|
|
824
|
+
IntlayerMarkdownModule.forRoot({
|
|
642
825
|
renderMarkdown: async (md) => {
|
|
643
|
-
const {
|
|
644
|
-
return
|
|
645
|
-
}
|
|
646
|
-
})
|
|
647
|
-
]
|
|
648
|
-
}
|
|
826
|
+
const { renderMarkdown } = await import('angular-intlayer/markdown');
|
|
827
|
+
return renderMarkdown(md);
|
|
828
|
+
}
|
|
829
|
+
})
|
|
830
|
+
]
|
|
831
|
+
})
|
|
832
|
+
export class AppModule {}
|
|
649
833
|
```
|
|
650
834
|
|
|
651
|
-
>
|
|
835
|
+
> 动态导入您的 Markdown 渲染器是减少应用程序包大小的好方法。
|
|
652
836
|
|
|
653
837
|
</Tab>
|
|
654
838
|
</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 编译器。 |
|