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, data \\ %{}) do
11 Regex.scan(@tag_regex, text)
12 |> Enum.map(fn (["#" <> tag = full_tag]) -> {full_tag, String.downcase(tag)} end)
13 |> (fn map -> if data["sensitive"], do: [{"#nsfw", "nsfw"}] ++ map, else: map end).()
16 def parse_mentions(text) do
17 # Modified from https://www.w3.org/TR/html5/forms.html#valid-e-mail-address
18 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
20 Regex.scan(regex, text)
23 |> Enum.map(fn ("@" <> match = full_match) -> {full_match, User.get_cached_by_nickname(match)} end)
24 |> Enum.filter(fn ({_match, user}) -> user end)
43 "four_seasons_of_bbq",
69 "pusa_hispida_saimensis",
93 @finmoji_with_filenames Enum.map(@finmoji, fn (finmoji) ->
94 {finmoji, "/finmoji/128px/#{finmoji}-128.png"}
97 @emoji_from_file (with {:ok, file} <- File.read("config/emoji.txt") do
100 |> String.split("\n")
101 |> Enum.map(fn(line) ->
102 [name, file] = String.split(line, ", ")
109 @emoji @finmoji_with_filenames ++ @emoji_from_file
111 def emojify(text, additional \\ nil) do
112 all_emoji = if additional do
113 Map.to_list(additional) ++ @emoji
118 Enum.reduce(all_emoji, text, fn ({emoji, file}, text) ->
119 String.replace(text, ":#{emoji}:", "<img height='32px' width='32px' alt='#{emoji}' title='#{emoji}' src='#{file}' />")
123 def get_emoji(text) do
124 Enum.filter(@emoji, fn ({emoji, _}) -> String.contains?(text, ":#{emoji}:") end)
127 def get_custom_emoji() do