UX: Don't add light box for SVG images.

This commit is contained in:
Guo Xiang Tan 2018-06-18 17:10:23 +08:00
parent f1d1207725
commit c18b86d9b2
2 changed files with 24 additions and 6 deletions

View File

@ -269,7 +269,7 @@ class CookedPostProcessor
def convert_to_link!(img) def convert_to_link!(img)
src = img["src"] 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 width, height = img["width"].to_i, img["height"].to_i
# TODO: store original dimentions in db # TODO: store original dimentions in db
@ -538,4 +538,10 @@ class CookedPostProcessor
@doc.try(:to_html) @doc.try(:to_html)
end end
private
def is_svg?(img)
File.extname(img["src"]) == '.svg'
end
end end

View File

@ -152,15 +152,15 @@ describe CookedPostProcessor do
before do before do
SiteSetting.max_image_height = 2000 SiteSetting.max_image_height = 2000
SiteSetting.create_thumbnails = true SiteSetting.create_thumbnails = true
Upload.expects(:get_from_url).returns(upload)
FastImage.expects(:size).returns([1750, 2000]) FastImage.expects(:size).returns([1750, 2000])
OptimizedImage.expects(:resize).returns(true)
FileStore::BaseStore.any_instance.expects(:get_depth_for).returns(0)
end end
it "generates overlay information" do it "generates overlay information" do
Upload.expects(:get_from_url).returns(upload)
OptimizedImage.expects(:resize).returns(true)
FileStore::BaseStore.any_instance.expects(:get_depth_for).returns(0)
cpp.post_process_images cpp.post_process_images
expect(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\"> expect(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> <span class=\"filename\">logo.png</span><span class=\"informations\">1750x2000 1.21 KB</span><span class=\"expand\"></span>
@ -168,6 +168,18 @@ describe CookedPostProcessor do
expect(cpp).to be_dirty expect(cpp).to be_dirty
end end
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
end end
context "with tall images" do context "with tall images" do