【发布时间】:2019-04-13 12:03:02
【问题描述】:
rst2html 是否复制图像目录和图像路径?
我尝试了 rst2odt,它会复制图像。 rst2html 我没能达到同样的效果。
这太疯狂了。它是一种文档工具,但我正在寻找几个小时来为这样一个核心问题找到明确的答案。
【问题讨论】:
rst2html 是否复制图像目录和图像路径?
我尝试了 rst2odt,它会复制图像。 rst2html 我没能达到同样的效果。
这太疯狂了。它是一种文档工具,但我正在寻找几个小时来为这样一个核心问题找到明确的答案。
【问题讨论】:
reStructuredText 标记语言
包括image directive,
和基于 reStructuredText 构建的文档生成器一样,例如
Sphinx。
图像如何包含在输出中
取决于输出格式。
例如,rst2odt 程序不会复制图像目录或图像路径,
它将实际图像复制到 ODT 文件中。
ODT files are just ZIP files with a particular structure,
这样您就可以解压 ODT 文件并查看 Pictures/ 中的图像。
相比之下,rst2html 程序不会将图像直接存储在 HTML 文件中
因为这不是典型的 HTML。
相反,它generates
一个img tag
指向图像。
例如,这个标记:
.. image:: example.png
将生成此 HTML:
<img alt="example.png" src="example.png" />
路径example.png 是相对于源文件的路径示例,
但是there are other options for img tags。
如果您想将图像直接嵌入到 HTML 文件中,例如 data URLs, 您将需要做其他事情,例如:
手动将图像转换为 Base64,使用它来制作带有数据 URL 的 HTML img 标签,并使用 raw directive.
例如,这个标记:
.. raw:: html
<img alt="red square" src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAQMAAABKLAcXAAAAA1BMVEX/AAAZ4gk3AAAAFElEQVQ4 y2NgGAWjYBSMglFATwAABXgAASlxufwAAAAASUVORK5CYII=" />
将生成此 HTML:
<img alt="red square" src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAQMAAABKLAcXAAAAA1BMVEX/AAAZ4gk3AAAAFElEQVQ4 y2NgGAWjYBSMglFATwAABXgAASlxufwAAAAASUVORK5CYII=" />
这将产生这个图像:
使用SingleFile等工具, inliner, 或webpage2html 到post-process the generated HTML。
请注意,数据 URL 存在限制,包括 browser-dependent size restrictions.
相关:
Creating a self contained, offline HTML5 app and the best method for embedding its resources
What's the best "file format" for saving complete web pages (images, etc.) in a single archive?
http://www.techerator.com/2011/12/how-to-embed-images-directly-into-your-html/
https://www.davidbcalhoun.com/2011/when-to-base64-encode-images-and-when-not-to/
【讨论】: