Sphinx:对不同的输出格式使用不同的指令 [英] Sphinx: Use a different directive for a different output format
问题描述
假设您有一个 reStructuredText 文档,并希望使用 Sphinx 2.x 将其导出为两种格式:HTML 和 PDF.
您想在这两种格式中放置一些略有不同的内容.例如,文本 "I am HTML" 出现在 HTML 版本中,而 "I am PDF" 出现在 PDF 版本中的文档相同位置.>
使用像下面这样的替换指令会给你我是 HTML",无论导出格式如何.
.. |foo|替换:: HTML⋮我是 |foo|
您能否为不同的导出格式使用不同的指令?
这有点笨拙,但对我有用:
.. role:: latex(raw):格式:乳胶.. 角色:: html(raw):格式:html.. |foo|替换:: :latex:`LaTeX 文本`:html:`HTML 文本`.. |酒吧|替换:: :latex:`其他乳胶文本`:html:`其他 html 文本`
Assume you have a reStructuredText document and want to export it in two formats using Sphinx 2.x: HTML and PDF.
You want to put some slightly different contents in these two formats. For example, the text "I am HTML" appears in the HTML version whereas "I am PDF" appears in the PDF version in the same location of the document.
Use a replace directive like below will give you "I am HTML" regardless of the export format.
.. |foo| replace:: HTML
⋮
I am |foo|
Can you use a different directive for a different export format?
This is a little clunky, but it works for me:
.. role:: latex(raw)
:format: latex
.. role:: html(raw)
:format: html
.. |foo| replace:: :latex:`LaTeX text`:html:`HTML text`
.. |bar| replace:: :latex:`other latex text`:html:`other html text`
这篇关于Sphinx:对不同的输出格式使用不同的指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!