blob: 7352af31563e2f8955da57fc5f64e643c6e6e29f (
plain) (
blame)
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
44
45
46
47
48
|
= Block Processor Extension Example
:navtitle: Block Processor
Purpose::
Register a custom block style named `shout` that uppercases all the words and converts periods to exclamation points.
== sample-with-shout-block.adoc
[source,asciidoc]
----
[shout]
The time is now. Get a move on.
----
== ShoutBlock
[source,ruby]
----
require 'asciidoctor'
require 'asciidoctor/extensions'
class ShoutBlock < Asciidoctor::Extensions::BlockProcessor
PeriodRx = /\.(?= |$)/
use_dsl
named :shout
on_context :paragraph
name_positional_attributes 'vol'
parse_content_as :simple
def process parent, reader, attrs
volume = ((attrs.delete 'vol') || 1).to_i
create_paragraph parent, (reader.lines.map {|l| l.upcase.gsub PeriodRx, '!' * volume }), attrs
end
end
----
== Usage
[source,ruby]
----
Asciidoctor::Extensions.register do
block ShoutBlock
end
Asciidoctor.convert_file 'sample-with-shout-block.adoc', safe: :safe
----
|