|
| 1 | +import pytest |
| 2 | +import pyhtml2md |
| 3 | + |
| 4 | +def test_escape_numbered_list_enabled_by_default(): |
| 5 | + html = "4.<br />\nPlease implement as requested." |
| 6 | + expected = "4\\. \nPlease implement as requested.\n" |
| 7 | + assert pyhtml2md.convert(html) == expected |
| 8 | + |
| 9 | +def test_escape_numbered_list_disabled(): |
| 10 | + html = "4.<br />\nPlease implement as requested." |
| 11 | + options = pyhtml2md.Options() |
| 12 | + options.escapeNumberedList = False |
| 13 | + |
| 14 | + # When disabled, it should be interpreted as a list item (or at least not escaped) |
| 15 | + # The original issue was that "4." became "1." because it was seen as a list. |
| 16 | + # So we expect "1. \nPlease..." or similar if it's interpreted as a list, |
| 17 | + # OR just "4. \n..." if it's not escaped but also not renumbered (depending on md4c/parser behavior). |
| 18 | + # However, based on the issue description: "The issue is, that this text is renumbered by Markdown and rendered as '1.\nPlease...'." |
| 19 | + # So if we disable escaping, we expect the output to contain "4. \n" which might then be rendered as "1." by a viewer, |
| 20 | + # BUT html2md output itself is what we check. |
| 21 | + # If we don't escape, html2md outputs "4. \n". |
| 22 | + |
| 23 | + expected = "4. \nPlease implement as requested.\n" |
| 24 | + converter = pyhtml2md.Converter(html, options) |
| 25 | + assert converter.convert() == expected |
| 26 | + |
| 27 | +def test_escape_numbered_list_with_other_content(): |
| 28 | + html = "<p>1. Item</p>" |
| 29 | + # In a paragraph, it might be different. |
| 30 | + # But our fix is in ParseCharInTagContent which handles text content. |
| 31 | + # If it's "1. Item", it should be escaped to "1\. Item" if enabled. |
| 32 | + |
| 33 | + expected = "1\\. Item\n" |
| 34 | + assert pyhtml2md.convert(html) == expected |
| 35 | + |
| 36 | + options = pyhtml2md.Options() |
| 37 | + options.escapeNumberedList = False |
| 38 | + expected_disabled = "1. Item\n" |
| 39 | + converter = pyhtml2md.Converter(html, options) |
| 40 | + assert converter.convert() == expected_disabled |
0 commit comments