html: allow scrubbing policies to be stackable

This commit is contained in:
William Pitcock 2018-09-16 02:07:01 +00:00
parent 2881275291
commit cd13fa17fd
1 changed files with 13 additions and 2 deletions

View File

@ -3,13 +3,24 @@ defmodule Pleroma.HTML do
@markup Application.get_env(:pleroma, :markup) @markup Application.get_env(:pleroma, :markup)
defp get_scrubbers(scrubber) when is_atom(scrubber), do: [scrubber]
defp get_scrubbers(scrubbers) when is_list(scrubbers), do: scrubbers
defp get_scrubbers(_), do: [Pleroma.HTML.Scrubber.Default]
def get_scrubbers() do
Keyword.get(@markup, :scrub_policy)
|> get_scrubbers
end
def filter_tags(html, scrubber) do def filter_tags(html, scrubber) do
html |> Scrubber.scrub(scrubber) html |> Scrubber.scrub(scrubber)
end end
def filter_tags(html) do def filter_tags(html) do
scrubber = Keyword.get(@markup, :scrub_policy) get_scrubbers()
filter_tags(html, scrubber) |> Enum.reduce(html, fn scrubber, html ->
filter_tags(html, scrubber)
end)
end end
def strip_tags(html) do def strip_tags(html) do