incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [28/50] git commit: [#6534] ticket:441 Convert markup using html2text if available
Date Fri, 04 Oct 2013 18:07:12 GMT
[#6534] ticket:441 Convert markup using html2text if available


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

Branch: refs/heads/cj/6692
Commit: af36eaf0d514d0acd9cd18219862970056c303a8
Parents: 31b4db7
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri Sep 20 11:13:47 2013 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Oct 4 14:21:22 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_wiki.py    | 41 +++++++++++++++++++-
 ForgeImporters/forgeimporters/github/wiki.py    | 22 +++++++++++
 2 files changed, 62 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/af36eaf0/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 4f29842..352ce24 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -21,8 +21,9 @@ from unittest import TestCase
 from nose.tools import assert_equal
 from mock import Mock, patch, call
 
+from IPython.testing.decorators import module_not_available, skipif
 from allura.tests import TestController
-from allura.tests.decorators import with_tool
+from allura.tests.decorators import with_tool, without_module
 from alluratest.controller import setup_basic_test
 from forgeimporters.github.wiki import GitHubWikiImporter
 
@@ -182,6 +183,44 @@ Our website is <http://sf.net>.
 
         assert_equal(f(source), result)
 
+    @skipif(module_not_available('html2text'))
+    def test_convert_markup(self):
+        f = GitHubWikiImporter().convert_markup
+        source = 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](Some Page)
+
+More info at: [MoreInfo] [Even More Info]
+
+Our website is <http://sf.net>.
+
+[[Escaped Tag]]\n\n'''
+
+        assert_equal(f(source, 'test.md'), result)
+
+    @without_module('html2text')
+    def test_convert_markup_without_html2text(self):
+        f = GitHubWikiImporter().convert_markup
+        source = u'''Look at [[this page|Some Page]]
+
+More info at: [[MoreInfo]] [[Even More Info]]
+
+Our website is [[http://sf.net]].
+
+'[[Escaped Tag]]'''
+
+        result = u'''<div class="markdown_content"><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></div>'''
+
+        assert_equal(f(source, 'test.md'), result)
 
 class TestGitHubWikiImportController(TestController, TestCase):
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/af36eaf0/ForgeImporters/forgeimporters/github/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/wiki.py b/ForgeImporters/forgeimporters/github/wiki.py
index a05b954..b299a85 100644
--- a/ForgeImporters/forgeimporters/github/wiki.py
+++ b/ForgeImporters/forgeimporters/github/wiki.py
@@ -204,6 +204,28 @@ class GitHubWikiImporter(ToolImporter):
             self.get_blobs_with_history(commit)
         rmtree(wiki_path)
 
+    def convert_markup(self, text, filename):
+        """Convert any supported github markup into Allura-markdown.
+
+        Conversion happens in 3 phases:
+
+        1. Convert source text to a html using h.render_any_markup
+        2. Convert resulting html to a markdown using html2text, if available.
+        3. Convert gollum tags
+
+        If html2text module isn't available then only phase (1) will be executed.
+        """
+        try:
+            import html2text
+        except ImportError:
+            html2text = None
+
+        text = h.render_any_markup(filename, text)
+        if html2text:
+            text = html2text.html2text(text)
+            text = self.convert_gollum_tags(text)
+        return text
+
     def convert_gollum_tags(self, text):
         # order is important
         text = self.convert_gollum_external_links(text)


Mime
View raw message