Module: Slack::Messages::Formatting

Defined in:
lib/slack/messages/formatting.rb

Class Method Summary collapse

Class Method Details

.unescape(message) ⇒ Object

Unescape a message.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/slack/messages/formatting.rb', line 9

def unescape(message)
  CGI.unescapeHTML(message.gsub(/[“”]/, '"')
    .gsub(/[‘’]/, "'")
    .gsub(/<(?<sign>[?@#!]?)(?<dt>.*?)>/) do
      sign = Regexp.last_match[:sign]
      dt = Regexp.last_match[:dt]
      rhs = dt.split('|', 2).last
      case sign
      when '@', '!'
        "@#{rhs}"
      when '#'
        "##{rhs}"
      else
        rhs
      end
    end)
end