better formatting for titles

This commit is contained in:
Peter Zingg 2022-12-20 11:00:47 -08:00
parent 8b488899aa
commit b0532e136b
5 changed files with 15 additions and 6 deletions

View File

@ -286,7 +286,7 @@ config :pleroma, :feed,
max_length: 100,
omission: "...",
# New method to extract title
parse_source: true
parse_source: false
}
config :pleroma, :markup,

View File

@ -2919,6 +2919,7 @@ config :pleroma, :config_description, [
%{
group: :pleroma,
key: :feed,
label: "RSS Feeds",
type: :group,
description: "Configure feed rendering",
children: [

View File

@ -156,10 +156,13 @@ defmodule Pleroma.Formatter 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

View File

@ -86,6 +86,7 @@ defmodule Pleroma.Web.Feed.FeedView do
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()

View File

@ -42,8 +42,12 @@ defmodule Pleroma.Web.Metadata.Utils 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&nbsp;")
|> String.replace(~r/<\/p\s*\/?>/, "&nbsp;\\0")
|> HTML.strip_tags()
# strip_tags will convert &nbsp; to U+00A0, adding /u will match these to " "
|> String.replace(~r/\s+/u, " ")
|> String.trim()
end
def scrub_html(content), do: content