4.2. 在Sphinx中支持Markdown

MyST Markdown

4.2.1. MyST 与解析器

MyST(全称 Markedly Structured Text)专为 Sphinx 项目使用而设计的 Markdown 风格。 它是 CommonMark Markdown 和一些额外的语法片段的组合,以支持 Sphinx 的功能,因此您可以用纯 Markdown 编写 Sphinx 文档。 它是 Jupyter Book 使用的核心技术之一。

MyST-Parser 是 Sphinx 的解析器,它可以读取以 MyST Markdown 编写的内容。 MyST-NB 也使用它来解析 Jupyter 笔记本内部的 MyST Markdown。

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

4.2.2. 在 Sphinx 中启用 Markdown 支持

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