【问题标题】:Custom (multiple words) title for Sphinx AdmonitionSphinx Admonition 的自定义(多字)标题
【发布时间】:2020-06-14 08:27:47
【问题描述】:

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

.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-sphinx markup restructuredtext


    【解决方案1】:

    我不确定我是否正确理解了您的问题。但是,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.).
    

    【讨论】:

    • 但是我也可以设置颜色吗?
    • 颜色和外观通常取决于应用于由 Sphinx 生成的输出 HTML 的 CSS 样式。在 admonition:: 指令中添加 :class: 选项以应用 CSS 类。例如:class: admonition-historical 和 HTML
      将具有“class=adminition-historical”。
    猜你喜欢
    • 2020-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-05
    相关资源
    最近更新 更多