incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [14/44] git commit: [#6534] ticket:441 gollum page links conversion
Date Fri, 04 Oct 2013 14:43:02 GMT
[#6534] ticket:441 gollum page links conversion


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

Branch: refs/heads/master
Commit: f06327ad00c1b63db274ba7af9a03e7e0310cdd9
Parents: ec066ab
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Wed Sep 18 15:50:02 2013 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Oct 4 14:21:21 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/github/wiki.py | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f06327ad/ForgeImporters/forgeimporters/github/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/wiki.py b/ForgeImporters/forgeimporters/github/wiki.py
index feaca46..027bc89 100644
--- a/ForgeImporters/forgeimporters/github/wiki.py
+++ b/ForgeImporters/forgeimporters/github/wiki.py
@@ -15,6 +15,7 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
+import re
 from datetime import datetime
 from tempfile import mkdtemp
 from shutil import rmtree
@@ -204,7 +205,24 @@ class GitHubWikiImporter(ToolImporter):
         rmtree(wiki_path)
 
     def convert_gollum_page_links(self, text):
-        return text
+        _re = re.compile(r'''(?P<quote>')?            # possible tag escaping
+                             (?P<tag>\[\[             # tag start
+                             (?:(?P<title>[^]|]*)\|)? # optional title
+                             (?P<page>[^]]+)          # page name
+                             \]\])                    # tag end''', re.VERBOSE)
+
+        def repl(match):
+            page = match.group('page').replace('-', ' ').replace('/', ' ')
+            title = match.groupdict().get('title')
+            quote = match.groupdict().get('quote')
+            if quote:
+                # tag is escaped, return untouched
+                return match.group('tag')
+            if title:
+                return u'[{}]({})'.format(title, page)
+            return u'[{}]'.format(page)
+
+        return _re.sub(repl, text)
 
     def convert_gollum_external_links(self, text):
         return text


Mime
View raw message