Skip to content

Commit

Permalink
Better comments on link regex
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhammond committed Dec 16, 2014
1 parent c1fec0c commit 426f16d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/slack.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,13 @@ class SlackBot extends Adapter

removeFormatting: (txt) ->
# https://api.slack.com/docs/formatting
txt = txt.replace /\<([\@\#\!])(\w+)(?:\|([^>]+))?\>/g, (m, type, id, label) =>

txt = txt.replace ///
< # opening angle bracket
([\@\#\!]) # link type
(\w+) # id
(?:\|([^>]+))? # |label (optional)
> # closing angle bracket
///g, (m, type, id, label) =>
if label then return label

switch type
Expand All @@ -143,7 +148,13 @@ class SlackBot extends Adapter
if id in ['channel','group','everyone']
return "@#{id}"
"#{type}#{id}"
txt = txt.replace /<([^>\|]+)(?:\|([^>]+))?\>/g, (m, link, label) =>

txt = txt.replace ///
< # opening angle bracket
([^>\|]+) # link
(?:\|([^>]+))? # label
> # closing angle bracket
///g, (m, link, label) =>
if label
"#{label} #{link}"
else
Expand Down

0 comments on commit 426f16d

Please sign in to comment.