incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [5/6] git commit: [#5315] ticket:218 artifact links don't show brackets if text is specified
Date Wed, 28 Nov 2012 01:27:57 GMT
[#5315] ticket:218 artifact links don't show brackets if text is specified


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/552a04b3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/552a04b3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/552a04b3

Branch: refs/heads/cj/4691
Commit: 552a04b3d17198c74898d7c6555d367a109460b0
Parents: d124811
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Tue Nov 20 17:26:54 2012 +0400
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Mon Nov 26 16:26:15 2012 +0000

----------------------------------------------------------------------
 Allura/allura/lib/markdown_extensions.py          |   13 ++++++++-----
 Allura/allura/tests/test_globals.py               |    4 ++--
 ForgeWiki/forgewiki/tests/functional/test_root.py |    8 ++++----
 3 files changed, 14 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/552a04b3/Allura/allura/lib/markdown_extensions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index 6454df5..6ef4b68 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -67,10 +67,12 @@ class ForgeLinkPattern(markdown.inlinepatterns.LinkPattern):
     def handleMatch(self, m):
         el = markdown.util.etree.Element('a')
         el.text = m.group(2)
+        is_link_with_brackets = False
         try:
             href = m.group(9)
         except IndexError:
             href = m.group(2)
+            is_link_with_brackets = True
         try:
             title = m.group(13)
         except IndexError:
@@ -80,7 +82,7 @@ class ForgeLinkPattern(markdown.inlinepatterns.LinkPattern):
             if href == 'TOC':
                 return '[TOC]'  # skip TOC
             if self.artifact_re.match(href):
-                href, classes = self._expand_alink(href)
+                href, classes = self._expand_alink(href, is_link_with_brackets)
             el.set('href', self.sanitize_url(self.unescape(href.strip())))
             el.set('class', classes)
         else:
@@ -92,18 +94,19 @@ class ForgeLinkPattern(markdown.inlinepatterns.LinkPattern):
 
         return el
 
-    def _expand_alink(self, link):
+    def _expand_alink(self, link, is_link_with_brackets):
         '''Return (href, classes) for an artifact link'''
         classes = ''
+        if is_link_with_brackets:
+            classes = 'alink'
         href = link
         shortlink = M.Shortlink.lookup(link)
         if shortlink:
             href = shortlink.url
-            classes = 'alink'
             self.ext.forge_link_tree_processor.alinks.append(shortlink)
         elif self.ext._use_wiki and ':' not in link:
             href = h.urlquote(link)
-            classes = 'notfound alink'
+            classes += ' notfound'
         return href, classes
 
 
@@ -175,7 +178,7 @@ class ForgeLinkTreeProcessor(markdown.treeprocessors.Treeprocessor):
 
     def run(self, root):
         for node in root.getiterator('a'):
-            if 'alink' in node.get('class', '').split():
+            if 'alink' in node.get('class', '').split() and node.text:
                 node.text = '[' + node.text + ']'
         return root
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/552a04b3/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 57422f1..111ebd8 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -175,9 +175,9 @@ def test_markdown_toc():
 def test_markdown_links():
     h.set_context('test', 'wiki', neighborhood='Projects')
     text = g.markdown.convert('Read [here](Home) about our project')
-    assert '<a class="alink" href="/p/test/wiki/Home/">[here]</a>' in text, text
+    assert '<a class="" href="/p/test/wiki/Home/">here</a>' in text, text
     text = g.markdown.convert('[Go home](test:wiki:Home)')
-    assert '<a class="alink" href="/p/test/wiki/Home/">[Go home]</a>' in text,
text
+    assert '<a class="" href="/p/test/wiki/Home/">Go home</a>' in text, text
     text = g.markdown.convert('See [test:wiki:Home]')
     assert '<a class="alink" href="/p/test/wiki/Home/">[test:wiki:Home]</a>'
in text, text
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/552a04b3/ForgeWiki/forgewiki/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/tests/functional/test_root.py b/ForgeWiki/forgewiki/tests/functional/test_root.py
index 945a6c6..3375b6d 100644
--- a/ForgeWiki/forgewiki/tests/functional/test_root.py
+++ b/ForgeWiki/forgewiki/tests/functional/test_root.py
@@ -475,16 +475,16 @@ class TestRootController(TestController):
         r = self.app.get('/wiki/TEST/')
         found_links = 0
         for link in r.html.findAll('a'):
-            if link.contents == ['[this page]']:
+            if link.contents == ['this page']:
                 assert 'notfound' not in link.get('class', '')
                 found_links +=1
-            if link.contents == ['[another page]']:
+            if link.contents == ['another page']:
                 assert 'notfound' in link.get('class', '')
                 found_links +=1
-            if link.contents == ['[space page space]']:
+            if link.contents == ['space page space']:
                 assert 'notfound' not in link.get('class', '')
                 found_links +=1
-            if link.contents == ['[space page escape]']:
+            if link.contents == ['space page escape']:
                 assert 'notfound' not in link.get('class', '')
                 found_links +=1
             if link.contents == ['[TEST]']:


Mime
View raw message