diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 28cdaf6..72329c8 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -10,7 +10,7 @@ re_whitespace = re.compile(r'[\t ]+') re_all_whitespace = re.compile(r'[\t \r\n]+') re_newline_whitespace = re.compile(r'[\t \r\n]*[\r\n][\t \r\n]*') -re_html_heading = re.compile(r'h(\d+)') +re_html_heading = re.compile(r'h(\d+)$') re_pre_lstrip1 = re.compile(r'^ *\n') re_pre_rstrip1 = re.compile(r'\n *$') re_pre_lstrip = re.compile(r'^[ \n]*\n') diff --git a/tests/test_custom_converter.py b/tests/test_custom_converter.py index 00a83fc..682280d 100644 --- a/tests/test_custom_converter.py +++ b/tests/test_custom_converter.py @@ -1,5 +1,6 @@ from markdownify import MarkdownConverter from bs4 import BeautifulSoup +import pytest class UnitTestConverter(MarkdownConverter): @@ -42,3 +43,19 @@ def test_soup(): html = 'test' soup = BeautifulSoup(html, 'html.parser') assert MarkdownConverter().convert_soup(soup) == '**test**' + + +@pytest.mark.parametrize('tag_name', ['h1-label', 'h2-status', 'h10-widget']) +def test_heading_prefix_does_not_make_custom_tag_a_heading(tag_name): + html = 'Before <{0}>Status after'.format(tag_name) + assert MarkdownConverter().convert(html) == 'Before Status after' + + +def test_heading_prefix_custom_tag_preserves_block_children(): + html = '

First

Second

' + assert MarkdownConverter().convert(html) == 'First\n\nSecond' + + +def test_heading_prefix_custom_tag_preserves_images(): + html = 'Ready' + assert MarkdownConverter().convert(html) == '![Ready](status.png)'