mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-12 20:25:00 +00:00
allow small/center tags in misskeymarkdown (#132)
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/132
This commit is contained in:
parent
38659e5610
commit
19a27ff006
4 changed files with 25 additions and 6 deletions
|
@ -136,7 +136,12 @@ defmodule Pleroma.Formatter do
|
||||||
HTML.filter_tags(text)
|
HTML.filter_tags(text)
|
||||||
end
|
end
|
||||||
|
|
||||||
def html_escape(text, format) when format in ["text/plain", "text/x.misskeymarkdown"] do
|
def html_escape(text, "text/x.misskeymarkdown") do
|
||||||
|
text
|
||||||
|
|> HTML.filter_tags()
|
||||||
|
end
|
||||||
|
|
||||||
|
def html_escape(text, "text/plain") do
|
||||||
Regex.split(@link_regex, text, include_captures: true)
|
Regex.split(@link_regex, text, include_captures: true)
|
||||||
|> Enum.map_every(2, fn chunk ->
|
|> Enum.map_every(2, fn chunk ->
|
||||||
{:safe, part} = Phoenix.HTML.html_escape(chunk)
|
{:safe, part} = Phoenix.HTML.html_escape(chunk)
|
||||||
|
|
|
@ -259,8 +259,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
||||||
@doc """
|
@doc """
|
||||||
Formatting text to plain text, BBCode, HTML, or Markdown
|
Formatting text to plain text, BBCode, HTML, or Markdown
|
||||||
"""
|
"""
|
||||||
def format_input(text, format, options)
|
def format_input(text, "text/plain", options) do
|
||||||
when format in ["text/plain", "text/x.misskeymarkdown"] do
|
|
||||||
text
|
text
|
||||||
|> Formatter.html_escape("text/plain")
|
|> Formatter.html_escape("text/plain")
|
||||||
|> Formatter.linkify(options)
|
|> Formatter.linkify(options)
|
||||||
|
@ -284,6 +283,15 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
||||||
|> Formatter.linkify(options)
|
|> Formatter.linkify(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def format_input(text, "text/x.misskeymarkdown", options) do
|
||||||
|
text
|
||||||
|
|> Formatter.linkify(options)
|
||||||
|
|> Formatter.html_escape("text/x.misskeymarkdown")
|
||||||
|
|> (fn {text, mentions, tags} ->
|
||||||
|
{String.replace(text, ~r/\r?\n/, "<br>"), mentions, tags}
|
||||||
|
end).()
|
||||||
|
end
|
||||||
|
|
||||||
def format_input(text, "text/markdown", options) do
|
def format_input(text, "text/markdown", options) do
|
||||||
text
|
text
|
||||||
|> Formatter.mentions_escape(options)
|
|> Formatter.mentions_escape(options)
|
||||||
|
|
|
@ -97,5 +97,8 @@ defmodule Pleroma.HTML.Scrubber.Default do
|
||||||
Meta.allow_tag_with_these_attributes(:font, ["face"])
|
Meta.allow_tag_with_these_attributes(:font, ["face"])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Meta.allow_tag_with_these_attributes(:center, [])
|
||||||
|
Meta.allow_tag_with_these_attributes(:small, [])
|
||||||
|
|
||||||
Meta.strip_everything_not_covered()
|
Meta.strip_everything_not_covered()
|
||||||
end
|
end
|
||||||
|
|
|
@ -130,18 +130,21 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest
|
||||||
|> Jason.decode!()
|
|> Jason.decode!()
|
||||||
|
|
||||||
expected_content =
|
expected_content =
|
||||||
"<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{local_user.id}\" href=\"#{local_user.ap_id}\" rel=\"ugc\">@<span>akkoma_user</span></a></span> linkifylink <a class=\"hashtag\" data-tag=\"dancedance\" href=\"http://localhost:4001/tag/dancedance\" rel=\"tag ugc\">#dancedance</a> $[jelly mfm goes here] <br><br>## aaa"
|
"<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{local_user.id}\" href=\"#{local_user.ap_id}\" rel=\"ugc\">@<span>akkoma_user</span></a></span> linkifylink <a class=\"hashtag\" data-tag=\"dancedance\" href=\"http://localhost:4001/tag/dancedance\">#dancedance</a> $[jelly mfm goes here] <br><br>## aaa"
|
||||||
|
|
||||||
|
changes = ArticleNotePageValidator.cast_and_validate(note)
|
||||||
|
|
||||||
%{
|
%{
|
||||||
valid?: true,
|
valid?: true,
|
||||||
changes: %{
|
changes: %{
|
||||||
content: ^expected_content,
|
|
||||||
source: %{
|
source: %{
|
||||||
"content" => "@akkoma_user linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa",
|
"content" => "@akkoma_user linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa",
|
||||||
"mediaType" => "text/x.misskeymarkdown"
|
"mediaType" => "text/x.misskeymarkdown"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} = ArticleNotePageValidator.cast_and_validate(note)
|
} = changes
|
||||||
|
|
||||||
|
assert changes.changes[:content] == expected_content
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue