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



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

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


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

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


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

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


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

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