defmodule Pleroma.Formatter do
alias Pleroma.User
alias Pleroma.Web.MediaProxy
+ alias Pleroma.HTML
@tag_regex ~r/\#\w+/u
def parse_tags(text, data \\ %{}) do
def emojify(text, emoji) do
Enum.reduce(emoji, text, fn {emoji, file}, text ->
- emoji = HtmlSanitizeEx.strip_tags(emoji)
- file = HtmlSanitizeEx.strip_tags(file)
+ emoji = HTML.strip_tags(emoji)
+ file = HTML.strip_tags(file)
String.replace(
text,
MediaProxy.url(file)
}' />"
)
- |> HtmlSanitizeEx.basic_html()
+ |> HTML.filter_tags()
end)
end
alias Pleroma.User
alias Pleroma.Activity
alias Pleroma.Repo
+ alias Pleroma.HTML
@instance Application.get_env(:pleroma, :instance)
@gopher Application.get_env(:pleroma, :gopher)
info("#{like_count} likes, #{announcement_count} repeats") <>
"i\tfake\t(NULL)\t0\r\n" <>
info(
- HtmlSanitizeEx.strip_tags(
+ HTML.strip_tags(
String.replace(activity.data["object"]["content"], "<br>", "\r")
)
)
alias Pleroma.Web.MastodonAPI.AccountView
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.MediaProxy
+ alias Pleroma.HTML
def render("accounts.json", %{users: users} = opts) do
render_many(users, AccountView, "account.json", opts)
followers_count: user_info.follower_count,
following_count: user_info.following_count,
statuses_count: user_info.note_count,
- note: HtmlSanitizeEx.basic_html(user.bio) || "",
+ note: HTML.filter_tags(user.bio) || "",
url: user.ap_id,
avatar: image,
avatar_static: image,
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.MediaProxy
alias Pleroma.Repo
+ alias Pleroma.HTML
# TODO: Add cached version.
defp get_replied_to_activities(activities) do
emojis =
(activity.data["object"]["emoji"] || [])
|> Enum.map(fn {name, url} ->
- name = HtmlSanitizeEx.strip_tags(name)
+ name = HTML.strip_tags(name)
url =
- HtmlSanitizeEx.strip_tags(url)
+ HTML.strip_tags(url)
|> MediaProxy.url()
%{shortcode: name, url: url, static_url: url}
object["content"]
end
- HtmlSanitizeEx.basic_html(content)
+ HTML.filter_tags(content)
end
def render_content(%{"type" => "Article"} = object) do
object["content"]
end
- HtmlSanitizeEx.basic_html(content)
+ HTML.filter_tags(content)
end
def render_content(object) do
- HtmlSanitizeEx.basic_html(object["content"])
+ HTML.filter_tags(object["content"])
end
end
alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView}
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Formatter
+ alias Pleroma.HTML
defp user_by_ap_id(user_list, ap_id) do
Enum.find(user_list, fn %{ap_id: user_id} -> ap_id == user_id end)
{summary, content} = ActivityView.render_content(object)
html =
- HtmlSanitizeEx.basic_html(content)
+ HTML.filter_tags(content)
|> Formatter.emojify(object["emoji"])
video =
"uri" => activity.data["object"]["id"],
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
"statusnet_html" => html,
- "text" => HtmlSanitizeEx.strip_tags(content),
+ "text" => HTML.strip_tags(content),
"is_local" => activity.local,
"is_post_verb" => true,
"created_at" => created_at,
alias Pleroma.User
alias Pleroma.Repo
alias Pleroma.Formatter
+ alias Pleroma.HTML
import Ecto.Query
{summary, content} = render_content(object)
html =
- HtmlSanitizeEx.basic_html(content)
+ HTML.filter_tags(content)
|> Formatter.emojify(object["emoji"])
%{
"uri" => activity.data["object"]["id"],
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
"statusnet_html" => html,
- "text" => HtmlSanitizeEx.strip_tags(content),
+ "text" => HTML.strip_tags(content),
"is_local" => activity.local,
"is_post_verb" => true,
"created_at" => created_at,
alias Pleroma.Formatter
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.MediaProxy
+ alias Pleroma.HTML
def render("show.json", %{user: user = %User{}} = assigns) do
render_one(user, Pleroma.Web.TwitterAPI.UserView, "user.json", assigns)
data = %{
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
"description" =>
- HtmlSanitizeEx.strip_tags((user.bio || "") |> String.replace("<br>", "\n")),
- "description_html" => HtmlSanitizeEx.basic_html(user.bio),
+ HTML.strip_tags((user.bio || "") |> String.replace("<br>", "\n")),
+ "description_html" => HTML.filter_tags(user.bio),
"favourites_count" => 0,
"followers_count" => user_info[:follower_count],
"following" => following,
"friends_count" => user_info[:following_count],
"id" => user.id,
"name" => user.name,
- "name_html" => HtmlSanitizeEx.strip_tags(user.name) |> Formatter.emojify(emoji),
+ "name_html" => HTML.strip_tags(user.name) |> Formatter.emojify(emoji),
"profile_image_url" => image,
"profile_image_url_https" => image,
"profile_image_url_profile_size" => image,