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 89A3410BE8 for ; Fri, 15 Nov 2013 15:43:12 +0000 (UTC) Received: (qmail 65326 invoked by uid 500); 15 Nov 2013 15:43:02 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 65053 invoked by uid 500); 15 Nov 2013 15:42:50 -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 64081 invoked by uid 99); 15 Nov 2013 15:42:26 -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, 15 Nov 2013 15:42:26 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 6FD1482EC8B; Fri, 15 Nov 2013 15:42:26 +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, 15 Nov 2013 15:42:41 -0000 Message-Id: In-Reply-To: <7e9d5c72bb8e4724b18c0f6e787629d2@git.apache.org> References: <7e9d5c72bb8e4724b18c0f6e787629d2@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [16/50] git commit: [#6622] ticket:469 handling github inline code [#6622] ticket:469 handling github inline code Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/43f16922 Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/43f16922 Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/43f16922 Branch: refs/heads/cj/6777 Commit: 43f16922c239d5445e455986771783d0e536ffcb Parents: f9db5f9 Author: coldmind Authored: Wed Nov 6 19:35:57 2013 +0200 Committer: Dave Brondsema Committed: Wed Nov 13 17:16:56 2013 +0000 ---------------------------------------------------------------------- ForgeImporters/forgeimporters/github/utils.py | 24 ++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/43f16922/ForgeImporters/forgeimporters/github/utils.py ---------------------------------------------------------------------- diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py index 03dfe1b..292b41e 100644 --- a/ForgeImporters/forgeimporters/github/utils.py +++ b/ForgeImporters/forgeimporters/github/utils.py @@ -33,8 +33,14 @@ class GitHubMarkdownConverter(object): if in_block: new_lines.append(self._handle_code(line)) else: + _re = re.compile(r'`\s*(.*?)`') + is_inline_code = _re.findall(line) + if line.lstrip().startswith(' '): - new_lines.append(self._handle_code(line)) + # code block due to github syntax + continue + elif is_inline_code and not is_inline_code[0].isspace(): + new_lines.append(self._handle_inline_code(line)) else: new_lines.append(self._handle_non_code(line)) return new_lines @@ -47,6 +53,16 @@ class GitHubMarkdownConverter(object): text = ' ' + text return text + def _handle_inline_code(self, text): + """Return a string that will replace ``text`` in the final text + output. ``text`` is inline code. + + """ + _re = re.compile(r'`(\s*)(.*?)`') + text = _re.sub(self._convert_inline_codeblock, text) + + return text + def _handle_non_code(self, text): """Return a string that will replace ``text`` in the final text output. ``text`` is *not* code. @@ -125,4 +141,8 @@ class GitHubMarkdownConverter(object): return '%s' % m.group(1) def _codeblock_syntax(self, text): - return '\n :::%s' % text \ No newline at end of file + return '\n :::%s' % text + + def _convert_inline_codeblock(self, m): + text = m.group(0) + return '**%s**' % text