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 E99F410622 for ; Fri, 4 Oct 2013 16:31:00 +0000 (UTC) Received: (qmail 29620 invoked by uid 500); 4 Oct 2013 16:30:49 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 29383 invoked by uid 500); 4 Oct 2013 16:30:44 -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 28509 invoked by uid 99); 4 Oct 2013 16:30:31 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Oct 2013 16:30:31 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 8A11190FAC5; Fri, 4 Oct 2013 16:30:30 +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: Fri, 04 Oct 2013 16:30:56 -0000 Message-Id: <4acf5defc00442eea41f9efceec6db46@git.apache.org> In-Reply-To: <22c701cf1faa461199ee44abb47bd1f2@git.apache.org> References: <22c701cf1faa461199ee44abb47bd1f2@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [28/50] git commit: [#6534] ticket:441 Convert markup using html2text if available [#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/5561 Commit: af36eaf0d514d0acd9cd18219862970056c303a8 Parents: 31b4db7 Author: Igor Bondarenko Authored: Fri Sep 20 11:13:47 2013 +0300 Committer: Dave Brondsema 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 . 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 . + +[[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'''

Look at [[this page|Some Page]]

+

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

+

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

+

'[[Escaped Tag]]

''' + + 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)