Sphinx Recommonmark CommonMarkParser 未检测到 URL link

Sphinx Recommonmark CommonMarkParser does not detect URL link

我正在使用 Sphinx 从 Markdown 文件构建文档。 文档非常清楚,myst-parser 应该以典型的 [some text](www.example.com) 方式处理 markdown links。

随后我安装了 myst-parser,设置扩展名 extensions = ['myst_parser'] 并指定 source_suffix:

source_suffix = {
    '.rst': 'restructuredtext',
    '.txt': 'markdown',
    '.md': 'markdown',
}

不幸的是,links 没有得到正确的转换,只是显示如下 HTML:

[some text](<a class="reference external" href="www.example.com">www.example.com</a>)

然后在浏览器中以以下方式显示 [some text](www.example.com),这显然不是预期的 link。

我也试过通过以下方式使用 Recommonmark:

from recommonmark.parser import CommonMarkParser

source_parsers = {
    '.md': CommonMarkParser,
}

source_suffix = ['.rst', '.md']

and here 所述,但结果相同。 如何解决这个相当简单的问题?

正在使用的版本: 推荐 0.7.1 神秘解析器 0.13.6 狮身人面像 3.5.4 python3.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)

默认情况下,您必须包含用于外部链接的协议。

但是如果你想使用没有协议的裸链接,那么使用 Linkify:

Adding "linkify" to myst_enable_extensions (in the sphinx conf.py configuration file) will automatically identify “bare” web URLs and add hyperlinks:

www.example.com -> www.example.com

This extension requires that linkify-it-py is installed. Either directly; pip install linkify-it-py or via pip install myst-parser[linkify].

以下代码示例演示了文档描述的内容。

myst_enable_extensions = [
    "linkify",
]