diff options
author | Isaac Muse <faceless.shop@gmail.com> | 2018-10-30 09:09:40 -0600 |
---|---|---|
committer | Waylan Limberg <waylan.limberg@icloud.com> | 2018-10-30 11:09:40 -0400 |
commit | a38fd1bb8b15e5de44e322b3345d0b5c29d5bf6b (patch) | |
tree | d39d28e0c81666602763afaa3e7e9c65c2912aae | |
parent | 7c78ac347b5dcad2be3d8d18b37ec33c96c1eb0b (diff) | |
download | python-markdown-a38fd1bb8b15e5de44e322b3345d0b5c29d5bf6b.tar.gz |
Collapse all whitespace in reference ids (#743)
Previously only newlines preceded by whitespace were collapsed. Fixes #742.
-rw-r--r-- | docs/change_log/release-3.1.md | 1 | ||||
-rw-r--r-- | markdown/inlinepatterns.py | 2 | ||||
-rw-r--r-- | tests/test_syntax/inline/test_links.py | 37 |
3 files changed, 39 insertions, 1 deletions
diff --git a/docs/change_log/release-3.1.md b/docs/change_log/release-3.1.md index c05d70f..0e8e2b1 100644 --- a/docs/change_log/release-3.1.md +++ b/docs/change_log/release-3.1.md @@ -35,3 +35,4 @@ The following bug fixes are included in the 3.1 release: * Block level elements are defined per instance, not as class attributes (#731). * Double escaping of block code has been eliminated (#725). +* Problems with newlines in references has been fixed (#742). diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py index 3d3e65f..dc502c2 100644 --- a/markdown/inlinepatterns.py +++ b/markdown/inlinepatterns.py @@ -617,7 +617,7 @@ class ImageInlineProcessor(LinkInlineProcessor): class ReferenceInlineProcessor(LinkInlineProcessor): """ Match to a stored reference and return link element. """ - NEWLINE_CLEANUP_RE = re.compile(r'[ ]?\n', re.MULTILINE) + NEWLINE_CLEANUP_RE = re.compile(r'\s+', re.MULTILINE) RE_LINK = re.compile(r'\s?\[([^\]]*)\]', re.DOTALL | re.UNICODE) diff --git a/tests/test_syntax/inline/test_links.py b/tests/test_syntax/inline/test_links.py index e147c82..988e041 100644 --- a/tests/test_syntax/inline/test_links.py +++ b/tests/test_syntax/inline/test_links.py @@ -134,3 +134,40 @@ class TestAdvancedLinks(TestCase): '[title](http://example.com/?a=1&b=2)', '<p><a href="http://example.com/?a=1&b=2">title</a></p>' ) + + def test_reference_newlines(self): + """Test reference id whitespace cleanup.""" + + self.assertMarkdownRenders( + self.dedent( + """ + Two things: + + - I would like to tell you about the [code of + conduct][] we are using in this project. + - Only one in fact. + + [code of conduct]: https://github.com/Python-Markdown/markdown/blob/master/CODE_OF_CONDUCT.md + """ + ), + '<p>Two things:</p>\n<ul>\n<li>I would like to tell you about the ' + '<a href="https://github.com/Python-Markdown/markdown/blob/master/CODE_OF_CONDUCT.md">code of\n' + ' conduct</a> we are using in this project.</li>\n<li>Only one in fact.</li>\n</ul>' + ) + + def test_reference_across_blocks(self): + """Test references across blocks.""" + + self.assertMarkdownRenders( + self.dedent( + """ + I would like to tell you about the [code of + + conduct][] we are using in this project. + + [code of conduct]: https://github.com/Python-Markdown/markdown/blob/master/CODE_OF_CONDUCT.md + """ + ), + '<p>I would like to tell you about the [code of</p>\n' + '<p>conduct][] we are using in this project.</p>' + ) |