MyST扩展

5. MyST扩展#

MyST(全称 Markedly Structured Text)专为 Sphinx 项目使用而设计的兼容 Markdown 的指令。 它是 CommonMark Markdown 和一些额外的语法片段的组合,以支持 Sphinx 的功能,因此您可以用纯 Markdown 语法编写 Sphinx 文档。 它也是 Jupyter Book 使用的核心技术之一,MyST-NB 也使用它来解析 Jupyter 笔记本内部的 MyST Markdown。

MyST-Parser 是 Sphinx 的解析器,它可以读取以 MyST Markdown 编写的内容。 它包含一个使用 markdown-it-py 的符合 CommonMark 标准的扩展解析器, 以及一个允许你在 Sphinx 中编写 MyST Markdown 的 Sphinx 扩展。

备注

缺省的 Sphinx Markdown 解析器是 recommonmark,它不支持 MyST 语法,只能完成基本的 Markdown 语法解析。 markdown-it-py 是 CommonMark 的解析器,它支持 MyST 语法,但无法解析 Sphinx 的扩展语法。 因此,MyST-Parser 将 markdown-it-py 与 Sphinx 扩展结合在一起,以支持 Sphinx 的扩展语法。

To use MyST you need to install myst-parser and enable it in Sphinx’s conf.py:

extensions = ["myst_parser"]

A number of plugins can be enabled to extend the default syntax. The way to enable them is to add them to the myst_enable_extensions list in conf.py.

Some of them will be addressed in the syntax section but others are:

  • "smartquotes": converts standard quotes to their opening/closing variants

  • "linkify": convert bare URLs in hyperlinks

All of them are in the MyST docs