Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
f8c93246
Commit
f8c93246
authored
Oct 13, 2020
by
Alex Gleason
Committed by
feld
Dec 11, 2020
Browse files
Refactor Earmark code, fix tests
parent
b2548cfc
Changes
6
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/formatter.ex
View file @
f8c93246
...
...
@@ -121,6 +121,10 @@ def mentions_escape(text, options \\ []) do
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
...
...
lib/pleroma/web/activity_pub/object_validators/audio_video_validator.ex
View file @
f8c93246
...
...
@@ -95,7 +95,7 @@ defp fix_content(%{"mediaType" => "text/markdown", "content" => content} = data)
when
is_binary
(
content
)
do
content
=
content
|>
Earmark
.
as
_html
!
()
|>
Pleroma
.
Formatter
.
markdown_to
_html
()
|>
Pleroma
.
HTML
.
filter_tags
()
Map
.
put
(
data
,
"content"
,
content
)
...
...
lib/pleroma/web/common_api/utils.ex
View file @
f8c93246
...
...
@@ -294,7 +294,7 @@ def format_input(text, "text/html", options) do
def
format_input
(
text
,
"text/markdown"
,
options
)
do
text
|>
Formatter
.
mentions_escape
(
options
)
|>
Ea
rma
rk
.
as
_html
!
()
|>
Fo
rma
tter
.
markdown_to
_html
()
|>
Formatter
.
linkify
(
options
)
|>
Formatter
.
minify
(
"text/html"
)
|>
Formatter
.
html_escape
(
"text/html"
)
...
...
priv/scrubbers/default.ex
View file @
f8c93246
...
...
@@ -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
(
:code
,
"class"
,
[
"inline"
])
@allow_inline_images
Pleroma
.
Config
.
get
([
:markup
,
:allow_inline_images
])
if
@allow_inline_images
do
...
...
test/pleroma/web/common_api/utils_test.exs
View file @
f8c93246
...
...
@@ -178,13 +178,13 @@ test "Paragraph" do
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"
)
assert
result
==
"<p>before</p><hr
/><p>after</p>"
assert
result
==
"<p>before</p><hr/><p>after</p>"
end
test
"blockquote"
do
...
...
@@ -204,7 +204,7 @@ test "code" do
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
...
...
@@ -227,9 +227,9 @@ test "delegated renderers" do
assert
result
==
~s[<p><strong>aaaa~</strong></p>]
# strikethrough
code
=
~s[
<del>aaaa~</del>
]
code
=
~s[
~~aaaa~~~
]
{
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
...
...
test/pleroma/web/common_api_test.exs
View file @
f8c93246
...
...
@@ -558,7 +558,7 @@ test "it filters out obviously bad tags when accepting a post as Markdown" do
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment