【发布时间】:2021-04-19 19:38:49
【问题描述】:
我正在使用 Sphinx 从 Markdown 文件中构建文档。
文档很清楚 myst-parser 应该以典型的[some text](www.example.com) 方式处理降价链接。
随后我安装了myst-parser,设置扩展名extensions = ['myst_parser']并指定source_suffix:
source_suffix = {
'.rst': 'restructuredtext',
'.txt': 'markdown',
'.md': 'markdown',
}
不幸的是,链接没有正确转换,只是显示为以下 HTML:
[some text](<a class="reference external" href="www.example.com">www.example.com</a>)
然后在浏览器中以以下方式显示[some text](www.example.com),这显然不是预期的链接。
我也尝试通过以下方式使用 Recommonmark:
from recommonmark.parser import CommonMarkParser
source_parsers = {
'.md': CommonMarkParser,
}
source_suffix = ['.rst', '.md']
正如 here 和 here 所解释的,但最终得到了相同的输出。 如何解决这个相当简单的问题?
正在使用的版本: 推荐 0.7.1 神秘解析器 0.13.6 狮身人面像 3.5.4 蟒蛇3.9.2
编辑 在这里找到更新的 conf.py 文件
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
import sphinx_rtd_theme
import sys
import os
print("CURRENT WORKING DIRECTORY")
print(os.getcwd())
print('adding path')
sys.path.insert(0, r'path_to_repo')
print(sys.path)
# At top on conf.py (with other import statements)
import recommonmark
from recommonmark.transform import AutoStructify
from recommonmark.parser import CommonMarkParser
# -- Project information -----------------------------------------------------
project = 'py_neuromodulation'
copyright = '2021, John Doe'
author = 'John Doe'
source_parsers = {
'.md': 'recommonmark.parser.CommonMarkParser',
}
source_suffix = ['.rst', '.md']
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.viewcode',
'numpydoc',
'sphinx_rtd_theme',
'sphinx.ext.napoleon',
'recommonmark'
]
autosummary_generate = True
html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']
# At the bottom of conf.py
def setup(app):
app.add_config_value('recommonmark_config', {
'url_resolver': lambda url: github_doc_root + url,
'auto_toc_tree_section': 'Contents',
}, True)
app.add_transform(AutoStructify)
【问题讨论】:
-
如果答案解决了您的问题,请不要忘记在答案左侧点赞和accept it by clicking the green check mark。
-
不幸的是它没有解决问题,我添加了 conf.py 以获得更多详细信息
-
请注意,recommonmark 已弃用,取而代之的是 myst-parser github.com/readthedocs/recommonmark/issues/221
标签: markdown python-sphinx myst