misaka 是python 世界性能最好的 markdown 解析库,gfm (GitHub Flavored Markdown)是 github 扩展的格式。可以通过下面的方式用 misaka 实现 gfm 解析
misaka 早起版本
1
2
3
4
5
6
7
8
9
10
11
12
import misaka
def gfm(str_md=''):
"""
transform the markdown text to html, using github favoured markdown
usage: str_html = gfm(str_md)
"""
str_html = misaka.html(str_md,
extensions=misaka.EXT_NO_INTRA_EMPHASIS | misaka.EXT_FENCED_CODE | misaka.EXT_AUTOLINK | misaka.EXT_LAX_HTML_BLOCKS | misaka.EXT_TABLES | misaka.EXT_STRIKETHROUGH,
render_flags=misaka.HTML_TOC | misaka.HTML_USE_XHTML | misaka.HTML_HARD_WRAP | misaka.HTML_SKIP_HTML)
return str_html
misaka v2+ 以上版本
1
2
3
4
5
6
7
8
9
10
11
12
import misaka
def gfm(str_md=''):
"""
transform the markdown text to html, using github favoured markdown
usage: str_html = gfm(str_md)
"""
str_html = misaka.html(str_md,
extensions=misaka.EXT_NO_INTRA_EMPHASIS | misaka.EXT_FENCED_CODE | misaka.EXT_AUTOLINK | misaka.EXT_TABLES | misaka.EXT_STRIKETHROUGH,
render_flags=misaka.HTML_USE_XHTML | misaka.HTML_HARD_WRAP | misaka.HTML_SKIP_HTML)
return str_html
项目地址
misaka https://github.com/FSX/misaka
pip 安装
1
pip install misaka
本文网址: https://pylist.com/topic/85.html 转摘请注明来源