/
extension.rb
43 lines (38 loc) · 974 Bytes
/
extension.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'asciidoctor/extensions'
include Asciidoctor
# An extension that introduces a custom admonition type, complete
# with a custom icon.
#
# Usage
#
# [QUESTION]
# ====
# What's the main tool for selecting colors?
# ====
#
# or
#
# [QUESTION]
# What's the main tool for selecting colors?
#
class CustomAdmonitionBlock < Extensions::BlockProcessor
use_dsl
named :QUESTION
on_contexts :example, :paragraph
def process parent, reader, attrs
attrs.update 'name' => 'question', 'textlabel' => 'Question'
node = create_block parent, :admonition, reader.lines, attrs, content_model: :compound
node.caption = attrs['textlabel'] unless node.caption
node
end
end
class CustomAdmonitionBlockDocinfo < Extensions::DocinfoProcessor
use_dsl
def process doc
if (doc.basebackend? 'html') && doc.backend != 'pdf'
'<style>
.admonitionblock td.icon .icon-question:before {content:"\f128";color:#871452;}
</style>'
end
end
end