X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fformatter.ex;h=575bf9b2dcb20d3bc0ded04ea0abdb406cb6d0f1;hb=b058df3faa60f3996ad02362432cf7567e87f100;hp=ae37946ab79630af6111ae439a8849a33df4f379;hpb=0c56f9de0d607b88fd107e0bd13ef286f0629346;p=akkoma diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index ae37946ab..575bf9b2d 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -32,26 +32,29 @@ defmodule Pleroma.Formatter do end end + def mention_tag(%User{id: id} = user, nickname, opts \\ []) do + user_url = user.uri || user.ap_id + nickname_text = get_nickname_text(nickname, opts) + + :span + |> Phoenix.HTML.Tag.content_tag( + Phoenix.HTML.Tag.content_tag( + :a, + ["@", Phoenix.HTML.Tag.content_tag(:span, nickname_text)], + "data-user": id, + class: "u-url mention", + href: user_url, + rel: "ugc" + ), + class: "h-card" + ) + |> Phoenix.HTML.safe_to_string() + end + def mention_handler("@" <> nickname, buffer, opts, acc) do case User.get_cached_by_nickname(nickname) do - %User{id: id} = user -> - user_url = user.uri || user.ap_id - nickname_text = get_nickname_text(nickname, opts) - - link = - Phoenix.HTML.Tag.content_tag( - :span, - Phoenix.HTML.Tag.content_tag( - :a, - ["@", Phoenix.HTML.Tag.content_tag(:span, nickname_text)], - "data-user": id, - class: "u-url mention", - href: user_url, - rel: "ugc" - ), - class: "h-card" - ) - |> Phoenix.HTML.safe_to_string() + %User{id: _id} = user -> + link = mention_tag(user, nickname, opts) {link, %{acc | mentions: MapSet.put(acc.mentions, {"@" <> nickname, user})}} @@ -133,6 +136,11 @@ defmodule Pleroma.Formatter do HTML.filter_tags(text) end + def html_escape(text, "text/x.misskeymarkdown") do + text + |> HTML.filter_tags() + end + def html_escape(text, "text/plain") do Regex.split(@link_regex, text, include_captures: true) |> Enum.map_every(2, fn chunk ->