如何通过在 python-sphinx 中使用角色来使用内联唯一指令?
How can I use the only directive inline by using role in python-sphinx?
在python-sphinx 中有only directive,可用于根据文档的输出有条件地影响文档。例如,文本仅出现在 html 或乳胶中。
是这样使用的:
.. only:: not latex
Here there is some Text, that does not appear in latex output.
.. only:: html
Here there is some Text, that only appears in html output.
如何以正确的方式使用角色指令来使用 only-class 内联,让我们这样说:
Here there is some Text, that :only-notlatex:`does not appear in latex`
:only-html:`only appears in html`.
我看到了与 raw 指令类似的内容。 only 指令也可以这样吗?我试过了:
.. role:: only-html(only)
:format: html
.. role:: only-notlatex(only)
:format: not latex
但这不起作用。
指令适用于文本块(整段);角色用于内联文本(段落内)。
您提到了 raw
,"raw data pass-through" 确实有一个 directive and a role 同名。
但是没有内置角色是 only
directive. You will have to create your own custom role for this purpose. I can't provide any detailed instructions, but here is an article that can help you get started: http://doughellmann.com/2010/05/09/defining-custom-roles-in-sphinx.html 的内联等效项。
在python-sphinx 中有only directive,可用于根据文档的输出有条件地影响文档。例如,文本仅出现在 html 或乳胶中。
是这样使用的:
.. only:: not latex Here there is some Text, that does not appear in latex output. .. only:: html Here there is some Text, that only appears in html output.
如何以正确的方式使用角色指令来使用 only-class 内联,让我们这样说:
Here there is some Text, that :only-notlatex:`does not appear in latex`
:only-html:`only appears in html`.
我看到了与 raw 指令类似的内容。 only 指令也可以这样吗?我试过了:
.. role:: only-html(only) :format: html .. role:: only-notlatex(only) :format: not latex
但这不起作用。
指令适用于文本块(整段);角色用于内联文本(段落内)。
您提到了 raw
,"raw data pass-through" 确实有一个 directive and a role 同名。
但是没有内置角色是 only
directive. You will have to create your own custom role for this purpose. I can't provide any detailed instructions, but here is an article that can help you get started: http://doughellmann.com/2010/05/09/defining-custom-roles-in-sphinx.html 的内联等效项。