From 2ecf81f10c1ebc01d21b4183f6cd248ce5cfbd6a Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 10 Jan 2019 02:22:11 +0000 Subject: [PATCH 1/3] common api: fix newlines in markdown code blocks --- lib/pleroma/web/common_api/utils.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 3ff9f9452..187e908ce 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -150,7 +150,6 @@ def format_input(text, mentions, tags, "text/markdown") do |> Formatter.mentions_escape(mentions) |> Earmark.as_html!() |> Formatter.html_escape("text/html") - |> String.replace(~r/\r?\n/, "") |> (&{[], &1}).() |> Formatter.add_user_links(mentions) |> Formatter.add_hashtag_links(tags) From 0bdbd4f968b20a508f9433480c7e358428dc55d7 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 10 Jan 2019 03:45:58 +0000 Subject: [PATCH 2/3] common api: utils: remove newline to
conversion from bare HTML to be consistent with markdown ok @lanodan --- lib/pleroma/web/common_api/utils.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 187e908ce..7e30d224c 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -136,7 +136,6 @@ def format_input(text, mentions, tags, "text/plain") do def format_input(text, mentions, _tags, "text/html") do text |> Formatter.html_escape("text/html") - |> String.replace(~r/\r?\n/, "
") |> (&{[], &1}).() |> Formatter.add_user_links(mentions) |> Formatter.finalize() From 490c80bc9651f93b61dfe4ae531bc0072a35d044 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 10 Jan 2019 03:46:34 +0000 Subject: [PATCH 3/3] test: common api: add tests for format_input/4 --- test/web/common_api/common_api_utils_test.exs | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs index fc89e3116..754bc7255 100644 --- a/test/web/common_api/common_api_utils_test.exs +++ b/test/web/common_api/common_api_utils_test.exs @@ -56,4 +56,54 @@ test "parses emoji from name and bio" do assert expected == Utils.emoji_from_profile(user) end + + describe "format_input/4" do + test "works for bare text/plain" do + text = "hello world!" + expected = "hello world!" + + output = Utils.format_input(text, [], [], "text/plain") + + assert output == expected + + text = "hello world!\n\nsecond paragraph!" + expected = "hello world!

second paragraph!" + + output = Utils.format_input(text, [], [], "text/plain") + + assert output == expected + end + + test "works for bare text/html" do + text = "

hello world!

" + expected = "

hello world!

" + + output = Utils.format_input(text, [], [], "text/html") + + assert output == expected + + text = "

hello world!

\n\n

second paragraph

" + expected = "

hello world!

\n\n

second paragraph

" + + output = Utils.format_input(text, [], [], "text/html") + + assert output == expected + end + + test "works for bare text/markdown" do + text = "**hello world**" + expected = "

hello world

\n" + + output = Utils.format_input(text, [], [], "text/markdown") + + assert output == expected + + text = "**hello world**\n\n*another paragraph*" + expected = "

hello world

\n

another paragraph

\n" + + output = Utils.format_input(text, [], [], "text/markdown") + + assert output == expected + end + end end