forked from AkkomaGang/akkoma
better formatting for titles
This commit is contained in:
parent
8b488899aa
commit
b0532e136b
5 changed files with 15 additions and 6 deletions
|
@ -286,7 +286,7 @@
|
|||
max_length: 100,
|
||||
omission: "...",
|
||||
# New method to extract title
|
||||
parse_source: true
|
||||
parse_source: false
|
||||
}
|
||||
|
||||
config :pleroma, :markup,
|
||||
|
|
|
@ -2919,6 +2919,7 @@
|
|||
%{
|
||||
group: :pleroma,
|
||||
key: :feed,
|
||||
label: "RSS Feeds",
|
||||
type: :group,
|
||||
description: "Configure feed rendering",
|
||||
children: [
|
||||
|
|
|
@ -156,10 +156,13 @@ def truncate(text, max_length \\ 200, omission \\ "...") when max_length >= 0 do
|
|||
|
||||
length_with_omission = max_length - String.length(omission)
|
||||
|
||||
if length_with_omission <= 0 do
|
||||
String.slice(text, 0, max_length)
|
||||
else
|
||||
String.slice(text, 0, length_with_omission) <> omission
|
||||
cond do
|
||||
String.length(text) <= max_length ->
|
||||
text
|
||||
length_with_omission > 0 ->
|
||||
String.slice(text, 0, length_with_omission) <> omission
|
||||
true ->
|
||||
String.slice(text, 0, max_length)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ def activity_title(
|
|||
split_content(content, content_type, opts) |> elem(0)
|
||||
end
|
||||
|
||||
# TODO: scrub_html should replace <p> with " "
|
||||
def activity_title(%{"content" => content}, opts) do
|
||||
content
|
||||
|> Pleroma.Web.Metadata.Utils.scrub_html()
|
||||
|
|
|
@ -42,8 +42,12 @@ def scrub_html(content) when is_binary(content) do
|
|||
content
|
||||
# html content comes from DB already encoded, decode first and scrub after
|
||||
|> HtmlEntities.decode()
|
||||
|> String.replace(~r/<br\s?\/?>/, " ")
|
||||
|> String.replace(~r/<(br|p)[^>]*>/, "\\0 ")
|
||||
|> String.replace(~r/<\/p\s*\/?>/, " \\0")
|
||||
|> HTML.strip_tags()
|
||||
# strip_tags will convert to U+00A0, adding /u will match these to " "
|
||||
|> String.replace(~r/\s+/u, " ")
|
||||
|> String.trim()
|
||||
end
|
||||
|
||||
def scrub_html(content), do: content
|
||||
|
|
Loading…
Reference in a new issue