Merge pull request 'Interpret \n
as newline for MFM' (#478) from ilja/akkoma:newline_remains_newline_in_mfm into develop
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/478
This commit is contained in:
commit
ea30d22dfe
5 changed files with 11 additions and 7 deletions
|
@ -124,8 +124,8 @@ defmodule Pleroma.Formatter do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def markdown_to_html(text) do
|
def markdown_to_html(text, opts \\ %{}) do
|
||||||
Earmark.as_html!(text, %Earmark.Options{compact_output: true})
|
Earmark.as_html!(text, %Earmark.Options{compact_output: true} |> Map.merge(opts))
|
||||||
end
|
end
|
||||||
|
|
||||||
def html_escape({text, mentions, hashtags}, type) do
|
def html_escape({text, mentions, hashtags}, type) do
|
||||||
|
|
|
@ -104,9 +104,9 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# https://github.com/misskey-dev/misskey/pull/8787
|
# See https://akkoma.dev/FoundKeyGang/FoundKey/issues/343
|
||||||
# Misskey has an awful tendency to drop all custom formatting when it sends remotely
|
# Misskey/Foundkey drops some of the custom formatting when it sends remotely
|
||||||
# So this basically reprocesses their MFM source
|
# So this basically reprocesses the MFM source
|
||||||
defp fix_misskey_content(
|
defp fix_misskey_content(
|
||||||
%{"source" => %{"mediaType" => "text/x.misskeymarkdown", "content" => content}} = object
|
%{"source" => %{"mediaType" => "text/x.misskeymarkdown", "content" => content}} = object
|
||||||
)
|
)
|
||||||
|
@ -121,6 +121,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator do
|
||||||
Map.put(object, "content", linked)
|
Map.put(object, "content", linked)
|
||||||
end
|
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
|
defp fix_misskey_content(%{"_misskey_content" => content} = object) when is_binary(content) do
|
||||||
mention_handler = fn nick, buffer, opts, acc ->
|
mention_handler = fn nick, buffer, opts, acc ->
|
||||||
remote_mention_resolver(object, nick, buffer, opts, acc)
|
remote_mention_resolver(object, nick, buffer, opts, acc)
|
||||||
|
|
|
@ -289,7 +289,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
||||||
|
|
||||||
def format_input(text, "text/x.misskeymarkdown", options) do
|
def format_input(text, "text/x.misskeymarkdown", options) do
|
||||||
text
|
text
|
||||||
|> Formatter.markdown_to_html()
|
|> Formatter.markdown_to_html(%{breaks: true})
|
||||||
|> MfmParser.Parser.parse()
|
|> MfmParser.Parser.parse()
|
||||||
|> MfmParser.Encoder.to_html()
|
|> MfmParser.Encoder.to_html()
|
||||||
|> Formatter.linkify(options)
|
|> Formatter.linkify(options)
|
||||||
|
|
2
test/fixtures/misskey/mfm_x_format.json
vendored
2
test/fixtures/misskey/mfm_x_format.json
vendored
|
@ -5,7 +5,7 @@
|
||||||
"summary": null,
|
"summary": null,
|
||||||
"content": "this does not get replaced",
|
"content": "this does not get replaced",
|
||||||
"source": {
|
"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"
|
"mediaType": "text/x.misskeymarkdown"
|
||||||
},
|
},
|
||||||
"published": "2022-07-10T15:37:36.368Z",
|
"published": "2022-07-10T15:37:36.368Z",
|
||||||
|
|
|
@ -136,6 +136,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest
|
||||||
|
|
||||||
assert content =~
|
assert content =~
|
||||||
"<span class=\"mfm _mfm_jelly_\" style=\"display: inline-block; animation: 1s linear 0s infinite normal both running mfm-rubberBand;\">mfm goes here</span> </p>aaa"
|
"<span class=\"mfm _mfm_jelly_\" style=\"display: inline-block; animation: 1s linear 0s infinite normal both running mfm-rubberBand;\">mfm goes here</span> </p>aaa"
|
||||||
|
|
||||||
|
assert content =~ "some text<br/>newline"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "a misskey MFM status with a _misskey_content field should work and be linked", _ do
|
test "a misskey MFM status with a _misskey_content field should work and be linked", _ do
|
||||||
|
|
Loading…
Reference in a new issue