aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--markdown/inlinepatterns.py5
-rw-r--r--tests/basic/links-reference.html8
-rw-r--r--tests/basic/links-reference.txt10
3 files changed, 22 insertions, 1 deletions
diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py
index ebc6d8d..badcef1 100644
--- a/markdown/inlinepatterns.py
+++ b/markdown/inlinepatterns.py
@@ -325,6 +325,9 @@ class ImagePattern(LinkPattern):
class ReferencePattern(LinkPattern):
""" Match to a stored reference and return link element. """
+
+ NEWLINE_CLEANUP_RE = re.compile(r'[ ]?\n', re.MULTILINE)
+
def handleMatch(self, m):
if m.group(9):
id = m.group(9).lower()
@@ -333,6 +336,8 @@ class ReferencePattern(LinkPattern):
# we'll use "google" as the id
id = m.group(2).lower()
+ # Clean up linebreaks in id
+ id = self.NEWLINE_CLEANUP_RE.sub(' ', id)
if not id in self.markdown.references: # ignore undefined refs
return None
href, title = self.markdown.references[id]
diff --git a/tests/basic/links-reference.html b/tests/basic/links-reference.html
index 9780bf3..992525c 100644
--- a/tests/basic/links-reference.html
+++ b/tests/basic/links-reference.html
@@ -9,4 +9,10 @@
<pre><code>[four]: /url
</code></pre>
<p>With <a href="http://example.com/" title="Angle Brackets">angle brackets</a>.</p>
-<p>And <a href="http://example.com/" title="Without angle brackets.">without</a>.</p> \ No newline at end of file
+<p>And <a href="http://example.com/" title="Without angle brackets.">without</a>.</p>
+<p>With <a href="http://example.com" title="Yes this works">line
+breaks</a></p>
+<p>and <a href="http://example.com" title="Yes this works">line
+breaks</a> with one space.</p>
+<p>and [line<br />
+breaks[] with two spaces.</p> \ No newline at end of file
diff --git a/tests/basic/links-reference.txt b/tests/basic/links-reference.txt
index 9993b10..c95a195 100644
--- a/tests/basic/links-reference.txt
+++ b/tests/basic/links-reference.txt
@@ -37,3 +37,13 @@ And [without][].
[angle brackets]: <http://example.com/> "Angle Brackets"
[without]: http://example.com/ "Without angle brackets."
+With [line
+breaks][]
+
+and [line
+breaks][] with one space.
+
+and [line
+breaks[] with two spaces.
+
+[line breaks]: http://example.com "Yes this works"