From: ilja
Date: Sat, 18 Feb 2023 18:30:27 +0000 (+0100)
Subject: Interpret `\n` as newline for MFM
X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=b4952a81fe2eeec9c033bf8c69148e53e1f40be2;p=akkoma
Interpret `\n` as newline for MFM
Markdown doesn't generally consider `\n` a newline,
but Misskey does for MFM.
Now we do to for MFM (and not for Markdown) :)
---
diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex
index 575bf9b2d..fc841a550 100644
--- a/lib/pleroma/formatter.ex
+++ b/lib/pleroma/formatter.ex
@@ -124,8 +124,8 @@ defmodule Pleroma.Formatter do
end
end
- def markdown_to_html(text) do
- Earmark.as_html!(text, %Earmark.Options{compact_output: true})
+ def markdown_to_html(text, opts \\ %{}) do
+ Earmark.as_html!(text, %Earmark.Options{compact_output: true} |> Map.merge(opts))
end
def html_escape({text, mentions, hashtags}, type) do
diff --git a/lib/pleroma/web/activity_pub/object_validators/article_note_page_validator.ex b/lib/pleroma/web/activity_pub/object_validators/article_note_page_validator.ex
index 09b68c977..d4beed78d 100644
--- a/lib/pleroma/web/activity_pub/object_validators/article_note_page_validator.ex
+++ b/lib/pleroma/web/activity_pub/object_validators/article_note_page_validator.ex
@@ -104,9 +104,9 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator do
end
end
- # https://github.com/misskey-dev/misskey/pull/8787
- # Misskey has an awful tendency to drop all custom formatting when it sends remotely
- # So this basically reprocesses their MFM source
+ # See https://akkoma.dev/FoundKeyGang/FoundKey/issues/343
+ # Misskey/Foundkey drops some of the custom formatting when it sends remotely
+ # So this basically reprocesses the MFM source
defp fix_misskey_content(
%{"source" => %{"mediaType" => "text/x.misskeymarkdown", "content" => content}} = object
)
@@ -121,6 +121,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator do
Map.put(object, "content", linked)
end
+ # See https://github.com/misskey-dev/misskey/pull/8787
+ # This is for compatibility with older Misskey instances
defp fix_misskey_content(%{"_misskey_content" => content} = object) when is_binary(content) do
mention_handler = fn nick, buffer, opts, acc ->
remote_mention_resolver(object, nick, buffer, opts, acc)
diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex
index 345c5d10d..54918d13c 100644
--- a/lib/pleroma/web/common_api/utils.ex
+++ b/lib/pleroma/web/common_api/utils.ex
@@ -289,7 +289,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
def format_input(text, "text/x.misskeymarkdown", options) do
text
- |> Formatter.markdown_to_html()
+ |> Formatter.markdown_to_html(%{breaks: true})
|> MfmParser.Parser.parse()
|> MfmParser.Encoder.to_html()
|> Formatter.linkify(options)
diff --git a/test/fixtures/misskey/mfm_x_format.json b/test/fixtures/misskey/mfm_x_format.json
index 590e399fe..ecbbddadd 100644
--- a/test/fixtures/misskey/mfm_x_format.json
+++ b/test/fixtures/misskey/mfm_x_format.json
@@ -5,7 +5,7 @@
"summary": null,
"content": "this does not get replaced",
"source": {
- "content": "@akkoma_user @remote_user @full_tag_remote_user@misskey.local.live @oops_not_a_mention linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa",
+ "content": "@akkoma_user @remote_user @full_tag_remote_user@misskey.local.live @oops_not_a_mention linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa\n\nsome text\nnewline",
"mediaType": "text/x.misskeymarkdown"
},
"published": "2022-07-10T15:37:36.368Z",
diff --git a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs
index 62ac5e051..523a17c17 100644
--- a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs
@@ -136,6 +136,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest
assert content =~
"mfm goes here
aaa"
+
+ assert content =~ "some text
newline"
end
test "a misskey MFM status with a _misskey_content field should work and be linked", _ do