3131# Because asciidoctor clears attributes set in a block. See
3232# https://github.com/asciidoctor/asciidoctor/issues/2993
3333#
34+ # Turns
35+ # ["source","sh",subs="attributes"]
36+ # --------------------------------------------
37+ # wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{version}.zip
38+ # wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{version}.zip.sha512
39+ # shasum -a 512 -c elasticsearch-{version}.zip.sha512 <1>
40+ # unzip elasticsearch-{version}.zip
41+ # cd elasticsearch-{version}/ <2>
42+ # --------------------------------------------
43+ # <1> Compares the SHA of the downloaded `.zip` archive and the published checksum, which should output
44+ # `elasticsearch-{version}.zip: OK`.
45+ # <2> This directory is known as `$ES_HOME`.
46+ #
47+ # Into
48+ # ["source","sh",subs="attributes,callouts"]
49+ # --------------------------------------------
50+ # wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{version}.zip
51+ # wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{version}.zip.sha512
52+ # shasum -a 512 -c elasticsearch-{version}.zip.sha512 <1>
53+ # unzip elasticsearch-{version}.zip
54+ # cd elasticsearch-{version}/ <2>
55+ # --------------------------------------------
56+ # <1> Compares the SHA of the downloaded `.zip` archive and the published checksum, which should output
57+ # `elasticsearch-{version}.zip: OK`.
58+ # <2> This directory is known as `$ES_HOME`.
59+ # Because asciidoc adds callouts to all "source" blocks. We'd *prefer* to do
60+ # this in the tree processor because it is less messy but we can't because
61+ # asciidoctor checks the `:callout` sub before giving us a chance to add it.
62+ #
3463class ElasticCompatPreprocessor < Extensions ::Preprocessor
3564 IncludeTaggedDirectiveRx = /^include-tagged::([^\[ ][^\[ ]*)\[ (#{ CC_ANY } +)?\] $/
65+ SourceWithSubsRx = /^\[ "source", ?"[^"]+", ?subs="(#{ CC_ANY } +)"\] $/
3666
3767 def process document , reader
3868 reader . instance_variable_set :@in_attribute_only_block , false
@@ -46,8 +76,8 @@ def reader.process_line line
4676 else
4777 line
4878 end
49- elsif IncludeTaggedDirectiveRx =~ line then
50- if preprocess_include_directive "elastic-include-tagged:#{ $1} " , $2 then
79+ elsif IncludeTaggedDirectiveRx =~ line
80+ if preprocess_include_directive "elastic-include-tagged:#{ $1} " , $2
5181 nil
5282 else
5383 # the line was not a valid include line and we've logged a warning
@@ -61,12 +91,18 @@ def reader.process_line line
6191 lines . shift
6292 while Asciidoctor ::AttributeEntryRx =~ ( check_line = lines . shift )
6393 end
64- if check_line == '--' then
94+ if check_line == '--'
6595 @in_attribute_only_block = true
6696 line . clear
6797 else
6898 line
6999 end
100+ elsif SourceWithSubsRx =~ line
101+ line = super
102+ unless $1. include? ( 'callouts' )
103+ line . sub! "subs=\" #{ $1} \" " , "subs=\" #{ $1} ,callouts\" "
104+ end
105+ line
70106 else
71107 line = super
72108 line &.gsub! ( /(added)\[ ([^\] ]*)\] / , '\1::[\2]' )
0 commit comments