mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 00:26:30 +00:00
modify Utils.scrub_html_and_truncate to take omission parameter
This commit is contained in:
parent
117a53b88e
commit
86ee4b72f3
2 changed files with 4 additions and 3 deletions
|
@ -30,12 +30,13 @@ defmodule Pleroma.Web.Metadata.Utils do
|
||||||
|> scrub_html_and_truncate_object_field(object)
|
|> scrub_html_and_truncate_object_field(object)
|
||||||
end
|
end
|
||||||
|
|
||||||
def scrub_html_and_truncate(content, max_length \\ 200) when is_binary(content) do
|
def scrub_html_and_truncate(content, max_length \\ 200, omission \\ "...")
|
||||||
|
when is_binary(content) do
|
||||||
content
|
content
|
||||||
|> scrub_html
|
|> scrub_html
|
||||||
|> Emoji.Formatter.demojify()
|
|> Emoji.Formatter.demojify()
|
||||||
|> HtmlEntities.decode()
|
|> HtmlEntities.decode()
|
||||||
|> Formatter.truncate(max_length)
|
|> Formatter.truncate(max_length, omission)
|
||||||
end
|
end
|
||||||
|
|
||||||
def scrub_html(content) when is_binary(content) do
|
def scrub_html(content) when is_binary(content) do
|
||||||
|
|
|
@ -72,7 +72,7 @@ defmodule Pleroma.Web.Metadata.UtilsTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "scrub_html_and_truncate/2" do
|
describe "scrub_html_and_truncate/3" do
|
||||||
test "it returns text without encode HTML" do
|
test "it returns text without encode HTML" do
|
||||||
assert Utils.scrub_html_and_truncate("Pleroma's really cool!") == "Pleroma's really cool!"
|
assert Utils.scrub_html_and_truncate("Pleroma's really cool!") == "Pleroma's really cool!"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue