diff options
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/pdf/converter.rb | 1 | ||||
| -rw-r--r-- | spec/running_content_spec.rb | 47 |
3 files changed, 49 insertions, 0 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 0ae2ab66..f6377ef2 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -9,6 +9,7 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co Bug Fixes:: +* resolve attribute references in target of image in running content (#2361) * replace use of AbstractNode#role= method to ensure compatiblity with minimum supported version of Asciidoctor (Asciidoctor 2.0.10) (#2363) == 2.3.3 (2022-10-21) - @mojavelinux diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index 4168d7ef..de31fe65 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -3435,6 +3435,7 @@ module Asciidoctor attrlist = $2 image_attrs = (AttributeList.new attrlist).parse %w(alt width) image_path, image_format = ::Asciidoctor::Image.target_and_format $1, image_attrs + image_path = apply_subs_discretely doc, image_path, subs: [:attributes], imagesdir: @themesdir if (image_path = resolve_image_path doc, image_path, image_format, @themesdir) && (::File.readable? image_path) image_opts = resolve_image_options image_path, image_format, image_attrs, container_size: [colspec_dict[side][position][:width], trim_content_height[side]] side_content[position] = [image_path, image_opts, image_attrs['link']] diff --git a/spec/running_content_spec.rb b/spec/running_content_spec.rb index 45c76cd1..2100f1ea 100644 --- a/spec/running_content_spec.rb +++ b/spec/running_content_spec.rb @@ -2950,6 +2950,53 @@ describe 'Asciidoctor::PDF::Converter - Running Content' do end).to log_message severity: :WARN, message: %(~could not embed image in running content: #{fixture_file 'broken.svg'}; Missing end tag for 'rect') end + it 'should resolve attribute references in target of inline image' do + expected_image_data = File.binread example_file 'sample-logo.jpg' + %w(docdir docimagesdir).each do |name| + pdf_theme = { + page_margin: 36, + footer_height: 36, + footer_columns: '=100%', + footer_recto_center_content: %(image:{#{name}}/sample-logo.jpg[fit=line]), + footer_recto_right_content: nil, + } + + input = Pathname.new example_file 'basic-example.adoc' + pdf = to_pdf input, pdf_theme: pdf_theme, attributes: { 'source-highlighter' => nil }, enable_footer: true + images = get_images pdf + (expect images).to have_size 1 + (expect images[0].data).to eql expected_image_data + end + end + + it 'should resolve page-layout attribute references in target of inline image' do + pdf_theme = { + __dir__: fixtures_dir, + page_margin: 36, + footer_height: 36, + footer_columns: '=100%', + footer_recto_center_content: %(image:square-{page-layout}.svg[fit=line]), + footer_verso_center_content: %(image:square-{page-layout}.svg[fit=line]), + footer_recto_right_content: nil, + footer_verso_left_content: nil, + } + + input = <<~'EOS' + portrait + + [page-layout=landscape] + <<< + + landscape + EOS + rects = (to_pdf input, pdf_theme: pdf_theme, enable_footer: true, analyze: :rect).rectangles + (expect rects).to have_size 2 + (expect rects[0][:page_number]).to eql 1 + (expect rects[0][:fill_color]).to eql 'FF0000' + (expect rects[1][:page_number]).to eql 2 + (expect rects[1][:fill_color]).to eql '0000FF' + end + it 'should support data URI image', visual: true do image_data = File.binread fixture_file 'tux.png' encoded_image_data = Base64.strict_encode64 image_data |
