Class: Fastlane::Helper::SlackBotLinkFormatterHelper
- Inherits:
-
Object
- Object
- Fastlane::Helper::SlackBotLinkFormatterHelper
- Defined in:
- lib/fastlane/plugin/slack_bot/helper/slack_bot_link_formatter_helper.rb
Overview
Fastlane is moving away ‘slack-notifier’ gem, github.com/fastlane/fastlane/pull/18512 Duplicate of: github.com/stevenosloan/slack-notifier/blob/master/lib/slack-notifier/util/link_formatter.rb
Constant Summary collapse
- HTML_PATTERN =
%r{ <a (?:.*?) href=['"](.+?)['"] (?:.*?)> (.+?) </a> }x
- VALID_PATH_CHARS =
the path portion of a url can contain these characters
'\w\-\.\~\/\?\#\='
- MARKDOWN_PATTERN =
Attempt at only matching pairs of parens per the markdown spec spec.commonmark.org/0.27/#links
%r{ \[ ([^\[\]]*?) \] \( ((https?://.*?) | (mailto:.*?)) \) (?! [#{VALID_PATH_CHARS}]* \) ) }x
Instance Attribute Summary collapse
-
#formats ⇒ Object
readonly
Returns the value of attribute formats.
Class Method Summary collapse
Instance Method Summary collapse
-
#formatted ⇒ Object
rubocop:disable Lint/RescueWithoutErrorClass.
-
#initialize(string, opts = {}) ⇒ SlackBotLinkFormatterHelper
constructor
A new instance of SlackBotLinkFormatterHelper.
Constructor Details
#initialize(string, opts = {}) ⇒ SlackBotLinkFormatterHelper
Returns a new instance of SlackBotLinkFormatterHelper.
41 42 43 44 |
# File 'lib/fastlane/plugin/slack_bot/helper/slack_bot_link_formatter_helper.rb', line 41 def initialize string, opts = {} @formats = opts[:formats] || %i[html markdown] @orig = string.respond_to?(:scrub) ? string.scrub : string end |
Instance Attribute Details
#formats ⇒ Object (readonly)
Returns the value of attribute formats.
39 40 41 |
# File 'lib/fastlane/plugin/slack_bot/helper/slack_bot_link_formatter_helper.rb', line 39 def formats @formats end |
Class Method Details
.format(string, opts = {}) ⇒ Object
34 35 36 |
# File 'lib/fastlane/plugin/slack_bot/helper/slack_bot_link_formatter_helper.rb', line 34 def format string, opts={} SlackBotLinkFormatterHelper.new(string, **opts).formatted end |
Instance Method Details
#formatted ⇒ Object
rubocop:disable Lint/RescueWithoutErrorClass
47 48 49 50 51 52 53 54 |
# File 'lib/fastlane/plugin/slack_bot/helper/slack_bot_link_formatter_helper.rb', line 47 def formatted return @orig unless @orig.respond_to?(:gsub) sub_markdown_links(sub_html_links(@orig)) rescue => e raise e unless RUBY_VERSION < "2.1" && e..include?("invalid byte sequence") raise e, "#{e.}. Consider including the 'string-scrub' gem to strip invalid characters" end |