Skip to content

Commit a38fd1b

Browse files
facelessuserwaylan
authored andcommitted
Collapse all whitespace in reference ids (#743)
Previously only newlines preceded by whitespace were collapsed. Fixes #742.
1 parent 7c78ac3 commit a38fd1b

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

docs/change_log/release-3.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ The following bug fixes are included in the 3.1 release:
3535
* Block level elements are defined per instance, not as class attributes
3636
(#731).
3737
* Double escaping of block code has been eliminated (#725).
38+
* Problems with newlines in references has been fixed (#742).

markdown/inlinepatterns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ def handleMatch(self, m, data):
617617

618618
class ReferenceInlineProcessor(LinkInlineProcessor):
619619
""" Match to a stored reference and return link element. """
620-
NEWLINE_CLEANUP_RE = re.compile(r'[ ]?\n', re.MULTILINE)
620+
NEWLINE_CLEANUP_RE = re.compile(r'\s+', re.MULTILINE)
621621

622622
RE_LINK = re.compile(r'\s?\[([^\]]*)\]', re.DOTALL | re.UNICODE)
623623

tests/test_syntax/inline/test_links.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,40 @@ def test_amp_in_url(self):
134134
'[title](http://example.com/?a=1&b=2)',
135135
'<p><a href="http://example.com/?a=1&#x26;b=2">title</a></p>'
136136
)
137+
138+
def test_reference_newlines(self):
139+
"""Test reference id whitespace cleanup."""
140+
141+
self.assertMarkdownRenders(
142+
self.dedent(
143+
"""
144+
Two things:
145+
146+
- I would like to tell you about the [code of
147+
conduct][] we are using in this project.
148+
- Only one in fact.
149+
150+
[code of conduct]: https://github.com/Python-Markdown/markdown/blob/master/CODE_OF_CONDUCT.md
151+
"""
152+
),
153+
'<p>Two things:</p>\n<ul>\n<li>I would like to tell you about the '
154+
'<a href="https://github.com/Python-Markdown/markdown/blob/master/CODE_OF_CONDUCT.md">code of\n'
155+
' conduct</a> we are using in this project.</li>\n<li>Only one in fact.</li>\n</ul>'
156+
)
157+
158+
def test_reference_across_blocks(self):
159+
"""Test references across blocks."""
160+
161+
self.assertMarkdownRenders(
162+
self.dedent(
163+
"""
164+
I would like to tell you about the [code of
165+
166+
conduct][] we are using in this project.
167+
168+
[code of conduct]: https://github.com/Python-Markdown/markdown/blob/master/CODE_OF_CONDUCT.md
169+
"""
170+
),
171+
'<p>I would like to tell you about the [code of</p>\n'
172+
'<p>conduct][] we are using in this project.</p>'
173+
)

0 commit comments

Comments
 (0)