python markdown 转 html

创建日期: 2024-11-12 17:42 | 作者: 风波 | 浏览次数: 15 | 分类: Python

来源:https://www.linode.com/docs/guides/how-to-use-python-markdown-to-convert-markdown-to-html/

1. 安装

pip install markdown -i https://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com

2. 使用

import markdown

markdown.markdown('## Work Tasks')

长文本

markdown.markdown('''
# To Do
## At Home
* Wash dishes
## At Work
* Finish Report
''')

3. 保留 #

使用 \# 可以避免 # 被解析为 h1

其它的特殊标签都可以通过加转义字符的方式避免被解析。

15 浏览
0 评论