- def truncate(text, opts \\ []) do
- max_length = opts[:max_length] || 200
- omission = opts[:omission] || "..."
-
- cond do
- not String.valid?(text) ->
- text
+ def truncate(text, max_length \\ 200, omission \\ "...") do
+ # Remove trailing whitespace
+ text = Regex.replace(~r/([^ \t\r\n])([ \t]+$)/u, text, "\\g{1}")