aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2010-10-11 23:40:50 -0400
committerWaylan Limberg <waylan@gmail.com>2010-10-11 23:40:50 -0400
commitcbb8de8c5001b85dd28b6dca20c0bf58827167fb (patch)
tree92dd20e2a0930bd891057564eb0c25ec5da17a29
parente2a79787f426bef4c2455d235252362586838773 (diff)
downloadmarkdown-cbb8de8c5001b85dd28b6dca20c0bf58827167fb.tar.gz
markdown-cbb8de8c5001b85dd28b6dca20c0bf58827167fb.tar.bz2
markdown-cbb8de8c5001b85dd28b6dca20c0bf58827167fb.zip
Fixed Ticket 79. Linebreaks in reference link identifiers are now ignored. This matches the most recent version of markdown.pl among other implementations and allows links to work after editors do autolinebreak stuff to text.
-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"