Commit c7b04841 authored by Connor Shea's avatar Connor Shea

Wrap images in divs with Banzai and limit max-height.

Add max-height to prevent images from displaying larger than the provided screen size.

Also fix a failing test and add a new one.
parent f48f7760
...@@ -4,6 +4,7 @@ v 8.10.0 (unreleased) ...@@ -4,6 +4,7 @@ v 8.10.0 (unreleased)
- Replace Haml with Hamlit to make view rendering faster. !3666 - Replace Haml with Hamlit to make view rendering faster. !3666
- Wrap code blocks on Activies and Todos page. !4783 (winniehell) - Wrap code blocks on Activies and Todos page. !4783 (winniehell)
- Add Sidekiq queue duration to transaction metrics. - Add Sidekiq queue duration to transaction metrics.
- Make images fit to the size of the viewport !4810
- Fix MR-auto-close text added to description. !4836 - Fix MR-auto-close text added to description. !4836
- Fix pagination when sorting by columns with lots of ties (like priority) - Fix pagination when sorting by columns with lots of ties (like priority)
- Exclude email check from the standard health check - Exclude email check from the standard health check
......
...@@ -63,5 +63,6 @@ ...@@ -63,5 +63,6 @@
border: 1px solid $table-border-gray; border: 1px solid $table-border-gray;
padding: 5px; padding: 5px;
margin: 5px; margin: 5px;
max-height: calc(100vh - 100px);
} }
} }
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
border: 1px solid $table-border-gray; border: 1px solid $table-border-gray;
padding: 5px; padding: 5px;
margin: 5px; margin: 5px;
max-height: calc(100vh - 100px);
} }
} }
......
...@@ -113,6 +113,7 @@ ul.notes { ...@@ -113,6 +113,7 @@ ul.notes {
border: 1px solid $table-border-gray; border: 1px solid $table-border-gray;
padding: 5px; padding: 5px;
margin: 5px 0; margin: 5px 0;
max-height: calc(100vh - 100px);
} }
} }
} }
......
...@@ -9,6 +9,11 @@ module Banzai ...@@ -9,6 +9,11 @@ module Banzai
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',
...@@ -17,7 +22,10 @@ module Banzai ...@@ -17,7 +22,10 @@ module Banzai
) )
link.children = img.clone link.children = img.clone
img.replace(link)
div.children = 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 'should have XHTML summaries in merge request descriptions' do it 'should have XHTML summaries in merge request descriptions' do
expect(body).to match /Here is the fix: <a[^>]*><img[^>]*\/><\/a>/ expect(body).to match /Here is the fix: <\/p><div[^>]*><a[^>]*><img[^>]*\/><\/a><\/div>/
end end
end end
end end
......
...@@ -21,4 +21,9 @@ describe Banzai::Filter::ImageLinkFilter, lib: true do ...@@ -21,4 +21,9 @@ describe Banzai::Filter::ImageLinkFilter, lib: true do
doc = filter(image('https://i.imgur.com/DfssX9C.jpg')) doc = filter(image('https://i.imgur.com/DfssX9C.jpg'))
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
doc = filter(image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg'))
expect(doc.to_html).to include('<div class="image-container">')
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