/
/
/
1"""Tests for converting HTML descriptions to markdown."""
2
3from music_assistant.helpers.util import html_to_markdown
4
5
6def test_html_to_markdown() -> None:
7 """Test that safe HTML is converted to markdown and the rest is stripped."""
8 # regression for audiobook/podcast descriptions leaking HTML into the player OSD
9 line = "<p>In 1940, 18-year old Ursula Todd is born.</p>"
10 assert html_to_markdown(line) == "In 1940, 18-year old Ursula Todd is born."
11
12 # inline formatting is converted to markdown
13 assert html_to_markdown("A <b>bold</b> tale") == "A **bold** tale"
14 assert html_to_markdown("An <i>italic</i> tale") == "An *italic* tale"
15
16 # html entities are unescaped
17 assert html_to_markdown("Cause & Effect") == "Cause & Effect"
18
19 # entity-escaped markup (e.g. from podcast RSS feeds) is decoded first, then converted
20 assert html_to_markdown("<p>In 1940.</p>") == "In 1940."
21 assert html_to_markdown("A <b>bold</b> tale") == "A **bold** tale"
22
23 # multiple paragraphs become separate markdown paragraphs
24 assert html_to_markdown("<p>First.</p><p>Second.</p>") == "First.\n\nSecond."
25
26 # tags outside the safe set are stripped while their text content is kept
27 assert html_to_markdown("A <u>underlined</u> word") == "A underlined word"
28
29 # plain text without markup is returned unchanged
30 assert html_to_markdown("Just plain text") == "Just plain text"
31