summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsaac Muse <faceless.shop@gmail.com>2018-12-22 13:51:30 -0700
committerWaylan Limberg <waylan.limberg@icloud.com>2018-12-22 15:51:30 -0500
commit596be577c69c13ac3addcc84701e0a1014b088b0 (patch)
tree484b99f80d25c385a8be05022fce363fc8363e6f
parentab24c2357dfd98540d5196470164bf49b5e6d9f3 (diff)
downloadpython-markdown-596be577c69c13ac3addcc84701e0a1014b088b0.tar.gz
Allow hashes to be escaped in headers (#763)
Adjust pattern to allow for escaped hashes, but take care to not treat escaped escapes before hashes as escaped hashes. Close #762.
-rw-r--r--docs/change_log/release-3.1.md1
-rw-r--r--markdown/blockprocessors.py2
-rw-r--r--tests/test_syntax/blocks/test_headers.py20
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>
+ """
+ )
+ )