[ckan-changes] commit/ckan: zephod: [markdown][s]: Glitchfix of multi-line links.

Bitbucket commits-noreply at bitbucket.org
Tue Nov 1 15:21:26 UTC 2011


1 new commit in ckan:


https://bitbucket.org/okfn/ckan/changeset/607f3363a8c5/
changeset:   607f3363a8c5
user:        zephod
date:        2011-11-01 16:21:17
summary:     [markdown][s]: Glitchfix of multi-line links.
affected #:  2 files

diff -r 5d6a3e50fe8fa15de8d57f2ed269952c9e08d17a -r 607f3363a8c5d83792cd81a9bde833365ff8e626 ckan/misc.py
--- a/ckan/misc.py
+++ b/ckan/misc.py
@@ -24,7 +24,7 @@
     any_link = re.compile(r'<a[^>]*?>', re.IGNORECASE)
     close_link = re.compile(r'<(\/a[^>]*)>', re.IGNORECASE)
     link_escp = re.compile(r'\\xfc\\xfd(\/?(%s)[^>]*?)\\xfd\\xfc' % "|".join(['a']), re.IGNORECASE)
-    web_address = re.compile(r'(\s|^)((http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)', re.IGNORECASE)
+    web_address = re.compile(r'(\s|<p>)((http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)', re.IGNORECASE)
     
     def to_html(self, text):
         if text is None:
@@ -32,9 +32,6 @@
         # Encode whitelist elements.
         text = self.whitelist_elem.sub(r'\\\\xfc\\\\xfd\1\\\\xfd\\\\xfc', text)
 
-        # Discover external addresses and make them links
-        text = self.web_address.sub(r'\1<\2>', text)
-        
         # Encode links only in an acceptable format (guard against spammers)
         text = self.normal_link.sub(r'\\\\xfc\\\\xfda href="\1" target="_blank" rel="nofollow"\\\\xfd\\\\xfc', text)
         text = self.abbrev_link.sub(r'\\\\xfc\\\\xfda href="\1" target="_blank" rel="nofollow"\\\\xfd\\\\xfc\1</a>', text)
@@ -53,6 +50,9 @@
         # Markdown to HTML.
         text = webhelpers.markdown.markdown(text, safe_mode=True)
 
+        # Remaining unlinked web addresses to become addresses
+        text = self.web_address.sub(r'\1<a href="\2" target="_blank" rel="nofollow">\2</a>', text)
+
         # Decode whitelist elements.
         text = self.whitelist_escp.sub(r'<\1>', text)
         text = self.link_escp.sub(r'<\1>', text)


diff -r 5d6a3e50fe8fa15de8d57f2ed269952c9e08d17a -r 607f3363a8c5d83792cd81a9bde833365ff8e626 ckan/tests/misc/test_format_text.py
--- a/ckan/tests/misc/test_format_text.py
+++ b/ckan/tests/misc/test_format_text.py
@@ -82,3 +82,16 @@
         out = format.to_html(instr)
         assert exp in out, '\nGot: %s\nWanted: %s' % (out, exp)
 
+    def test_multiline_links(self):
+        instr = u'''I get 10 times more traffic from [Google][] than from
+[Yahoo][] or [MSN][].
+
+  [google]: http://google.com/        "Google"
+  [yahoo]:  http://search.yahoo.com/  "Yahoo Search"
+  [msn]:    http://search.msn.com/    "MSN Search"'''
+        exp = '''I get 10 times more traffic from <a href="http://google.com/" title="Google">Google</a> than from
+   <a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a> or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.'''
+        # NB when this is put into Genshi, it will close the tag for you.
+        format = MarkdownFormat()
+        out = format.to_html(instr)
+        assert exp in out, '\nGot: %s\nWanted: %s' % (out, exp)

Repository URL: https://bitbucket.org/okfn/ckan/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list