amis2/docs/zh-CN/components/markdown.md
吴多益 060e1b9f8a
feat: markdown 增加 src 属性支持加载外部文件 Closes #3533 (#3553)
* feat: markdown 增加 src 属性支持加载外部文件 Closes #3533

* 改成 isApiOutdated 判断
2022-02-10 14:19:40 +08:00

92 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Markdown 渲染
description:
type: 0
group: ⚙ 组件
menuName: Markdown 渲染
icon:
order: 58
---
> 1.1.6 版本开始
## 基本用法
```schema
{
"type": "page",
"body": {
"type": "markdown",
"value": "# title\n markdown **text**"
}
}
```
## 动态数据
动态数据可以通过 name 来关联,类似 [static](form/static) 组件
## 基于 Editor 和数据联动来实现预览功能
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "group",
"body": [
{
"type": "editor",
"name": "md",
"language": "markdown"
},
{
"type": "markdown",
"name": "md"
}
]
}
]
}
```
## 加载外部 markdown 文件
> 1.6.5 及以上版本
可以通过 `src` 属性来加载外部 markdown 文件,比如
```schema: scope="body"
{
"type": "markdown",
"src": "/api/mock2/sample/mirror?json=%7B%22status%22%3A0%2C%22data%22%3A%22%23%23%20title%20%5Cn%20content%22%7D"
}
```
这个接口的返回格式可以是两种,一种是 JSON类似
```
{
"status": 0,
"msg": "",
"data": "markdown"
}
```
另一种是返回 `content-type``text/markdown``text/x-markdown` 的纯文本。
## 视频
可以使用 `![text](video.mp4)` 语法来嵌入视频。
## 属性表
| 属性名 | 类型 | 默认值 | 说明 |
| --------- | -------- | ------ | -------- |
| name | `string` | | 名称 |
| value | `string` | | 静态值 |
| className | `string` | | 类名 |
| src | `Api` | | 外部地址 |