Add Camo for <img>-tags inside Markdown contents
This commit is contained in:
parent
e68704890e
commit
aec00f834f
2 changed files with 9 additions and 1 deletions
|
|
@ -3,9 +3,12 @@ module Diaspora
|
||||||
module Camo
|
module Camo
|
||||||
def self.from_markdown(markdown_text)
|
def self.from_markdown(markdown_text)
|
||||||
return unless markdown_text
|
return unless markdown_text
|
||||||
markdown_text.gsub(/(!\[(.*?)\]\s?\([ \t]*()<?(\S+?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/m) do |link|
|
markdown_text.gsub!(/(!\[(.*?)\]\s?\([ \t]*()<?(\S+?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/m) do |link|
|
||||||
link.gsub($4, self.image_url($4))
|
link.gsub($4, self.image_url($4))
|
||||||
end
|
end
|
||||||
|
markdown_text.gsub(/src=(['"])(.+?)\1/m) do |link|
|
||||||
|
link.gsub($2, self.image_url($2))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.image_url(url)
|
def self.image_url(url)
|
||||||
|
|
|
||||||
|
|
@ -46,5 +46,10 @@ describe Diaspora::Camo do
|
||||||
it 'should rewrite markdown images with title texts' do
|
it 'should rewrite markdown images with title texts' do
|
||||||
expect(Diaspora::Camo.from_markdown(" \"title\"")).to include(@camo_image_url)
|
expect(Diaspora::Camo.from_markdown(" \"title\"")).to include(@camo_image_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should rewrite URLs inside <img/> tags' do
|
||||||
|
image_tag = '<img src="' + @raw_image_url + '" />'
|
||||||
|
expect(Diaspora::Camo.from_markdown(image_tag)).to include(@camo_image_url)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue