Using a regexp to determine if a tag is a heading.
This commit is contained in:
@@ -6,6 +6,7 @@ import six
|
||||
convert_heading_re = re.compile(r'convert_h(\d+)')
|
||||
line_beginning_re = re.compile(r'^', re.MULTILINE)
|
||||
whitespace_re = re.compile(r'[\r\n\s\t ]+')
|
||||
html_heading_re = re.compile(r'h[1-6]')
|
||||
|
||||
|
||||
# Heading styles
|
||||
@@ -66,7 +67,7 @@ class MarkdownConverter(object):
|
||||
def process_tag(self, node, convert_as_inline, children_only=False):
|
||||
text = ''
|
||||
# markdown headings can't include block elements (elements w/newlines)
|
||||
isHeading = node.name.startswith('h')
|
||||
isHeading = html_heading_re.match(node.name) is not None
|
||||
convert_children_as_inline = convert_as_inline
|
||||
|
||||
if not children_only and isHeading:
|
||||
|
||||
@@ -115,6 +115,14 @@ def test_hn_nested_tag():
|
||||
assert md('<h3>A <blockquote>BQ</blockquote> C </h3>') == '### A BQ C\n\n'
|
||||
|
||||
|
||||
def test_hr():
|
||||
assert md('<hr>hr</hr>') == 'hr'
|
||||
|
||||
|
||||
def test_head():
|
||||
assert md('<head>head</head>') == 'head'
|
||||
|
||||
|
||||
def test_atx_headings():
|
||||
assert md('<h1>Hello</h1>', heading_style=ATX) == '# Hello\n\n'
|
||||
assert md('<h2>Hello</h2>', heading_style=ATX) == '## Hello\n\n'
|
||||
|
||||
Reference in New Issue
Block a user