2018-06-20 09:53:19 -04:00
|
|
|
module Gitlab
|
|
|
|
module HookData
|
|
|
|
class BaseBuilder
|
|
|
|
attr_accessor :object
|
|
|
|
|
2018-07-06 06:35:30 -04:00
|
|
|
MARKDOWN_SIMPLE_IMAGE = %r{
|
|
|
|
#{::Gitlab::Regex.markdown_code_or_html_blocks}
|
|
|
|
|
|
|
|
|
(?<image>
|
|
|
|
!
|
|
|
|
\[(?<title>[^\n]*?)\]
|
|
|
|
\((?<url>(?!(https?://|//))[^\n]+?)\)
|
|
|
|
)
|
|
|
|
}mx.freeze
|
|
|
|
|
2018-06-20 09:53:19 -04:00
|
|
|
def initialize(object)
|
|
|
|
@object = object
|
|
|
|
end
|
|
|
|
|
2018-07-17 09:58:14 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def absolute_image_urls(markdown_text)
|
2018-07-06 06:35:30 -04:00
|
|
|
return markdown_text unless markdown_text.present?
|
|
|
|
|
|
|
|
markdown_text.gsub(MARKDOWN_SIMPLE_IMAGE) do
|
|
|
|
if $~[:image]
|
2018-07-06 08:44:45 -04:00
|
|
|
url = $~[:url]
|
|
|
|
url = "/#{url}" unless url.start_with?('/')
|
|
|
|
|
|
|
|
"![#{$~[:title]}](#{Gitlab.config.gitlab.url}#{url})"
|
2018-07-06 06:35:30 -04:00
|
|
|
else
|
|
|
|
$~[0]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-06-20 09:53:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|