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 E73D61050D for ; Mon, 21 Oct 2013 21:09:24 +0000 (UTC) Received: (qmail 75007 invoked by uid 500); 21 Oct 2013 21:06:15 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 74531 invoked by uid 500); 21 Oct 2013 21:05:29 -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 73435 invoked by uid 99); 21 Oct 2013 21:04:38 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Oct 2013 21:04:38 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 894754F514; Mon, 21 Oct 2013 21:04:36 +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 Date: Mon, 21 Oct 2013 21:04:58 -0000 Message-Id: <4c234ad36b77466da5c82ba38428c79e@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [24/50] git commit: [#6534] ticket:450 properly converting formatted links for textile, added and changes tests [#6534] ticket:450 properly converting formatted links for textile, added and changes tests Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/1893c2b0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/1893c2b0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/1893c2b0 Branch: refs/heads/cj/6686 Commit: 1893c2b02be438d426b3f78d7ba5e7fcef025657 Parents: b1b7f4e Author: coldmind Authored: Tue Oct 8 23:58:56 2013 +0300 Committer: Dave Brondsema Committed: Tue Oct 15 21:27:52 2013 +0000 ---------------------------------------------------------------------- .../forgeimporters/github/tests/test_wiki.py | 33 ++++++++++++++---- ForgeImporters/forgeimporters/github/wiki.py | 36 ++++++++++++++++---- 2 files changed, 57 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1893c2b0/ForgeImporters/forgeimporters/github/tests/test_wiki.py ---------------------------------------------------------------------- diff --git a/ForgeImporters/forgeimporters/github/tests/test_wiki.py b/ForgeImporters/forgeimporters/github/tests/test_wiki.py index 9dc4d67..95c0373 100644 --- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py +++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py @@ -327,10 +327,10 @@ Our website is [[http://sf.net]]. [External link](https://github.com/a/b/issues/1)''' - result = u'''

Look at [[this page|Some Page]]

-

More info at: [[MoreInfo]] [[Even More Info]]

-

Our website is [[http://sf.net]].

-

'[[Escaped Tag]]

+ result = u'''

Look at this page

+

More info at: MoreInfo Even More Info

+

Our website is http://sf.net.

+

'Escaped Tag

[External link to the wiki page](https://github.com/a/b/wiki/Page)

[External link](https://github.com/a/b/issues/1)

''' @@ -399,7 +399,7 @@ Some text 1. ## Header 2 -See [Page]''' +See [Page](Page)''' assert_equal(f(source, 'test.textile').strip(), result) @skipif(module_not_available('html2text')) @@ -412,7 +412,7 @@ See [Page]''' source = u'[[Ticks & Leeches]]' result = u'[Ticks & Leeches]' # markdown should be untouched - assert_equal(f(source, 'test.textile').strip(), result) + assert_equal(f(source, 'test.rst').strip(), result) def test_convert_markup_textile(self): @@ -438,6 +438,27 @@ See [Page]''' assert_equal(f(source, 'test.textile'), result) + # textile-style links converts normal + source = '*"Textile":Troubleshooting*' + result = '**[Textile](Troubleshooting)**\n' + assert_equal(f(source, 'test2.textile'), result) + + # links with formatting converts normal in textile now + source = u'''*[[this checklist|Troubleshooting]]* + +some text and *[[Tips n' Tricks]]* + +*[[link|http://otherlink.com]]* +''' + result = u'''**[this checklist](Troubleshooting)** + +some text and **[Tips n' Tricks]** + +**[link](http://otherlink.com)** +''' + assert_equal(f(source, 'test3.textile'), result) + + class TestGitHubWikiImportController(TestController, TestCase): url = '/p/%s/admin/ext/import/github-wiki/' % test_project_with_wiki http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1893c2b0/ForgeImporters/forgeimporters/github/wiki.py ---------------------------------------------------------------------- diff --git a/ForgeImporters/forgeimporters/github/wiki.py b/ForgeImporters/forgeimporters/github/wiki.py index 944bf79..dbbaac9 100644 --- a/ForgeImporters/forgeimporters/github/wiki.py +++ b/ForgeImporters/forgeimporters/github/wiki.py @@ -279,12 +279,7 @@ class GitHubWikiImporter(ToolImporter): return text else: if ext and ext in self.textile_exts: - # need to convert lists properly - text_lines = text.splitlines() - for i, l in enumerate(text_lines): - if l.lstrip().startswith('#'): - text_lines[i] = l.lstrip() - text = '\n'.join(text_lines) + text = self._prepare_textile_text(text) text = h.render_any_markup(filename, text) text = self.rewrite_links(text, self.github_wiki_url, self.app.url) @@ -374,3 +369,32 @@ class GitHubWikiImporter(ToolImporter): elif a.text == prefix + page: a.setString(new_prefix + new_page) return unicode(soup) + + def _prepare_textile_text(self, text): + # need to convert lists properly + text_lines = text.splitlines() + for i, l in enumerate(text_lines): + if l.lstrip().startswith('#'): + text_lines[i] = l.lstrip() + text = '\n'.join(text_lines) + + # if gollum-link, need to convert it to textile-link, + # because textile converter does not convert formatted + # gollum-link properly + link_re = re.compile("\[\[(?P[^]]+)\]\]") + links = link_re.findall(text) + for link in links: + link = link.split('|') + if len(link) != 1: + title, link = link[0], link[1] + text = text.replace(u'[[%s|%s]]' % (title, link), + '"%s":%s' % (title, link.replace(' ', '%20'))) + else: + link = link[0] + # textile importer doesn't works with some symbols + if "'" in link: + text = text.replace(u'[[%s]]' % link, '[%s]' % link) + else: + text = text.replace(u'[[%s]]' % link, + '"%s":%s' % (link, link.replace(' ', '%20'))) + return text