1 defmodule Pleroma.Formatter do
4 @link_regex ~r/https?:\/\/[\w\.\/?=\-#%&]+[\w]/u
6 Regex.replace(@link_regex, text, "<a href='\\0'>\\0</a>")
10 def parse_tags(text) do
11 Regex.scan(@tag_regex, text)
12 |> Enum.map(fn (["#" <> tag = full_tag]) -> {full_tag, String.downcase(tag)} end)
15 def parse_mentions(text) do
16 # Modified from https://www.w3.org/TR/html5/forms.html#valid-e-mail-address
17 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])?)*/u
19 Regex.scan(regex, text)
22 |> Enum.map(fn ("@" <> match = full_match) -> {full_match, User.get_cached_by_nickname(match)} end)
23 |> Enum.filter(fn ({_match, user}) -> user end)
26 def finmojifiy(text) do
43 "four_seasons_of_bbq",
69 "pusa_hispida_saimensis",
93 Enum.reduce(emoji_list, text, fn (emoji, text) ->
94 String.replace(text, ":#{String.replace(emoji, "_", "")}:", "<img height='32px' width='32px' alt='#{emoji}' title='#{String.replace(emoji, "_", "")}' src='#{Pleroma.Web.Endpoint.static_url}/finmoji/128px/#{emoji}-128.png' />")