markdown的使用

通过修改配置内容和标识符来生成不同类型的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数学公式)

相关推荐
PC2005-cloud17 分钟前
Mysql学习笔记:InnoDB Cluster 集群从零搭建实战,基于 Docker 实现高可用读写分离架构
笔记·学习·mysql
小陈phd29 分钟前
深入理解agent学习笔记(七)——动态提示词与Skills
笔记·学习
我命由我1234529 分钟前
田野笔记极简理解
经验分享·笔记·学习·职场和发展·求职招聘·职场发展·学习方法
小陈phd1 小时前
深入理解agent学习笔记(六)——提示工程-优化系统提示词
笔记·学习
霖霖7141 小时前
【ESP32笔记】RGB灯WS2812实验
笔记·单片机·mcu·物联网
Aurora_eye1 小时前
Git 笔记
笔记·git
yi0112 小时前
DAY28: LeetCode 111. 二叉树的最小深度
人工智能·笔记·python·算法·leetcode·二叉树·递归
xxwl5852 小时前
三、区域赛算法模版第三章---字符串相关算法
笔记·学习·算法
卿卿的产品经理日记3 小时前
【AI产品经理实战】Day 37|拆开 JSON 与 EXE:数据都有格式
人工智能·笔记·python·json·产品经理
wdfk_prog3 小时前
LWIP教程 15:IPv4 与 IPv6——从网络层工作原理到嵌入式工程取舍
运维·开发语言·网络·笔记·学习·智能路由器·ip