Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def string_to_src(url)
- if url[/(?:png|jpe?g|gif|svg)$/]
- "<img src='#{url}' / class='link-image thumbnail'>".html_safe
- elsif url[/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix]
- "<a href='#{url}' target='_blank'>#{url}</a>".html_safe
- elsif url[/^(?:https?:\/\/)?(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch\?v=)?([\w-]{10,})/]
- # "<iframe width='420' height='315' src='#{url}' frameborder='0' allowfullscreen></iframe>".html_safe
- else
- url
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment