首页 > 解决方案 > Sphinx Admonition 的自定义(多字)标题

问题描述

我使用 Sphinx 发布课程。我想创建一个自定义警告,其标题由几个单词组成(例如“历史注释”)。我想出了一个.admonition-title:after在我的 custom.css 文件中使用的肮脏技巧:

.admonition-historical {
    border: solid 1px;
    border-color: rgb(153,102,153);
}

.rst-content .admonition-historical .admonition-title {
    background: #AD85AD;
}

.rst-content .admonition-historical {
   background: #EDE5ED
}

.rst-content .admonition-historical .admonition-title:before {
    content: "  ";
}

.rst-content .admonition-historical .admonition-title:after {
    content: " notes";
}

这在 HTML 文档中可以正常工作,但在 LaTeX 版本中却不行,它仅显示为“历史”。

用复杂的多词标题定义警告的正确方法是什么,在 HTML 和 LaTeX 中都能很好地呈现?

标签: python-sphinxmarkuprestructuredtext

解决方案


我不确定我是否正确理解了你的问题。但是,有一个admonition指令允许在其参数中设置标题:

.. admonition:: This is generic admonition title

   Generic admonition are rarely used but has one important benefit over
   specific ones: author may define admonition title in directive argument.
   Specific admonitions gets its type as title (danger has danger as title
   etc.).

推荐阅读