从.rst文件中的markdown文件中渲染输出

Jar*_*ber 6 documentation markdown restructuredtext python-sphinx

Sphinx用于记录Python项目,并希望将现有.md文件的内容显示在.rst文件中.(我已经设置了conf.py允许降价).

例如,我有一个名为的文件tutorial.md.我还有一个.rst文件如下:

ml
==

w2v
^^^

.. automodule:: package.ml.w2v
:members:
Run Code Online (Sandbox Code Playgroud)

我希望能够包含tutorial.md如下链接,以便tutorial.md在呈现时将在文件中显示内容.这可以通过以下方式实现:

ml
==

Tutorial
--------
.. include:: ../tutorial.md

w2v
^^^

.. automodule:: package.ml.w2v
:members:
Run Code Online (Sandbox Code Playgroud)

但是,结果内容看起来很糟糕,因为它不会将降价呈现为降价.

我意识到我可以通过编写整个文档来避免这个问题.md,但是这个练习给我留下了以下问题:

是否有可能有.md内容呈现为降价,里面的的.rst文件吗?

小智 11

尝试M2R sphinx扩展.

https://github.com/miyakogi/m2r#sphinx-integration

安装m2r并更改conf.py后,只需更改.. include即可.. mdinclude正常工作.

ml
==

Tutorial
--------
.. mdinclude:: ../tutorial.md

w2v
^^^

.. automodule:: package.ml.w2v
:members:
Run Code Online (Sandbox Code Playgroud)

  • 这[似乎不再工作了](https://github.com/sphinx-doc/sphinx/issues/7420),因为 m2r 没有积极维护并且[尚未更新到最新的 sphinx api]( https://github.com/sphinx-doc/sphinx/issues/7420#issuecomment-609814898) (3认同)
  • 非常有用的答案,如果在其中显示“安装 m2r 并更改 conf.py”,使用起来会更快。install 是 pip install 和 conf.py 是关于`extensions = ['m2r', #... ]` (2认同)