debian-mirror-gitlab/lib/gitlab/file_markdown_link_builder.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

24 lines
611 B
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2018-11-20 20:47:30 +05:30
# Builds the markdown link of a file
# It needs the methods filename and secure_url (final destination url) to be defined.
module Gitlab
module FileMarkdownLinkBuilder
include FileTypeDetection
def markdown_link
return unless name = markdown_name
markdown = "[#{name.gsub(']', '\\]')}](#{secure_url})"
2019-12-21 20:55:43 +05:30
markdown = "!#{markdown}" if embeddable? || dangerous_embeddable?
2018-11-20 20:47:30 +05:30
markdown
end
def markdown_name
return unless filename.present?
2019-12-21 20:55:43 +05:30
embeddable? ? File.basename(filename, File.extname(filename)) : filename
2018-11-20 20:47:30 +05:30
end
end
end