Using a regexp to determine if a tag is a heading.

This commit is contained in:
Igor Dvorkin
2020-12-11 16:54:14 -08:00
parent d558617cd7
commit 7780f82c30
2 changed files with 10 additions and 1 deletions

View File

@@ -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: