Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion markdown/blockprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ class SetextHeaderProcessor(BlockProcessor):
""" Process Setext-style Headers. """

# Detect Setext-style header. Must be first 2 lines of block.
RE = re.compile(r'^.*?\n[=-]+[ ]*(\n|$)', re.MULTILINE)
RE = re.compile(r'^.*?\n(?:[=]+|[-]+)[ ]*(\n|$)', re.MULTILINE)

def test(self, parent: etree.Element, block: str) -> bool:
return bool(self.RE.match(block))
Expand Down
51 changes: 51 additions & 0 deletions tests/test_syntax/blocks/test_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,57 @@ def test_setext_h2_followed_by_p(self):

# TODO: fix this
# see https://johnmacfarlane.net/babelmark2/?normalize=1&text=Paragraph%0AAn+H1%0A%3D%3D%3D%3D%3D

def test_setext_mixed_chars_not_h1(self):
"""Mixed = and - chars should not form a valid H1."""
self.assertMarkdownRenders(
self.dedent(
"""
This is not an H1
=-
"""
),
self.dedent(
"""
<p>This is not an H1
=-</p>
"""
)
)

def test_setext_mixed_chars_not_h2(self):
"""Mixed - and = chars should not form a valid H2."""
self.assertMarkdownRenders(
self.dedent(
"""
This is not an H2
-=
"""
),
self.dedent(
"""
<p>This is not an H2
-=</p>
"""
)
)

def test_setext_mixed_multiple_chars(self):
"""Multiple mixed = and - chars should not form a valid H1/H2."""
self.assertMarkdownRenders(
self.dedent(
"""
Not a Header
=-=-
"""
),
self.dedent(
"""
<p>Not a Header
=-=-</p>
"""
)
)
@unittest.skip('This is broken in Python-Markdown')
def test_p_followed_by_setext_h1(self):
self.assertMarkdownRenders(
Expand Down