Skip to content

Commit

Permalink
FIX: only add image size when with & height are in pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
ZogStriP committed Jul 5, 2019
1 parent 589351d commit 155cad8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/services/inline_uploads.rb
Expand Up @@ -220,10 +220,10 @@ def self.match_img(markdown, external_src: false)

if src && (matched_uploads(src).present? || external_src)
text = node.attributes["alt"]&.value
width = node.attributes["width"]&.value
height = node.attributes["height"]&.value
width = node.attributes["width"]&.value.to_i
height = node.attributes["height"]&.value.to_i
title = node.attributes["title"]&.value
text = "#{text}|#{width}x#{height}" if width && height
text = "#{text}|#{width}x#{height}" if width > 0 && height > 0
after_html_tag = match[0].present?

spaces_before =
Expand Down
2 changes: 2 additions & 0 deletions spec/services/inline_uploads_spec.rb
Expand Up @@ -267,6 +267,7 @@
#{Discourse.base_url}#{upload3.url} #{Discourse.base_url}#{upload3.url}
<img src="#{upload.url}" width="5" height="4">
<img src="#{upload.url}" width="5px" height="auto">
MD

expect(InlineUploads.process(md)).to eq(<<~MD)
Expand All @@ -283,6 +284,7 @@
#{Discourse.base_url}#{upload3.short_path} #{Discourse.base_url}#{upload3.short_path}
![|5x4](#{upload.short_url})
![](#{upload.short_url})
MD
end

Expand Down

0 comments on commit 155cad8

Please sign in to comment.