class Slack::Notifier::Util::LinkFormatter

Constants

HTML_PATTERN

rubular.com/r/19cNXW5qbH

MARKDOWN_PATTERN

Attempt at only matching pairs of parens per the markdown spec spec.commonmark.org/0.27/#links

rubular.com/r/y107aevxqT

VALID_PATH_CHARS

the path portion of a url can contain these characters

Attributes

formats[R]

Public Class Methods

format(string, opts={}) click to toggle source
# File lib/slack-notifier/util/link_formatter.rb, line 31
def format string, opts={}
  LinkFormatter.new(string, **opts).formatted
end
new(string, formats: %i[html markdown]) click to toggle source
# File lib/slack-notifier/util/link_formatter.rb, line 38
def initialize string, formats: %i[html markdown]
  @formats = formats
  @orig    = string.respond_to?(:scrub) ? string.scrub : string
end

Public Instance Methods

formatted() click to toggle source

rubocop:disable Lint/RescueWithoutErrorClass

# File lib/slack-notifier/util/link_formatter.rb, line 44
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.message.include?("invalid byte sequence")
  raise e, "#{e.message}. Consider including the 'string-scrub' gem to strip invalid characters"
end

Private Instance Methods