Fix inline comment images by removing wrapper #20890

This commit is contained in:
Jared Deckard 2016-08-13 00:13:39 -05:00
parent 30f5b9a5b7
commit 2c0f375f13
3 changed files with 5 additions and 12 deletions

View File

@ -8,11 +8,6 @@ module Banzai
# of the anchor, and then replace the img with the link-wrapped version.
def call
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(
'a',
class: 'no-attachment-icon',
@ -22,9 +17,7 @@ module Banzai
link.children = img.clone
div.children = link
img.replace(div)
img.replace(link)
end
doc

View File

@ -61,7 +61,7 @@ describe "User Feed", feature: true do
end
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

View File

@ -22,8 +22,8 @@ describe Banzai::Filter::ImageLinkFilter, lib: true do
expect(doc.at_css('img')['src']).to eq doc.at_css('a')['href']
end
it 'wraps the image with a link and a div' do
doc = filter(image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg'))
expect(doc.to_html).to include('<div class="image-container">')
it 'works with inline images' do
doc = filter(%Q(<p>test #{image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')} inline</p>))
expect(doc.to_html).to match /^<p>test <a[^>]*><img[^>]*><\/a> inline<\/p>$/
end
end