如果可能的话,我们如何在 rst 文件的代码段中放置超链接?
If possible, how do we put hyperlink within the code section in rst files?
我在第一个文件中有以下内容:
.. 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 的要求并更新主题可能具有挑战性,而且麻烦多于它的价值。
我在第一个文件中有以下内容:
.. 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 的要求并更新主题可能具有挑战性,而且麻烦多于它的价值。