2019-10-06 23:31:48 +02:00
|
|
|
defmodule PhilomenaWeb.PostView do
|
2019-11-27 02:45:57 +01:00
|
|
|
alias Philomena.Attribution
|
|
|
|
alias Textile.Parser
|
|
|
|
|
2019-10-06 23:31:48 +02:00
|
|
|
use PhilomenaWeb, :view
|
2019-11-27 02:45:57 +01:00
|
|
|
|
|
|
|
def textile_safe_author(object) do
|
|
|
|
author_name = author_name(object)
|
|
|
|
|
|
|
|
Parser.parse(%Parser{image_transform: & &1}, author_name)
|
|
|
|
|> case do
|
|
|
|
[{:text, ^author_name}] ->
|
|
|
|
author_name
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
# Cover *all* possibilities.
|
|
|
|
literal =
|
|
|
|
author_name
|
|
|
|
|> String.replace("==]", "==]==][==")
|
|
|
|
|
|
|
|
"[==#{literal}==]"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp author_name(object) do
|
|
|
|
case Attribution.anonymous?(object) do
|
|
|
|
true -> PhilomenaWeb.UserAttributionView.anonymous_name(object)
|
|
|
|
false -> object.user.name
|
|
|
|
end
|
|
|
|
end
|
2019-10-06 23:31:48 +02:00
|
|
|
end
|