Return-Path: X-Original-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B10D5E790 for ; Wed, 28 Nov 2012 01:27:57 +0000 (UTC) Received: (qmail 16459 invoked by uid 500); 28 Nov 2012 01:27:57 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 16424 invoked by uid 500); 28 Nov 2012 01:27:57 -0000 Mailing-List: contact allura-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: allura-dev@incubator.apache.org Delivered-To: mailing list allura-commits@incubator.apache.org Received: (qmail 16359 invoked by uid 99); 28 Nov 2012 01:27:57 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Nov 2012 01:27:57 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5E739812C37; Wed, 28 Nov 2012 01:27:57 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: johnsca@apache.org To: allura-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [5/6] git commit: [#5315] ticket:218 artifact links don't show brackets if text is specified Message-Id: <20121128012757.5E739812C37@tyr.zones.apache.org> Date: Wed, 28 Nov 2012 01:27:57 +0000 (UTC) [#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 Authored: Tue Nov 20 17:26:54 2012 +0400 Committer: Dave Brondsema 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 '[here]' in text, text + assert 'here' in text, text text = g.markdown.convert('[Go home](test:wiki:Home)') - assert '[Go home]' in text, text + assert 'Go home' in text, text text = g.markdown.convert('See [test:wiki:Home]') assert '[test:wiki:Home]' 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]']: