管理图像

默认情况下,图片不会嵌入到 HTML 输出中。如果您的文档中有图片引用,您必须将图片文件保存在与转换后的文档相同的目录中。

使用 data-uri 属性嵌入图片

作为替代方案,您可以通过设置 data-uri 文档属性将图片直接嵌入到文档中。

示例 1. 在文档头中设置 data-uri 属性
= The Dangers of Wolpertingers
:url-wolpertinger: https://en.wikipedia.org/wiki/Wolpertinger
:imagesdir: my-images
:data-uri:

Don't worry about gumberoos or splintercats.
Something far more fearsome plagues the days, nights, and inbetweens.
Wolpertingers.

== Origins

Wolpertingers are {url-wolpertinger}[ravenous beasts].
[.left.text-center]
image:wolpertinger.jpg[Wolpertinger,100,,link="https://commons.wikimedia.org/wiki/File:Wolpertinger.jpg"]
They may look cute and cuddly, but don't be fooled.

您也可以使用 API 或 CLI (此处展示) 设置 data-uri

$ asciidoctor -a data-uri my-document.adoc

当您在浏览器中查看 HTML 文件时,应该能在页面上看到显示的图片。

my document with data uri

allow-uri-read 属性

如果文档中一个或多个图片的指向是 URI,您还必须安全地设置 allow-uri-read 属性,并在 SECURE 模式或更低模式下运行 Asciidoctor。

$ asciidoctor -a data-uri -a allow-uri-read my-document.adoc

当使用 Asciidoctor PDF 将文档转换为 PDF 时,情况也是如此,无论是否设置了 data-uri 属性,因为这种行为是隐式的。