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

相关推荐
瑶光守护者5 小时前
【学习笔记】5G RedCap:智能回落5G NR驻留的接入策略
笔记·学习·5g
你想知道什么?5 小时前
Python基础篇(上) 学习笔记
笔记·python·学习
xian_wwq6 小时前
【学习笔记】可信数据空间的工程实现
笔记·学习
浩瀚地学6 小时前
【Arcpy】入门学习笔记(五)-矢量数据
经验分享·笔记·python·arcgis·arcpy
Li.CQ6 小时前
SQL学习笔记
笔记·sql·学习
云霄星乖乖的果冻6 小时前
01引言——李沐《动手学深度学习》个人笔记
人工智能·笔记·深度学习
AI视觉网奇7 小时前
移动端数字人 Ultralight-Digital-Human 算法笔记
笔记·计算机视觉
雍凉明月夜7 小时前
c++ 精学笔记记录Ⅱ
开发语言·c++·笔记·vscode
路弥行至7 小时前
FreeRTOS任务管理详解中: FreeRTOS任务创建与删除实战教程(动态方法)
c语言·开发语言·笔记·stm32·操作系统·freertos·入门教程
北岛寒沫8 小时前
北京大学国家发展研究院 经济学辅修 经济学原理课程笔记(第四课 税收和补贴)
笔记