A platform for community discussion. Free, open, simple.
UX: Don't add light box for SVG images.
Guo Xiang Tanc18b86d9b2b0
diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rbindex e1a44fa783c..12e2d35e056 100644--- a/lib/cooked_post_processor.rb+++ b/lib/cooked_post_processor.rb@@ -269,7 +269,7 @@ class CookedPostProcessordef convert_to_link!(img)src = img["src"]- return if src.blank? || is_a_hyperlink?(img)+ return if src.blank? || is_a_hyperlink?(img) || is_svg?(img)width, height = img["width"].to_i, img["height"].to_i# TODO: store original dimentions in db@@ -538,4 +538,10 @@ class CookedPostProcessor@doc.try(:to_html)end+ private++ def is_svg?(img)+ File.extname(img["src"]) == '.svg'+ end+enddiff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rbindex 103bbc4f799..1c3da190cca 100644--- a/spec/components/cooked_post_processor_spec.rb+++ b/spec/components/cooked_post_processor_spec.rb@@ -152,15 +152,15 @@ describe CookedPostProcessor dobefore doSiteSetting.max_image_height = 2000SiteSetting.create_thumbnails = true+ FastImage.expects(:size).returns([1750, 2000])+ end+ it "generates overlay information" doUpload.expects(:get_from_url).returns(upload)- FastImage.expects(:size).returns([1750, 2000])OptimizedImage.expects(:resize).returns(true)FileStore::BaseStore.any_instance.expects(:get_depth_for).returns(0)- end- it "generates overlay information" docpp.post_process_imagesexpect(cpp.html).to match_html "<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"/uploads/default/1/1234567890123456.jpg\" data-download-href=\"/uploads/default/#{upload.sha1}\" title=\"logo.png\"><img src=\"/uploads/default/optimized/1X/#{upload.sha1}_1_690x788.png\" width=\"690\" height=\"788\"><div class=\"meta\"><span class=\"filename\">logo.png</span><span class=\"informations\">1750x2000 1.21 KB</span><span class=\"expand\"></span>@@ -168,6 +168,18 @@ describe CookedPostProcessor doexpect(cpp).to be_dirtyend+ describe 'when image is an svg' do+ let(:post) do+ Fabricate(:post, raw: '<img src="/uploads/default/1/1234567890123456.svg">')+ end++ it 'should not add lightbox' do+ cpp.post_process_images++ expect(cpp.html).to match_html("<p><img src=\"/uploads/default/1/1234567890123456.svg\" width=\"690\"\ height=\"788\"></p>")+ end+ end+endcontext "with tall images" do