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数学公式)

相关推荐
zhangrelay4 小时前
影响移动固态磁盘稳定性的原因有哪些呢?
笔记·学习
lkbhua莱克瓦245 小时前
深入理解HTTP协议:从理论到SpringBoot实践
网络·笔记·后端·网络协议·http·javaweb
charlie1145141916 小时前
计算机图形学速通指南笔记(0)
c++·笔记·软件工程·计算机图形学·工程实践
百***78756 小时前
Sora Video2 API国内接入避坑与场景落地:开发者实战笔记
人工智能·笔记·gpt
日更嵌入式的打工仔6 小时前
RS-485通讯协议
笔记·嵌入式硬件
数据轨迹0017 小时前
ICCV MK-UNet:多核深度可分离卷积医学分割
经验分享·笔记·facebook·oneapi·twitter
狐579 小时前
2026-01-20-论文阅读-Can-1B-LLM-Surpass-405B-LLM?
论文阅读·笔记
Tiaoxiaobai9 小时前
如何实现亚细胞定位
人工智能·笔记
龙仔7259 小时前
n2n supernode Linux完整部署笔记,包含离线部署,
linux·运维·笔记·n2n·supernode
2501_9443321610 小时前
深圳的售后服务系统解决方案有哪些提供商?
笔记