+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Formatter do
alias Pleroma.User
alias Pleroma.Web.MediaProxy
String.replace(result_text, uuid, replacement)
end)
end
+
+ def truncate(text, opts \\ []) do
+ max_length = opts[:max_length] || 200
+ omission = opts[:omission] || "..."
+
+ cond do
+ not String.valid?(text) ->
+ text
+
+ String.length(text) < max_length ->
+ text
+
+ true ->
+ length_with_omission = max_length - String.length(omission)
+
+ "#{String.slice(text, 0, length_with_omission)}#{omission}"
+ end
+ end
end