markdown-it的Python端口。Markdown解析,做得正确!
项目描述
markdown-it-py
Markdown解析,做得正确。
- 遵循CommonMark规范进行基线解析
- 可配置的语法:您可以添加新规则,甚至替换现有的规则。
- 可扩展的:添加语法扩展以扩展解析器(见插件列表)。
- 速度快(见我们的基准测试)
- 默认安全
- Google的“保证开源软件”成员
这是markdown-it的Python移植版本,以及一些相关插件。更多详情请见:https://markdown-it-py.readthedocs.io。
有关markdown-it本身的详细信息,请见
安装
conda install -c conda-forge markdown-it-py
或
pip install markdown-it-py[plugins]
或使用额外功能
conda install -c conda-forge markdown-it-py linkify-it-py mdit-py-plugins
pip install markdown-it-py[linkify,plugins]
用法
Python API用法
使用markdown-it-py将markdown渲染为HTML,带有和没有插件和功能的自定义配置
from markdown_it import MarkdownIt
from mdit_py_plugins.front_matter import front_matter_plugin
from mdit_py_plugins.footnote import footnote_plugin
md = (
MarkdownIt('commonmark' ,{'breaks':True,'html':True})
.use(front_matter_plugin)
.use(footnote_plugin)
.enable('table')
)
text = ("""
---
a: 1
---
a | b
- | -
1 | 2
A footnote [^1]
[^1]: some details
""")
tokens = md.parse(text)
html_text = md.render(text)
## To export the html to a file, uncomment the lines below:
# from pathlib import Path
# Path("output.html").write_text(html_text)
命令行用法
从命令行使用markdown-it-py将markdown渲染为HTML
usage: markdown-it [-h] [-v] [filenames [filenames ...]]
Parse one or more markdown files, convert each to HTML, and print to stdout
positional arguments:
filenames specify an optional list of files to convert
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
Interactive:
$ markdown-it
markdown-it-py [version 0.0.0] (interactive)
Type Ctrl-D to complete input, or Ctrl-C to exit.
>>> # Example
... > markdown *input*
...
<h1>Example</h1>
<blockquote>
<p>markdown <em>input</em></p>
</blockquote>
Batch:
$ markdown-it README.md README.footer.md > index.html
参考/感谢
感谢markdown-it的作者
- Alex Kocharin github/rlidwka
- Vitaly Puzrin github/puzrin
还要感谢John MacFarlane,他为CommonMark规范和参考实现所做的贡献。
项目详情
下载文件
下载适用于您平台的应用程序。如果您不确定选择哪个,请了解更多关于安装包的信息。
源代码发行版
markdown-it-py-3.0.0.tar.gz (74.6 kB 查看哈希值)
构建发行版
markdown_it_py-3.0.0-py3-none-any.whl (87.5 kB 查看哈希值)