Commit e051ef69 authored by Robert Speicher's avatar Robert Speicher

Merge branch '20890-comment-image-inline' into 'master'

Fix inline comment images by removing wrapper #20890

Closes #20890

See merge request !5804
parents 5cd79bd6 b8cab61f
Pipeline #6716426 failed with stages
in 77 minutes and 15 seconds
...@@ -8,11 +8,6 @@ module Banzai ...@@ -8,11 +8,6 @@ module Banzai
# of the anchor, and then replace the img with the link-wrapped version. # of the anchor, and then replace the img with the link-wrapped version.
def call def call
doc.xpath('descendant-or-self::img[not(ancestor::a)]').each do |img| doc.xpath('descendant-or-self::img[not(ancestor::a)]').each do |img|
div = doc.document.create_element(
'div',
class: 'image-container'
)
link = doc.document.create_element( link = doc.document.create_element(
'a', 'a',
class: 'no-attachment-icon', class: 'no-attachment-icon',
...@@ -22,9 +17,7 @@ module Banzai ...@@ -22,9 +17,7 @@ module Banzai
link.children = img.clone link.children = img.clone
div.children = link img.replace(link)
img.replace(div)
end end
doc doc
......
...@@ -61,7 +61,7 @@ describe "User Feed", feature: true do ...@@ -61,7 +61,7 @@ describe "User Feed", feature: true do
end end
it 'has XHTML summaries in merge request descriptions' do it 'has XHTML summaries in merge request descriptions' do
expect(body).to match /Here is the fix: <\/p><div[^>]*><a[^>]*><img[^>]*\/><\/a><\/div>/ expect(body).to match /Here is the fix: <a[^>]*><img[^>]*\/><\/a>/
end end
end end
end end
......
...@@ -13,8 +13,8 @@ describe Banzai::Filter::ImageLinkFilter, lib: true do ...@@ -13,8 +13,8 @@ describe Banzai::Filter::ImageLinkFilter, lib: true do
end end
it 'does not wrap a duplicate link' do it 'does not wrap a duplicate link' do
exp = act = %q(<a href="/whatever">#{image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')}</a>) doc = filter(%Q(<a href="/whatever">#{image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')}</a>))
expect(filter(act).to_html).to eq exp expect(doc.to_html).to match /^<a href="\/whatever"><img[^>]*><\/a>$/
end end
it 'works with external images' do it 'works with external images' do
...@@ -22,8 +22,8 @@ describe Banzai::Filter::ImageLinkFilter, lib: true do ...@@ -22,8 +22,8 @@ describe Banzai::Filter::ImageLinkFilter, lib: true do
expect(doc.at_css('img')['src']).to eq doc.at_css('a')['href'] expect(doc.at_css('img')['src']).to eq doc.at_css('a')['href']
end end
it 'wraps the image with a link and a div' do it 'works with inline images' do
doc = filter(image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')) doc = filter(%Q(<p>test #{image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')} inline</p>))
expect(doc.to_html).to include('<div class="image-container">') expect(doc.to_html).to match /^<p>test <a[^>]*><img[^>]*><\/a> inline<\/p>$/
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment