通过修改配置内容和标识符来生成不同类型的markdown代码块。这些示例展示了各种标识符的基本用法和语法结构。
1.散点图
import json
def main():
echarts_config = {
"title": {"text": "简单散点图"},
"xAxis": {"type": "value"},
"yAxis": {"type": "value"},
"series": [{
"type": "scatter",
"data": [[1, 2], [3, 4], [5, 6]]
}]
}
output = "```echarts\n" + json.dumps(echarts_config, indent=2, ensure_ascii=False) + "\n```"
return {"output": output}
result = main()
print(result)
```
## 2. mermaid (流程图)
```python
import json
def main():
mermaid_config = """graph TD
A[开始] --> B{判断}
B -->|是| C[处理]
B -->|否| D[结束]
C --> D"""
output = "```mermaid\n" + mermaid_config + "\n```"
return {"output": output}
result = main()
print(result)
```
## 3. plantuml (时序图)
```python
import json
def main():
plantuml_config = """@startuml
Alice -> Bob: Hello
Bob --> Alice: Hi there
@enduml"""
output = "```plantuml\n" + plantuml_config + "\n```"
return {"output": output}
result = main()
print(result)
```
## 4. graphviz (有向图)
```python
import json
def main():
graphviz_config = """digraph G {
A -> B;
B -> C;
C -> A;
}"""
output = "```graphviz\n" + graphviz_config + "\n```"
return {"output": output}
result = main()
print(result)
```
## 5. vega-lite (柱状图)
```python
import json
def main():
vega_config = {
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {"values": [
{"category": "A", "value": 10},
{"category": "B", "value": 20},
{"category": "C", "value": 15}
]},
"mark": "bar",
"encoding": {
"x": {"field": "category"},
"y": {"field": "value"}
}
}
output = "```vega-lite\n" + json.dumps(vega_config, indent=2, ensure_ascii=False) + "\n```"
return {"output": output}
result = main()
print(result)
```
## 6. plotly (线图)
```python
import json
def main():
plotly_config = {
"data": [{
"type": "scatter",
"mode": "lines",
"x": [1, 2, 3, 4],
"y": [10, 11, 12, 13]
}],
"layout": {"title": "简单线图"}
}
output = "```plotly\n" + json.dumps(plotly_config, indent=2, ensure_ascii=False) + "\n```"
return {"output": output}
result = main()
print(result)
```
## 7. chartjs (饼图)
```python
import json
def main():
chartjs_config = {
"type": "pie",
"data": {
"labels": ["红色", "蓝色", "黄色"],
"datasets": [{
"data": [30, 50, 20],
"backgroundColor": ["#FF6384", "#36A2EB", "#FFCE56"]
}]
}
}
output = "```chartjs\n" + json.dumps(chartjs_config, indent=2, ensure_ascii=False) + "\n```"
return {"output": output}
result = main()
print(result)
```
## 8. d3 (简单可视化)
```python
import json
def main():
d3_code = """// 创建SVG
var svg = d3.select("body").append("svg")
.attr("width", 200)
.attr("height", 200);
// 添加圆形
svg.append("circle")
.attr("cx", 100)
.attr("cy", 100)
.attr("r", 50)
.style("fill", "blue");"""
output = "```d3\n" + d3_code + "\n```"
return {"output": output}
result = main()
print(result)
```
## 9. javascript (函数)
```python
import json
def main():
js_code = """function greet(name) {
console.log('Hello, ' + name + '!');
}
greet('World');"""
output = "```javascript\n" + js_code + "\n```"
return {"output": output}
result = main()
print(result)
```
## 10. python (列表操作)
```python
import json
def main():
python_code = """# 列表操作示例
numbers = [1, 2, 3, 4, 5]
squares = [x**2 for x in numbers]
print(squares)"""
output = "```python\n" + python_code + "\n```"
return {"output": output}
result = main()
print(result)
```
## 11. json (数据结构)
```python
import json
def main():
json_data = {
"name": "张三",
"age": 25,
"skills": ["Python", "JavaScript", "SQL"]
}
output = "```json\n" + json.dumps(json_data, indent=2, ensure_ascii=False) + "\n```"
return {"output": output}
result = main()
print(result)
```
## 12. yaml (配置)
```python
import json
def main():
yaml_config = """server:
host: localhost
port: 8080
database:
name: mydb
user: admin"""
output = "```yaml\n" + yaml_config + "\n```"
return {"output": output}
result = main()
print(result)
```
## 13. math (LaTeX数学公式)
```python
import json
def main():
latex_formula = r"""\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}"""
output = "```math\n" + latex_formula + "\n```"
return {"output": output}
result = main()
print(result)
```
在dify 中 可以使用 echarts (散点图)、mermaid (流程图)、 math (LaTeX数学公式)