diff --git a/lib/ES/Util.pm b/lib/ES/Util.pm index a6aa82894e546..a9d0b2a8a4175 100644 --- a/lib/ES/Util.pm +++ b/lib/ES/Util.pm @@ -97,6 +97,7 @@ sub build_chunked { '-a' => 'asciidoc-dir=' . $asciidoc_dir, '-a' => 'resources=' . join(',', @$resources), '-a' => 'copy-callout-images=png', + '-a' => 'copy-admonition-images=png', '--destination-dir=' . $dest, docinfo($index), $index @@ -217,6 +218,8 @@ sub build_single { $private ? () : ( '-a' => "edit_url=$edit_url" ), '-a' => 'asciidoc-dir=' . $asciidoc_dir, '-a' => 'resources=' . join(',', @$resources), + '-a' => 'copy-callout-images=png', + '-a' => 'copy-admonition-images=png', # Disable warning on missing attributes because we have # missing attributes! # '-a' => 'attribute-missing=warn', diff --git a/resources/asciidoctor/lib/change_admonishment/extension.rb b/resources/asciidoctor/lib/change_admonishment/extension.rb index 38af08001c16d..69053cd0d36a9 100644 --- a/resources/asciidoctor/lib/change_admonishment/extension.rb +++ b/resources/asciidoctor/lib/change_admonishment/extension.rb @@ -43,7 +43,8 @@ def process parent, target, attrs # go with this funny compound pass thing. note = Block.new(parent, :pass, :content_model => :compound) note << Block.new(note, :pass, - :source => "") + :source => "", + :attributes => {'revisionflag' => @revisionflag}) note << Block.new(note, :paragraph, :source => attrs[:passtext], :subs => Substitutors::NORMAL_SUBS) diff --git a/resources/asciidoctor/lib/copy_images/extension.rb b/resources/asciidoctor/lib/copy_images/extension.rb index 7fe3accb4a889..821ab2195f899 100644 --- a/resources/asciidoctor/lib/copy_images/extension.rb +++ b/resources/asciidoctor/lib/copy_images/extension.rb @@ -27,12 +27,32 @@ def process_block block uri = block.image_uri(block.attr 'target') return if Helpers.uriish? uri # Skip external images copy_image block, uri - elsif (extension = block.document.attr 'copy-callout-images') && - block.parent && - block.parent.context == :colist - id = block.attr('coids').scan(/CO(?:\d+)-(\d+)/) { - copy_image block, "images/icons/callouts/#{$1}.#{extension}" - } + return + end + callout_extension = block.document.attr 'copy-callout-images' + if callout_extension + if block.parent && block.parent.context == :colist + block.attr('coids').scan(/CO(?:\d+)-(\d+)/) { + copy_image block, "images/icons/callouts/#{$1}.#{callout_extension}" + } + return + end + end + admonition_extension = block.document.attr 'copy-admonition-images' + if admonition_extension + if block.context == :admonition + # The image for a standard admonition comes from the style + style = block.attr 'style' + return unless style + copy_image block, "images/icons/#{style.downcase(:ascii)}.#{admonition_extension}" + return + end + # The image for a change admonition comes from the revisionflag + revisionflag = block.attr 'revisionflag' + if revisionflag + copy_image block, "images/icons/#{revisionflag}.#{admonition_extension}" + return + end end end diff --git a/resources/asciidoctor/spec/copy_images_spec.rb b/resources/asciidoctor/spec/copy_images_spec.rb index 0f0edc97ecfd6..65c0b3f14d36f 100644 --- a/resources/asciidoctor/spec/copy_images_spec.rb +++ b/resources/asciidoctor/spec/copy_images_spec.rb @@ -1,3 +1,4 @@ +require 'change_admonishment/extension' require 'copy_images/extension' require 'fileutils' require 'tmpdir' @@ -6,6 +7,7 @@ RSpec::Matchers.define_negated_matcher :not_match, :match before(:each) do + Extensions.register ChangeAdmonishment Extensions.register do tree_processor CopyImages end @@ -375,4 +377,72 @@ def copy_attributes copied convert input, attributes expect(copied).to eq([]) end + + ['note', 'tip', 'important', 'caution', 'warning'].each { |(name)| + it "copies images for the #{name} admonition when requested" do + copied = [] + attributes = copy_attributes copied + attributes['copy-admonition-images'] = 'png' + input = <<~ASCIIDOC + #{name.upcase}: Words words words. + ASCIIDOC + expected_warnings = <<~WARNINGS + INFO: : line 1: copying #{spec_dir}/resources/copy_images/images/icons/#{name}.png + WARNINGS + convert input, attributes, eq(expected_warnings.strip) + expect(copied).to eq([ + ["images/icons/#{name}.png", "#{spec_dir}/resources/copy_images/images/icons/#{name}.png"], + ]) + end + } + + [ + ['added', 'added'], + ['coming', 'changed'], + ['deprecated', 'deleted'] + ].each { |(name, revisionflag)| + it "copies images for the block formatted #{name} change admonition when requested" do + copied = [] + attributes = copy_attributes copied + attributes['copy-admonition-images'] = 'png' + input = <<~ASCIIDOC + #{name}::[some_version] + ASCIIDOC + # We can't get the location of the blocks because asciidoctor doesn't + # make it available to us here! + expected_warnings = <<~WARNINGS + INFO: copying #{spec_dir}/resources/copy_images/images/icons/#{revisionflag}.png + WARNINGS + convert input, attributes, eq(expected_warnings.strip) + expect(copied).to eq([ + ["images/icons/#{revisionflag}.png", "#{spec_dir}/resources/copy_images/images/icons/#{revisionflag}.png"], + ]) + end + } + + it "copies images for admonitions when requested with a different file extension" do + copied = [] + attributes = copy_attributes copied + attributes['copy-admonition-images'] = 'gif' + input = <<~ASCIIDOC + NOTE: Words words words. + ASCIIDOC + expected_warnings = <<~WARNINGS + INFO: : line 1: copying #{spec_dir}/resources/copy_images/images/icons/note.gif + WARNINGS + convert input, attributes, eq(expected_warnings.strip) + expect(copied).to eq([ + ["images/icons/note.gif", "#{spec_dir}/resources/copy_images/images/icons/note.gif"], + ]) + end + + it "doesn't copy images for admonitions if not requested" do + copied = [] + attributes = copy_attributes copied + input = <<~ASCIIDOC + NOTE: Words words words. + ASCIIDOC + convert input, attributes + expect(copied).to eq([]) + end end \ No newline at end of file diff --git a/resources/asciidoctor/spec/resources/copy_images/images/icons/added.png b/resources/asciidoctor/spec/resources/copy_images/images/icons/added.png new file mode 100644 index 0000000000000..f37764b1f7606 Binary files /dev/null and b/resources/asciidoctor/spec/resources/copy_images/images/icons/added.png differ diff --git a/resources/asciidoctor/spec/resources/copy_images/images/icons/caution.png b/resources/asciidoctor/spec/resources/copy_images/images/icons/caution.png new file mode 100644 index 0000000000000..f37764b1f7606 Binary files /dev/null and b/resources/asciidoctor/spec/resources/copy_images/images/icons/caution.png differ diff --git a/resources/asciidoctor/spec/resources/copy_images/images/icons/changed.png b/resources/asciidoctor/spec/resources/copy_images/images/icons/changed.png new file mode 100644 index 0000000000000..f37764b1f7606 Binary files /dev/null and b/resources/asciidoctor/spec/resources/copy_images/images/icons/changed.png differ diff --git a/resources/asciidoctor/spec/resources/copy_images/images/icons/deleted.png b/resources/asciidoctor/spec/resources/copy_images/images/icons/deleted.png new file mode 100644 index 0000000000000..f37764b1f7606 Binary files /dev/null and b/resources/asciidoctor/spec/resources/copy_images/images/icons/deleted.png differ diff --git a/resources/asciidoctor/spec/resources/copy_images/images/icons/important.png b/resources/asciidoctor/spec/resources/copy_images/images/icons/important.png new file mode 100644 index 0000000000000..f37764b1f7606 Binary files /dev/null and b/resources/asciidoctor/spec/resources/copy_images/images/icons/important.png differ diff --git a/resources/asciidoctor/spec/resources/copy_images/images/icons/note.gif b/resources/asciidoctor/spec/resources/copy_images/images/icons/note.gif new file mode 100644 index 0000000000000..3c51d740ca812 Binary files /dev/null and b/resources/asciidoctor/spec/resources/copy_images/images/icons/note.gif differ diff --git a/resources/asciidoctor/spec/resources/copy_images/images/icons/note.png b/resources/asciidoctor/spec/resources/copy_images/images/icons/note.png new file mode 100644 index 0000000000000..f37764b1f7606 Binary files /dev/null and b/resources/asciidoctor/spec/resources/copy_images/images/icons/note.png differ diff --git a/resources/asciidoctor/spec/resources/copy_images/images/icons/tip.png b/resources/asciidoctor/spec/resources/copy_images/images/icons/tip.png new file mode 100644 index 0000000000000..f37764b1f7606 Binary files /dev/null and b/resources/asciidoctor/spec/resources/copy_images/images/icons/tip.png differ diff --git a/resources/asciidoctor/spec/resources/copy_images/images/icons/warning.png b/resources/asciidoctor/spec/resources/copy_images/images/icons/warning.png new file mode 100644 index 0000000000000..f37764b1f7606 Binary files /dev/null and b/resources/asciidoctor/spec/resources/copy_images/images/icons/warning.png differ