- 目的
-
创建一个名为`gist`的块宏,用于嵌入 gist。
sample-with-gist-macro.adoc
.My Gist gist::123456[]
代码块宏
class GistBlockMacro < Asciidoctor::Extensions::BlockMacroProcessor use_dsl 命名为:gist def process parent, target, attrs title_html = (attrs.has_key? 'title') ? %(<div class="title">#{attrs['title']}</div>\n) : nil html html = %(<div class="openblock gist"> #{title_html}<div class="content"> <script src="https://gist.github.com/#{target}.js"></script> </div> </div>) create_pass_block parent, html, attrs, subs: nil end end
使用方式
Asciidoctor::Extensions.register do block_macro GistBlockMacro if document.basebackend? 'html' end Asciidoctor.convert_file 'sample-with-gist.adoc', safe: :safe