From a38fd1bb8b15e5de44e322b3345d0b5c29d5bf6b Mon Sep 17 00:00:00 2001 From: Isaac Muse Date: Tue, 30 Oct 2018 09:09:40 -0600 Subject: Collapse all whitespace in reference ids (#743) Previously only newlines preceded by whitespace were collapsed. Fixes #742. --- docs/change_log/release-3.1.md | 1 + markdown/inlinepatterns.py | 2 +- tests/test_syntax/inline/test_links.py | 37 ++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) 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)', '

title

' ) + + 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 + """ + ), + '

Two things:

\n' + ) + + 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 + """ + ), + '

I would like to tell you about the [code of

\n' + '

conduct][] we are using in this project.

' + ) -- cgit v1.2.1