X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fformatter.ex;h=fc841a55087f266fe6feb2021f06b82b1a89d287;hb=a079ec3a3cdfd42d2cbd51c7698c2c87828e5778;hp=78325095aac79befc8f5674870548d3c5e278b36;hpb=5ad256f170c29a864b0f720acc8302b347fd9b25;p=akkoma diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 78325095a..fc841a550 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})}} @@ -121,8 +124,8 @@ defmodule Pleroma.Formatter do end end - def markdown_to_html(text) do - Earmark.as_html!(text, %Earmark.Options{compact_output: true}) + def markdown_to_html(text, opts \\ %{}) do + Earmark.as_html!(text, %Earmark.Options{compact_output: true} |> Map.merge(opts)) end def html_escape({text, mentions, hashtags}, type) do @@ -133,7 +136,12 @@ defmodule Pleroma.Formatter do HTML.filter_tags(text) end - def html_escape(text, format) when format in ["text/plain", "text/x.misskeymarkdown"] do + 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 -> {:safe, part} = Phoenix.HTML.html_escape(chunk)