X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=inline;f=lib%2Fpleroma%2Fformatter.ex;h=fc841a55087f266fe6feb2021f06b82b1a89d287;hb=3744789710d84d5b0b770f5fab5665dab056ab27;hp=b0e4a84ae8ed43dfbc243bde53eef0557d93d0b9;hpb=e9e17e5df34051bce60232890ea042582af31f8c;p=akkoma
diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex
index b0e4a84ae..fc841a550 100644
--- a/lib/pleroma/formatter.ex
+++ b/lib/pleroma/formatter.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Formatter do
@@ -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})}}
@@ -62,7 +65,7 @@ defmodule Pleroma.Formatter do
def hashtag_handler("#" <> tag = tag_text, _buffer, _opts, acc) do
tag = String.downcase(tag)
- url = "#{Pleroma.Web.base_url()}/tag/#{tag}"
+ url = "#{Pleroma.Web.Endpoint.url()}/tag/#{tag}"
link =
Phoenix.HTML.Tag.content_tag(:a, tag_text,
@@ -121,6 +124,10 @@ defmodule Pleroma.Formatter do
end
end
+ 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
{html_escape(text, type), mentions, hashtags}
end
@@ -129,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 ->
@@ -138,14 +150,6 @@ defmodule Pleroma.Formatter do
|> Enum.join("")
end
- def minify({text, mentions, hashtags}, type) do
- {minify(text, type), mentions, hashtags}
- end
-
- def minify(text, "text/html") do
- String.replace(text, "\n", "")
- end
-
def truncate(text, max_length \\ 200, omission \\ "...") do
# Remove trailing whitespace
text = Regex.replace(~r/([^ \t\r\n])([ \t]+$)/u, text, "\\g{1}")