目的

从URI包含一个文件。

Tip
如果设置了`allow-uri-read`属性(在安全模式为`secure`时不可用),Asciidoctor 支持不加配置地包含来自 URI 的内容。

sample-with-uri-include.adoc

:source-highlighter: coderay

.Gemfile
[,ruby]
----
include::https://cdn.jsdelivr.net/gh/asciidoctor/asciidoctor/Gemfile[]
----

UriIncludeProcessor

class UriIncludeProcessor < Asciidoctor::Extensions::IncludeProcessor
  def handles? target
    target.start_with? 'https://', 'https://'
  end

def process doc, reader, target, attributes
    content = (::OpenURI.open_uri target).readlines
    reader.push_include content, target, target, 1, attributes
    reader
  end
end

用法

Asciidoctor::Extensions.register do
  include_processor UriIncludeProcessor
end

Asciidoctor.convert_file 'sample-with-uri-include.adoc', safe: :safe