aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/formatter.ex
diff options
context:
space:
mode:
authorRoger Braun <roger@rogerbraun.net>2017-06-14 13:58:56 +0200
committerRoger Braun <roger@rogerbraun.net>2017-06-14 13:58:56 +0200
commit1af9c777365f3b54edcb572cea4e2e6f185b3099 (patch)
tree52e6e8b21c265dda04cbdfaadffdc30ed32f8313 /lib/pleroma/formatter.ex
parent93764439730d708a9a07375f9d840e8dd32156fb (diff)
downloadpleroma-1af9c777365f3b54edcb572cea4e2e6f185b3099.tar.gz
Move mention parsing to Formatter module.
Diffstat (limited to 'lib/pleroma/formatter.ex')
-rw-r--r--lib/pleroma/formatter.ex12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex
index 5d989bc8c..5a241fe45 100644
--- a/lib/pleroma/formatter.ex
+++ b/lib/pleroma/formatter.ex
@@ -1,4 +1,5 @@
defmodule Pleroma.Formatter do
+ alias Pleroma.User
@link_regex ~r/https?:\/\/[\w\.\/?=\-#]+[\w]/
def linkify(text) do
@@ -10,4 +11,15 @@ defmodule Pleroma.Formatter do
Regex.scan(@tag_regex, text)
|> Enum.map(fn (["#" <> tag = full_tag]) -> {full_tag, tag} end)
end
+
+ def parse_mentions(text) do
+ # Modified from https://www.w3.org/TR/html5/forms.html#valid-e-mail-address
+ regex = ~r/@[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@?[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*/
+
+ Regex.scan(regex, text)
+ |> List.flatten
+ |> Enum.uniq
+ |> Enum.map(fn ("@" <> match = full_match) -> {full_match, User.get_cached_by_nickname(match)} end)
+ |> Enum.filter(fn ({_match, user}) -> user end)
+ end
end