v1.0.0
This commit is contained in:
1 parent
dfad658237
commit
6c5175d2f1
34 files changed
+3007
-1239
No files matched your search
@@ -0,0 +1,59 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""Markdown für Hilfe, Impressum und Datenschutzerklärung: Aufbau und Sicherheit."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from surveybox import markdown
|
||||
|
||||
|
||||
def test_title_headings_and_anchors() -> None:
|
||||
doc = markdown.render(
|
||||
"# Titel\n\n## Erste Schritte\n\nText\n\n## Erste Schritte\n### Für `Profis`")
|
||||
assert doc.title == "Titel" and "<h1" not in doc.html
|
||||
assert '<h2 id="erste-schritte">' in doc.html and '<h2 id="erste-schritte-1">' in doc.html
|
||||
assert [h.anchor for h in doc.headings] == ["erste-schritte", "erste-schritte-1", "für-profis"]
|
||||
assert markdown.slugify("6. Baustein für die Datenschutzerklärung") == \
|
||||
"6-baustein-für-die-datenschutzerklärung"
|
||||
assert markdown.slugify("Einstellungen (.env)") == "einstellungen-env"
|
||||
|
||||
|
||||
def test_html_is_never_passed_through() -> None:
|
||||
doc = markdown.render('<script>alert(1)</script>\n\n**<img src=x onerror=alert(1)>**\n\n'
|
||||
'`<b>` and [x](javascript:alert(1)) and [y](https://a.example/"onmouseover)'
|
||||
' and [z](data:text/html,1) and [w](//evil.example)')
|
||||
assert "<script" not in doc.html and "<script>" in doc.html
|
||||
assert "<img" not in doc.html and "<strong><img" in doc.html
|
||||
assert "<code><b></code>" in doc.html
|
||||
# Unsichere Ziele werden zu reinem Text, ohne Link
|
||||
assert "<a " not in doc.html
|
||||
|
||||
|
||||
def test_links() -> None:
|
||||
doc = markdown.render("[A](https://a.example/?x=1&y=2) [M](mailto:a@b.example) [S](#sec) "
|
||||
"[P](/help) <https://b.example>")
|
||||
assert '<a href="https://a.example/?x=1&y=2" rel="noopener noreferrer">A</a>' in doc.html
|
||||
assert '<a href="mailto:a@b.example">M</a>' in doc.html and '<a href="#sec">S</a>' in doc.html
|
||||
assert '<a href="/help">P</a>' in doc.html and 'href="https://b.example"' in doc.html
|
||||
mapped = markdown.render(
|
||||
"[E](ersteller.md#x) [U](unbekannt.md)",
|
||||
link_map=lambda t: "/help/ersteller#x" if t.startswith("ersteller") else None)
|
||||
assert '<a href="/help/ersteller#x">E</a>' in mapped.html and ">U</a>" not in mapped.html
|
||||
|
||||
|
||||
def test_lists_tables_code_quotes() -> None:
|
||||
doc = markdown.render(
|
||||
"- eins\n weiter\n - innen\n- zwei\n\n1. a\n ```sql\n SELECT 1 < 2;\n ```\n2. b\n\n"
|
||||
"| A | B |\n| --- | --- |\n| `x|y` | z \\| w |\n\n> Zitat\n\n---\n")
|
||||
html = doc.html
|
||||
assert "<ul><li>eins weiter\n<ul><li>innen</li></ul></li><li>zwei</li></ul>" in html
|
||||
assert '<pre><code class="language-sql">SELECT 1 < 2;</code></pre>' in html
|
||||
assert "<td><code>x|y</code></td><td>z | w</td>" in html
|
||||
assert "<blockquote><p>Zitat</p></blockquote>" in html and "<hr>" in html
|
||||
assert "<p>" not in html.split("<ol>")[0] # enge Liste ohne Absätze
|
||||
|
||||
|
||||
def test_line_breaks() -> None:
|
||||
assert markdown.render("A\nB").html == "<p>A B</p>"
|
||||
assert markdown.render("A \nB").html == "<p>A<br>\nB</p>"
|
||||
assert markdown.render("Name\nStraße 1\n\nX", hard_breaks=True).html == \
|
||||
"<p>Name<br>\nStraße 1</p>\n<p>X</p>"
|
||||
Reference in new issue
Block a user