Refactor Earmark code, fix tests
[akkoma] / lib / pleroma / formatter.ex
index 0c450eae4ec6e26ac75280cd942556ce2e428440..1be12055f2954b333ce16a913703b70ef9d4bf17 100644 (file)
@@ -121,6 +121,10 @@ defmodule Pleroma.Formatter do
     end
   end
 
+  def markdown_to_html(text) do
+    Earmark.as_html!(text)
+  end
+
   def html_escape({text, mentions, hashtags}, type) do
     {html_escape(text, type), mentions, hashtags}
   end
@@ -138,6 +142,17 @@ defmodule Pleroma.Formatter do
     |> Enum.join("")
   end
 
+  def minify({text, mentions, hashtags}, type) do
+    {minify(text, type), mentions, hashtags}
+  end
+
+  def minify(text, "text/html") do
+    text
+    |> String.replace(">\n", ">")
+    |> String.replace(">  ", ">")
+    |> String.replace("  <", "<")
+  end
+
   def truncate(text, max_length \\ 200, omission \\ "...") do
     # Remove trailing whitespace
     text = Regex.replace(~r/([^ \t\r\n])([ \t]+$)/u, text, "\\g{1}")