Fix #923: Use same markdown widget for all content fields (rules, description, reports, notes, etc.)
This commit is contained in:
parent
8d29adf6be
commit
7850ca3e1c
12 changed files with 130 additions and 77 deletions
|
|
@ -103,27 +103,40 @@ def test_join_url(start, end, expected):
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"text, content_type, expected",
|
||||
"text, content_type, permissive, expected",
|
||||
[
|
||||
("hello world", "text/markdown", "<p>hello world</p>"),
|
||||
("hello world", "text/plain", "<p>hello world</p>"),
|
||||
("<strong>hello world</strong>", "text/html", "<strong>hello world</strong>"),
|
||||
("hello world", "text/markdown", False, "<p>hello world</p>"),
|
||||
("hello world", "text/plain", False, "<p>hello world</p>"),
|
||||
(
|
||||
"<strong>hello world</strong>",
|
||||
"text/html",
|
||||
False,
|
||||
"<strong>hello world</strong>",
|
||||
),
|
||||
# images and other non whitelisted html should be removed
|
||||
("hello world\n", "text/markdown", "<p>hello world</p>"),
|
||||
("hello world\n", "text/markdown", False, "<p>hello world</p>"),
|
||||
(
|
||||
"hello world\n\n<script></script>\n\n<style></style>",
|
||||
"text/markdown",
|
||||
False,
|
||||
"<p>hello world</p>",
|
||||
),
|
||||
(
|
||||
"<p>hello world</p><script></script>\n\n<style></style>",
|
||||
"text/html",
|
||||
False,
|
||||
"<p>hello world</p>",
|
||||
),
|
||||
(
|
||||
'<p class="foo">hello world</p><script></script>\n\n<style></style>',
|
||||
"text/markdown",
|
||||
True,
|
||||
'<p class="foo">hello world</p>',
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_render_html(text, content_type, expected):
|
||||
result = utils.render_html(text, content_type)
|
||||
def test_render_html(text, content_type, permissive, expected):
|
||||
result = utils.render_html(text, content_type, permissive=permissive)
|
||||
assert result == expected
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -281,3 +281,15 @@ def test_can_render_text_preview(api_client, db):
|
|||
expected = {"rendered": utils.render_html(payload["text"], "text/markdown")}
|
||||
assert response.status_code == 200
|
||||
assert response.data == expected
|
||||
|
||||
|
||||
def test_can_render_text_preview_permissive(api_client, db):
|
||||
payload = {"text": "Hello world", "permissive": True}
|
||||
url = reverse("api:v1:text-preview")
|
||||
response = api_client.post(url, payload)
|
||||
|
||||
expected = {
|
||||
"rendered": utils.render_html(payload["text"], "text/markdown", permissive=True)
|
||||
}
|
||||
assert response.status_code == 200
|
||||
assert response.data == expected
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue