Class: Fastlane::Notification::Slack::LinkConverter

Inherits:
Object
  • Object
show all
Defined in:
fastlane/lib/fastlane/notification/slack.rb

Overview

Constant Summary collapse

HTML_PATTERN =
%r{<a.*?href=['"](?<link>#{URI.regexp})['"].*?>(?<label>.+?)<\/a>}
MARKDOWN_PATTERN =
/\[(?<label>[^\[\]]*?)\]\((?<link>#{URI.regexp}|mailto:#{URI::MailTo::EMAIL_REGEXP})\)/

Class Method Summary collapse

Class Method Details

.convert(string) ⇒ Object



33
34
35
# File 'fastlane/lib/fastlane/notification/slack.rb', line 33

def self.convert(string)
  convert_markdown_to_slack_link(convert_html_to_slack_link(string.scrub))
end


37
38
39
40
41
# File 'fastlane/lib/fastlane/notification/slack.rb', line 37

def self.convert_html_to_slack_link(string)
  string.gsub(HTML_PATTERN) do |match|
    slack_link(Regexp.last_match[:link], Regexp.last_match[:label])
  end
end


43
44
45
46
47
# File 'fastlane/lib/fastlane/notification/slack.rb', line 43

def self.convert_markdown_to_slack_link(string)
  string.gsub(MARKDOWN_PATTERN) do |match|
    slack_link(Regexp.last_match[:link], Regexp.last_match[:label])
  end
end


49
50
51
52
# File 'fastlane/lib/fastlane/notification/slack.rb', line 49

def self.slack_link(href, text)
  return "<#{href}>" if text.nil? || text.empty?
  "<#{href}|#{text}>"
end