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

相关推荐
郑泰科技2 小时前
mstsc 频繁断开是由svchost 策略引起的吗?
windows·笔记·负载均衡
鲨莎分不晴2 小时前
优化的基石:深度解析“凸集”的数学美感与工程价值
笔记
雍凉明月夜3 小时前
深度学习网络笔记Ⅲ(注意力机制)
笔记·深度学习·神经网络·分类
Ahtacca4 小时前
Linux环境下前后端分离项目(Spring Boot + Vue)手动部署全流程指南
linux·运维·服务器·vue.js·spring boot·笔记
polarislove02145 小时前
9.6 [定时器]超声波测距实验-嵌入式铁头山羊STM32笔记
笔记·stm32·嵌入式硬件
chushiyunen5 小时前
快慢双指针算法笔记
数据结构·笔记·算法
临风小红楼5 小时前
别了2025,你好2026
笔记
laplace01237 小时前
Part 3:模型调用、记忆管理与工具调用流程(LangChain 1.0)笔记(Markdown)
开发语言·人工智能·笔记·python·langchain·prompt
wdfk_prog7 小时前
[Linux]学习笔记系列 -- [fs]open
linux·笔记·学习
wdfk_prog7 小时前
[Linux]学习笔记系列 -- [fs]nsfs
linux·笔记·学习