You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
941 B

4 years ago
////
Included in:
- user-manual: Extensions: Block macro processor example
////
Purpose::
Create a block macro named `gist` for embedding a gist.
.sample-with-gist-macro.adoc
```
.My Gist
gist::123456[]
```
.GistBlockMacro
```ruby
require 'asciidoctor'
require 'asciidoctor/extensions'
class GistBlockMacro < Asciidoctor::Extensions::BlockMacroProcessor
use_dsl
named :gist
def process parent, target, attrs
title_html = (attrs.has_key? 'title') ?
%(<div class="title">#{attrs['title']}</div>\n) : nil
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
```
.Usage
```ruby
Asciidoctor::Extensions.register do
block_macro GistBlockMacro if document.basebackend? 'html'
end
Asciidoctor.convert_file 'sample-with-gist.adoc', :safe => :safe
```