diff options
-rw-r--r-- | docs/change_log/release-3.1.md | 1 | ||||
-rw-r--r-- | markdown/blockprocessors.py | 2 | ||||
-rw-r--r-- | tests/test_syntax/blocks/test_headers.py | 20 |
3 files changed, 22 insertions, 1 deletions
diff --git a/docs/change_log/release-3.1.md b/docs/change_log/release-3.1.md index 0e8e2b1..5c225cf 100644 --- a/docs/change_log/release-3.1.md +++ b/docs/change_log/release-3.1.md @@ -36,3 +36,4 @@ The following bug fixes are included in the 3.1 release: (#731). * Double escaping of block code has been eliminated (#725). * Problems with newlines in references has been fixed (#742). +* Escaped `#` are now handled in header syntax (#762). diff --git a/markdown/blockprocessors.py b/markdown/blockprocessors.py index f3e1fa7..0bb6967 100644 --- a/markdown/blockprocessors.py +++ b/markdown/blockprocessors.py @@ -445,7 +445,7 @@ class HashHeaderProcessor(BlockProcessor): """ Process Hash Headers. """ # Detect a header at start of any line in block - RE = re.compile(r'(^|\n)(?P<level>#{1,6})(?P<header>.*?)#*(\n|$)') + RE = re.compile(r'(?:^|\n)(?P<level>#{1,6})(?P<header>(?:\\.|[^\\])*?)#*(?:\n|$)') def test(self, parent, block): return bool(self.RE.search(block)) diff --git a/tests/test_syntax/blocks/test_headers.py b/tests/test_syntax/blocks/test_headers.py index 38cae83..d9392e1 100644 --- a/tests/test_syntax/blocks/test_headers.py +++ b/tests/test_syntax/blocks/test_headers.py @@ -708,3 +708,23 @@ class TestHashHeaders(TestCase): """ ) ) + + def test_escaped_hash(self): + self.assertMarkdownRenders( + "### H3 \\###", + self.dedent( + """ + <h3>H3 #</h3> + """ + ) + ) + + def test_unescaped_hash(self): + self.assertMarkdownRenders( + "### H3 \\\\###", + self.dedent( + """ + <h3>H3 \\</h3> + """ + ) + ) |