forked from slack-ruby/slack-ruby-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformatting.rb
More file actions
30 lines (30 loc) · 752 Bytes
/
formatting.rb
File metadata and controls
30 lines (30 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true
module Slack
module Messages
module Formatting
class << self
#
# Unescape a message.
# @see https://api.slack.com/docs/formatting
#
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
end
end
end
end