diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 527ee7c62..d7267267b 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -10,6 +10,7 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co Improvements:: * don't hyphenate autolink when hyphenation is enabled (#2521) (*@meonkeys*) +* add support for base64-encoded SVG image reference in SVG (#2512) Bug Fixes:: diff --git a/lib/asciidoctor/pdf/ext/prawn-svg/loaders/data.rb b/lib/asciidoctor/pdf/ext/prawn-svg/loaders/data.rb index 3f4882a44..34f4a3dd0 100644 --- a/lib/asciidoctor/pdf/ext/prawn-svg/loaders/data.rb +++ b/lib/asciidoctor/pdf/ext/prawn-svg/loaders/data.rb @@ -2,5 +2,5 @@ class Prawn::SVG::Loaders::Data remove_const :REGEXP - REGEXP = %r(\Adata:image/(?:png|jpe?g);base64(?:;[a-z0-9]+)*,)i + REGEXP = %r(\Adata:image/(?:png|jpe?g|svg\+xml);base64(?:;[a-z0-9]+)*,)i end diff --git a/spec/fixtures/svg-with-data-uri-svg-image.svg b/spec/fixtures/svg-with-data-uri-svg-image.svg new file mode 100644 index 000000000..612de276a --- /dev/null +++ b/spec/fixtures/svg-with-data-uri-svg-image.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/spec/image_spec.rb b/spec/image_spec.rb index f6298827d..c6c83e96e 100644 --- a/spec/image_spec.rb +++ b/spec/image_spec.rb @@ -993,6 +993,12 @@ def traverse node (expect to_file).to visually_match 'image-block-svg-with-image.pdf' end + it 'should embed SVG image from data-uri in SVG', visual: true do + pdf = to_pdf 'image::svg-with-data-uri-svg-image.svg[]', analyze: :rect + (expect pdf.rectangles).to have_size 1 + (expect pdf.rectangles[0][:fill_color]).to eql 'FF0000' + end + it 'should support non-standard image/jpg MIME type', visual: true do image_data = File.binread fixture_file 'square.jpg' pdf = to_pdf 'image::svg-with-data-uri-jpg-image.svg[pdfwidth=1.27cm]', analyze: :image