python-sphinx - 如果可能,我们如何在 rst 文件的代码部分中放置超链接?

标签 python-sphinx restructuredtext

我在 rst 文件中有以下内容:

.. code-block:: bash

   user@adi:~/workspace$ pytest
   test/test/functional/example/test_api_2.py
   --testbed test/test/topo_confs/pytest_tb.json
   --loglevel DEBUG --html /home/user/test.html --self-contained-html

现在我如何在 上放置超链接pytest_tb.json 那个代码中的词?

最佳答案

.. code-block::仅将语法高亮应用于文字代码,这意味着它不支持通过解释 reStructuredText 标记来支持超链接。

相反,您可以在 Sphinx 主题的 CSS 文件中使用自定义样式,假设名为 my-code-block ,并使用 reST 标记,如下所示。

在您的 CSS 文件中:

p.my-code-block {
    font-family: monospace;
    white-space: pre;
}

在你的rest源文件中:
.. rst-class:: my-code-block

    user@adi:~/workspace$ pytest
    test/test/functional/example/test_api_2.py
    --testbed test/test/topo_confs/`pytest_tb.json <relative/path/to/pytest_tb.json>`_
    --loglevel DEBUG --html /home/user/test.html --self-contained-html

请注意,不会应用 Pygments 中的 bash 语法突出显示。然而,您可能会喜欢并在 HTML 输出上使用 JavaScript 语法高亮显示,但是让 HTML 输出符合 JavaScript 的要求以及更新主题可能具有挑战性,而且比它值得的麻烦更多。

关于python-sphinx - 如果可能,我们如何在 rst 文件的代码部分中放置超链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45499108/

相关文章:

python - 当模块需要在导入前设置时使用 sphinx 记录 sqlalchemy 类

python - 如何自动链接到 Sphinx 中 ReST 文档字符串中的参数类型?

python - 如何使用 Sphinx 记录特定部分中的成员?

python - 使用 reStructuredText 添加一些具有自定义 "id"和 "class"属性的 HTML

python - 如何将 ref 指向包含 Sphinx 项目中另一个文档的文档?

python - scikit-learn intersphinx 链接/库存对象?

Python:没有名为 sphinx 错误的模块

restructuredtext - 我可以在 reStructuredText 中使用编号链接吗?

python - 狮身人面像/rST : using configuration values in include statements?

restructuredtext - 在第一个图像中添加标题属性