incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [22/50] git commit: [#6534] ticket:450 properly converting formatted links for textile, added and changes tests
Date Tue, 22 Oct 2013 21:50:32 GMT
[#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/6422
Commit: 1893c2b02be438d426b3f78d7ba5e7fcef025657
Parents: b1b7f4e
Author: coldmind <sokandpal@yandex.ru>
Authored: Tue Oct 8 23:58:56 2013 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
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'''<p>Look at [[this page|Some Page]]</p>
-<p>More info at: [[MoreInfo]] [[Even More Info]]</p>
-<p>Our website is [[http://sf.net]].</p>
-<p>'[[Escaped Tag]]</p>
+        result = u'''<p>Look at <a href="Some%20Page" rel="nofollow">this page</a></p>
+<p>More info at: <a href="MoreInfo" rel="nofollow">MoreInfo</a> <a href="Even%20More%20Info"
rel="nofollow">Even More Info</a></p>
+<p>Our website is <a href="http://sf.net" rel="nofollow">http://sf.net</a>.</p>
+<p>'<a href="Escaped%20Tag" rel="nofollow">Escaped Tag</a></p>
 <p>[External link to the wiki page](https://github.com/a/b/wiki/Page)</p>
 <p>[External link](https://github.com/a/b/issues/1)</p>'''
 
@@ -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<link>[^]]+)\]\]")
+        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


Mime
View raw message