restructuredtext - 标题中的重组文本(狮身人面像)图像?

标签 restructuredtext sections

是否可以使用重组文本将图像放置在标题内?

就像是:

Introduction .. image:: path/to/img.png
---------------------------------------

这呈现为文本,即不解析图像语法。我还没有看到任何这样的例子让我相信这可能是不可能的,但也许有人有解决方法。

我打算输出到 HTML(因此可以修改派生的 CSS,但我更愿意更改 RST 源。这是因为我也打算输出到 pdf( latex )。

最佳答案

使用 HTML 和 CSS,有多种方法可以将图像添加到元素中,从而产生不同的结果。我能想到的一对是:

  • 使用图像代替任何文本。在这里,我们保留文本,但将其发送到屏幕外,因此仍然可以访问。
    h1 {
        background: url(images/image.jpg) no-repeat top center;
        display: block;
        text-indent: 100%;
        white-space: nowrap;
        overflow: hidden;
        width: XXpx;
        height: XXpx;
    }
    
  • 将图像放在文本的左侧(或者很容易放在右侧)
    h1 {
        background: url(images/image.jpg) no-repeat top left;
        padding-left: XXpx;
    }
    
  • 使用背景图像,在任何文本后面
    h1 {
        background:url(images/image.jpg) no-repeat top center;
    }
    

  • 更具体的 CSS 选择器可用于仅针对某些标题。

    您可以使用 raw directive 在 reStructuredText 文档中轻松包含自定义 CSS ,像这样:
    .. raw:: html
    
        <style>
            <!-- One of the CSS styles above. -->
        </style>
    

    或者,您可以使用 --stylesheet 从命令行包含自定义 CSS 样式表。 rst2html.py 的选项.

    在实现PDF输出方面,我将窃取部分another one of my answers :

    Obviously the above targets HTML output. However, I have not used rst2pdf, so can't comment on how the above needs to be modified to work with this program. Hopefully someone else will provide an answer to this. As far as I know, rst2pdf does support a cascading stylesheet mechanism, so it should be straightforward (for someone who knows rst2pdf style sheet syntax) to add an additional .. raw:: pdf role and to modify the above list styles.

    关于restructuredtext - 标题中的重组文本(狮身人面像)图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17680593/

    相关文章:

    python - 带有 reStructuredText 的项目符号列表中的源代码

    ios - NSFetchedResultController 按日期排序部分得到重新排列

    jQuery Accordion 一次打开多个部分

    jquery - Fullpage.js:根据当前部分更改页面标题

    javascript - HTML5中id的比较

    python - 如何将 ReStructuredText 文档转换为 ipython 笔记本?

    restructuredtext - 如何在 reStructuredText 中创建不间断空间?

    python-sphinx - 如何在节点中为指令添加 rst 格式?

    python - Django ReStructuredText 中的数学指令

    c - 使用 bfd 数据结构的目标文件中的节数