Use better upstream deps

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2020-11-30 12:22:05 +01:00
parent b05f0fe3e6
commit 207d5c0eb0
6 changed files with 39 additions and 35 deletions

View File

@@ -17,11 +17,6 @@ defmodule Mobilizon.Service.Formatter do
@link_regex ~r"((?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~%:/?#[\]@!\$&'\(\)\*\+,;=.]+)|[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+"ui
@markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/
@auto_linker_config hashtag: true,
hashtag_handler: &__MODULE__.hashtag_handler/4,
mention: true,
mention_handler: &__MODULE__.mention_handler/4
def escape_mention_handler("@" <> nickname = mention, buffer, _, _) do
case Actors.get_actor_by_name(nickname) do
%Actor{} ->
@@ -68,10 +63,10 @@ defmodule Mobilizon.Service.Formatter do
@spec linkify(String.t(), keyword()) ::
{String.t(), [{String.t(), Actor.t()}], [{String.t(), String.t()}]}
def linkify(text, options \\ []) do
options = options ++ @auto_linker_config
options = linkify_opts() ++ options
acc = %{mentions: MapSet.new(), tags: MapSet.new()}
{text, %{mentions: mentions, tags: tags}} = AutoLinker.link_map(text, acc, options)
{text, %{mentions: mentions, tags: tags}} = Linkify.link_map(text, acc, options)
{text, MapSet.to_list(mentions), MapSet.to_list(tags)}
end
@@ -87,7 +82,7 @@ defmodule Mobilizon.Service.Formatter do
mention_handler: &escape_mention_handler/4
)
AutoLinker.link(text, options)
Linkify.link(text, options)
end
def html_escape({text, mentions, hashtags}, type) do
@@ -121,4 +116,14 @@ defmodule Mobilizon.Service.Formatter do
String.slice(text, 0, length_with_omission) <> omission
end
end
defp linkify_opts do
Mobilizon.Config.get(__MODULE__) ++
[
hashtag: true,
hashtag_handler: &__MODULE__.hashtag_handler/4,
mention: true,
mention_handler: &__MODULE__.hashtag_handler/4
]
end
end