projects
/
akkoma
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
b2548cf
)
Refactor Earmark code, fix tests
author
Alex Gleason
<alex@alexgleason.me>
Tue, 13 Oct 2020 19:27:50 +0000
(14:27 -0500)
committer
Mark Felder
<feld@FreeBSD.org>
Fri, 11 Dec 2020 23:22:42 +0000
(17:22 -0600)
lib/pleroma/formatter.ex
patch
|
blob
|
history
lib/pleroma/web/activity_pub/object_validators/audio_video_validator.ex
patch
|
blob
|
history
lib/pleroma/web/common_api/utils.ex
patch
|
blob
|
history
priv/scrubbers/default.ex
patch
|
blob
|
history
test/pleroma/web/common_api/utils_test.exs
patch
|
blob
|
history
test/pleroma/web/common_api_test.exs
patch
|
blob
|
history
diff --git
a/lib/pleroma/formatter.ex
b/lib/pleroma/formatter.ex
index 61906dda6aa406c79a30ebb8de060c3fa8a57fbb..1be12055f2954b333ce16a913703b70ef9d4bf17 100644
(file)
--- a/
lib/pleroma/formatter.ex
+++ b/
lib/pleroma/formatter.ex
@@
-121,6
+121,10
@@
defmodule Pleroma.Formatter do
end
end
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
def html_escape({text, mentions, hashtags}, type) do
{html_escape(text, type), mentions, hashtags}
end
diff --git
a/lib/pleroma/web/activity_pub/object_validators/audio_video_validator.ex
b/lib/pleroma/web/activity_pub/object_validators/audio_video_validator.ex
index eaf94797af12c48c215c7128a4160a5e788c9ac3..9b38aa4c244f8f2fc7d6175f8becb9c5044fc513 100644
(file)
--- a/
lib/pleroma/web/activity_pub/object_validators/audio_video_validator.ex
+++ b/
lib/pleroma/web/activity_pub/object_validators/audio_video_validator.ex
@@
-95,7
+95,7
@@
defmodule Pleroma.Web.ActivityPub.ObjectValidators.AudioVideoValidator do
when is_binary(content) do
content =
content
when is_binary(content) do
content =
content
- |>
Earmark.as_html!
()
+ |>
Pleroma.Formatter.markdown_to_html
()
|> Pleroma.HTML.filter_tags()
Map.put(data, "content", content)
|> Pleroma.HTML.filter_tags()
Map.put(data, "content", content)
diff --git
a/lib/pleroma/web/common_api/utils.ex
b/lib/pleroma/web/common_api/utils.ex
index b434a069ed2f8dd1d48d5624610ffb5e001ec11f..be86009af1d3f82c22b09f7619e37bacca021d53 100644
(file)
--- a/
lib/pleroma/web/common_api/utils.ex
+++ b/
lib/pleroma/web/common_api/utils.ex
@@
-294,7
+294,7
@@
defmodule Pleroma.Web.CommonAPI.Utils do
def format_input(text, "text/markdown", options) do
text
|> Formatter.mentions_escape(options)
def format_input(text, "text/markdown", options) do
text
|> Formatter.mentions_escape(options)
- |>
Earmark.as_html!
()
+ |>
Formatter.markdown_to_html
()
|> Formatter.linkify(options)
|> Formatter.minify("text/html")
|> Formatter.html_escape("text/html")
|> Formatter.linkify(options)
|> Formatter.minify("text/html")
|> Formatter.html_escape("text/html")
diff --git
a/priv/scrubbers/default.ex
b/priv/scrubbers/default.ex
index 0893b17e50d393de0d662044250bd87e4db3a2b5..4694a92a53b657f501c6574f7e33fc0f20064daa 100644
(file)
--- a/
priv/scrubbers/default.ex
+++ b/
priv/scrubbers/default.ex
@@
-59,6
+59,8
@@
defmodule Pleroma.HTML.Scrubber.Default do
Meta.allow_tag_with_this_attribute_values(:span, "class", ["h-card"])
Meta.allow_tag_with_these_attributes(:span, [])
Meta.allow_tag_with_this_attribute_values(:span, "class", ["h-card"])
Meta.allow_tag_with_these_attributes(:span, [])
+ Meta.allow_tag_with_this_attribute_values(:code, "class", ["inline"])
+
@allow_inline_images Pleroma.Config.get([:markup, :allow_inline_images])
if @allow_inline_images do
@allow_inline_images Pleroma.Config.get([:markup, :allow_inline_images])
if @allow_inline_images do
diff --git
a/test/pleroma/web/common_api/utils_test.exs
b/test/pleroma/web/common_api/utils_test.exs
index c6abbbe84a838d4eeebc03f069d734ea5a4ee998..ab6392b1f5fb835d93f94c69edb86cfe62bcb3dc 100644
(file)
--- a/
test/pleroma/web/common_api/utils_test.exs
+++ b/
test/pleroma/web/common_api/utils_test.exs
@@
-178,13
+178,13
@@
defmodule Pleroma.Web.CommonAPI.UtilsTest do
test "raw HTML" do
code = ~s[<a href="http://example.org/">OwO</a><!-- what's this?-->]
{result, [], []} = Utils.format_input(code, "text/markdown")
test "raw HTML" do
code = ~s[<a href="http://example.org/">OwO</a><!-- what's this?-->]
{result, [], []} = Utils.format_input(code, "text/markdown")
- assert result ==
"<p>#{code}</p>"
+ assert result ==
~s[<a href="http://example.org/">OwO</a>]
end
test "rulers" do
code = ~s[before\n\n-----\n\nafter]
{result, [], []} = Utils.format_input(code, "text/markdown")
end
test "rulers" do
code = ~s[before\n\n-----\n\nafter]
{result, [], []} = Utils.format_input(code, "text/markdown")
- assert result == "<p>before</p><hr
/><p>after</p>"
+ assert result == "<p>before</p><hr/><p>after</p>"
end
test "blockquote" do
end
test "blockquote" do
@@
-204,7
+204,7
@@
defmodule Pleroma.Web.CommonAPI.UtilsTest do
code = ~s[```\nputs "Hello World"\n```]
{result, [], []} = Utils.format_input(code, "text/markdown")
code = ~s[```\nputs "Hello World"\n```]
{result, [], []} = Utils.format_input(code, "text/markdown")
- assert result == ~s[<pre><code
class=""
>puts "Hello World"</code></pre>]
+ assert result == ~s[<pre><code>puts "Hello World"</code></pre>]
end
test "lists" do
end
test "lists" do
@@
-227,9
+227,9
@@
defmodule Pleroma.Web.CommonAPI.UtilsTest do
assert result == ~s[<p><strong>aaaa~</strong></p>]
# strikethrough
assert result == ~s[<p><strong>aaaa~</strong></p>]
# strikethrough
- code = ~s[
<del>aaaa~</del>
]
+ code = ~s[
~~aaaa~~~
]
{result, [], []} = Utils.format_input(code, "text/markdown")
{result, [], []} = Utils.format_input(code, "text/markdown")
- assert result == ~s[<p><del>aaaa
~</del>
</p>]
+ assert result == ~s[<p><del>aaaa
</del>~
</p>]
end
end
end
end
diff --git
a/test/pleroma/web/common_api_test.exs
b/test/pleroma/web/common_api_test.exs
index 585b2c174c9564c4aa2ccb408c7847f39374b671..c1b1af07321e25874c58c52ec6bc2ecb8476c7f7 100644
(file)
--- a/
test/pleroma/web/common_api_test.exs
+++ b/
test/pleroma/web/common_api_test.exs
@@
-558,7
+558,7
@@
defmodule Pleroma.Web.CommonAPITest do
object = Object.normalize(activity)
object = Object.normalize(activity)
- assert object.data["content"] == "<p><b>2hu</b></p>
alert('xss')
"
+ assert object.data["content"] == "<p><b>2hu</b></p>"
assert object.data["source"] == post
end
assert object.data["source"] == post
end