You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/11/13 23:57:38 UTC

[18/44] 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/6815
Commit: 43f16922c239d5445e455986771783d0e536ffcb
Parents: f9db5f9
Author: coldmind <so...@yandex.ru>
Authored: Wed Nov 6 19:35:57 2013 +0200
Committer: Dave Brondsema <db...@slashdotmedia.com>
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>%s</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