|
| 1 | +from md2bbcode.main import process_readme |
| 2 | + |
| 3 | + |
| 4 | +def test_html_basic_formatting_and_links(): |
| 5 | + markdown = ( |
| 6 | + "<b>bold</b> <i>italic</i> <u>under</u> <s>strike</s> " |
| 7 | + "<ins>insert</ins> <mark>mark</mark> <kbd>kbd</kbd><br>" |
| 8 | + "<a href=\"https://example.com\">link</a> " |
| 9 | + "<img src=\"https://example.com/x.png\" alt=\"alt text\">" |
| 10 | + "<hr>" |
| 11 | + ) |
| 12 | + result = process_readme(markdown, domain="") |
| 13 | + lowered = result.lower() |
| 14 | + |
| 15 | + assert "[b]bold[/b]" in lowered |
| 16 | + assert "[i]italic[/i]" in lowered |
| 17 | + assert "[u]under[/u]" in lowered |
| 18 | + assert "[s]strike[/s]" in lowered |
| 19 | + assert "[u]insert[/u]" in lowered |
| 20 | + assert "[mark]mark[/mark]" in lowered |
| 21 | + assert "[icode]kbd[/icode]" in lowered |
| 22 | + assert "[url=https://example.com]link[/url]" in lowered |
| 23 | + assert "[img alt=\"alt text\"]https://example.com/x.png[/img]" in lowered |
| 24 | + assert "[hr][/hr]" in lowered |
| 25 | + |
| 26 | + |
| 27 | +def test_html_code_blocks_and_inline_code(): |
| 28 | + markdown = ( |
| 29 | + "<pre><code class=\"language-python\">print('hi')</code></pre>" |
| 30 | + " and <code>inline</code>" |
| 31 | + ) |
| 32 | + result = process_readme(markdown, domain="") |
| 33 | + lowered = result.lower() |
| 34 | + |
| 35 | + assert "[code=python]print('hi')[/code]" in lowered |
| 36 | + assert "[icode]inline[/icode]" in lowered |
| 37 | + |
| 38 | + |
| 39 | +def test_html_lists_and_tables(): |
| 40 | + markdown = ( |
| 41 | + "<ul><li>One</li><li>Two</li></ul>" |
| 42 | + "<ol><li>First</li><li>Second</li></ol>" |
| 43 | + "<table>" |
| 44 | + "<tr><th>H</th><th>H2</th></tr>" |
| 45 | + "<tr><td>A</td><td>B</td></tr>" |
| 46 | + "</table>" |
| 47 | + ) |
| 48 | + result = process_readme(markdown, domain="") |
| 49 | + lowered = result.lower() |
| 50 | + |
| 51 | + assert "[list]" in lowered |
| 52 | + assert "[*]one" in lowered |
| 53 | + assert "[*]two" in lowered |
| 54 | + assert "[list=1]" in lowered |
| 55 | + assert "[*]first" in lowered |
| 56 | + assert "[*]second" in lowered |
| 57 | + assert "[table]" in lowered |
| 58 | + assert "[tr]" in lowered |
| 59 | + assert "[th]h[/th]" in lowered |
| 60 | + assert "[td]a[/td]" in lowered |
| 61 | + |
| 62 | + |
| 63 | +def test_html_anchor_and_abbr(): |
| 64 | + markdown = ( |
| 65 | + "<a name=\"section\">Target</a> " |
| 66 | + "<a href=\"#section\">Jump</a> " |
| 67 | + "<abbr title=\"World Health Organization\">WHO</abbr>" |
| 68 | + ) |
| 69 | + result = process_readme(markdown, domain="") |
| 70 | + lowered = result.lower() |
| 71 | + |
| 72 | + assert "[aname=section]target[/aname]" in lowered |
| 73 | + assert "[jumpto=section]jump[/jumpto]" in lowered |
| 74 | + assert "[abbr=world health organization]who[/abbr]" in lowered |
| 75 | + |
| 76 | + |
| 77 | +def test_html_mailto_and_alignment(): |
| 78 | + markdown = ( |
| 79 | + "<a href=\"mailto:test@example.com?subject=Hello\">Email</a> " |
| 80 | + "<p style=\"text-align:center\">Centered</p>" |
| 81 | + "<div align=\"right\"><b>Right</b></div>" |
| 82 | + "<blockquote data-author=\"Alice\">Quoted</blockquote>" |
| 83 | + ) |
| 84 | + result = process_readme(markdown, domain="") |
| 85 | + lowered = result.lower() |
| 86 | + |
| 87 | + assert "[email]test@example.com[/email]" in lowered |
| 88 | + assert "[center]centered[/center]" in lowered |
| 89 | + assert "[right][b]right[/b][/right]" in lowered |
| 90 | + assert "[quote=\"alice\"]" in lowered |
| 91 | + assert "quoted" in lowered |
| 92 | + |
| 93 | + |
| 94 | +def test_span_and_div_without_style_convert_children(): |
| 95 | + markdown = "<span><b>Bold</b></span><div><i>Italic</i></div>" |
| 96 | + result = process_readme(markdown, domain="") |
| 97 | + lowered = result.lower() |
| 98 | + |
| 99 | + assert "[b]bold[/b]" in lowered |
| 100 | + assert "[i]italic[/i]" in lowered |
| 101 | + assert "<span>" not in lowered |
| 102 | + assert "<div>" not in lowered |
| 103 | + |
| 104 | + |
| 105 | +def test_unknown_html_passthrough(): |
| 106 | + markdown = "<custom-tag data-x=\"1\"><b>Bold</b></custom-tag>" |
| 107 | + result = process_readme(markdown, domain="") |
| 108 | + |
| 109 | + assert "<custom-tag data-x=\"1\">" in result |
| 110 | + assert "<b>Bold</b>" in result |
| 111 | + assert "[b]" not in result |
0 commit comments