Class: Fastlane::Notification::Slack::LinkConverter
- Inherits:
-
Object
- Object
- Fastlane::Notification::Slack::LinkConverter
- Defined in:
- fastlane/lib/fastlane/notification/slack.rb
Overview
This class was inspired by ‘LinkFormatter` in `slack-notifier` gem github.com/stevenosloan/slack-notifier/blob/4bf6582663dc9e5070afe3fdc42d67c14a513354/lib/slack-notifier/util/link_formatter.rb
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
- .convert(string) ⇒ Object
- .convert_html_to_slack_link(string) ⇒ Object
- .convert_markdown_to_slack_link(string) ⇒ Object
- .slack_link(href, text) ⇒ Object
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 |
.convert_html_to_slack_link(string) ⇒ Object
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 |
.convert_markdown_to_slack_link(string) ⇒ Object
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 |
.slack_link(href, text) ⇒ Object
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 |