前言
mistune库是一个解析Markdown的利器,使用起来非常简单。当我们想要解析Markdown格式的文档时,只需两步就能将其转换成html格式。如下:
import mistune
mistune.html(YOUR_MARKDOWN_TEXT)
安装方式也非常简单,dddd:
pip install mistune
命令行工具
mistune可以通过命令行将markdown格式的文本转换为HTML,可以使用python3 -m mistune -h查看帮助文档:
yczx@yczx:~$ python3 -m mistune -h
usage: python -m mistune [-h] [-m MESSAGE] [-f FILE] [-p NAME [NAME ...]]
[--escape] [--hardwrap] [-o OUTPUT] [-r RENDERER]
[--version]
Mistune, a sane and fast python markdown parser.
Here are some use cases of the command line tool:
$ python -m mistune -m "Hi **Markdown**"
<p>Hi <strong>Markdown</strong></p>
$ python -m mistune -f README.md
<p>...
$ cat README.md | python -m mistune
<p>...
options:
-h, --help show this help message and exit
-m MESSAGE, --message MESSAGE
the markdown message to convert
-f FILE, --file FILE the markdown file to convert
-p NAME [NAME ...], --plugin NAME [NAME ...]
specifiy a plugin to use
--escape turn on escape option
--hardwrap turn on hardwrap option
-o OUTPUT, --output OUTPUT
write the rendered result into file
-r RENDERER, --renderer RENDERER
specify the output renderer
--version show program'
Mistune:Markdown解析库的命令行工具与使用示例

本文介绍了Mistune库,一个用于解析Markdown格式的Python工具,演示了如何使用它进行Markdown到HTML的转换,包括命令行工具的用法、文本样式处理、列表和代码块等内容,以及Markdown转RestructuredText的尝试。
最低0.47元/天 解锁文章
3590

被折叠的 条评论
为什么被折叠?



