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

[20/21] git commit: [#6622] ticket:469 fixed regex'es and tests

[#6622] ticket:469 fixed regex'es and tests


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

Branch: refs/heads/master
Commit: ad1f2c335f1a51ced3250af4a39cbd97eaf9e4b3
Parents: bf301e0
Author: coldmind <so...@yandex.ru>
Authored: Thu Nov 7 13:08:11 2013 +0200
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:57 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_utils.py   | 23 +++++++-----
 .../forgeimporters/github/tests/test_wiki.py    | 11 ++++--
 ForgeImporters/forgeimporters/github/utils.py   | 37 +++++++-------------
 .../forgeimporters/tests/github/test_tracker.py | 25 ++++++++-----
 4 files changed, 53 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ad1f2c33/ForgeImporters/forgeimporters/github/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_utils.py b/ForgeImporters/forgeimporters/github/tests/test_utils.py
index d60cb0d..cc02e6b 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_utils.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_utils.py
@@ -85,15 +85,22 @@ for (var i = 0; i < a.length; i++) {
     console.log(i);
 }
 ```'''
-        result = u'''~~~~
-print "Hello!"
-~~~~
+        result = u'''<br>
+
+    :::python
+    print "Hello!"
+
+<br>
+
 
 Two code blocks here!
 
-~~~~
-for (var i = 0; i < a.length; i++) {
-    console.log(i);
-}
-~~~~'''
+
+<br>
+
+    for (var i = 0; i < a.length; i++) {
+        console.log(i);
+    }
+
+<br>'''
         assert_equal(self.conv.convert(text).strip(), result)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ad1f2c33/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 818f8ee..ee37c38 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -318,9 +318,14 @@ Our website is <http://sf.net>.
 
 [[Escaped Tag]]
 
-~~~~
-codeblock
-~~~~
+
+<br>
+
+    :::python
+    codeblock
+
+<br>
+
 
 ticket [#1]
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ad1f2c33/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
index 17e28ac..5d64666 100644
--- a/ForgeImporters/forgeimporters/github/utils.py
+++ b/ForgeImporters/forgeimporters/github/utils.py
@@ -6,7 +6,7 @@ class GitHubMarkdownConverter(object):
     def __init__(self, gh_user, gh_project):
         self.gh_project = '%s/%s' % (gh_user, gh_project)
         self.gh_base_url = u'https://github.com/'
-        self.code_patterns = ['```']
+        self.code_patterns = ['```', '~~~~~']
 
     def convert(self, text):
         lines = self._parse_lines(text.split('\n'))
@@ -19,11 +19,15 @@ class GitHubMarkdownConverter(object):
             nextline = False
             for p in self.code_patterns:
                 if line.lstrip().startswith(p):
-                    _re = re.compile(r'\```(.*)')
-                    syntax = _re.findall(line)[0]
-                    if syntax and not syntax.isspace():
-                        new_lines.append(self._codeblock_syntax(syntax))
-
+                    # this is extreme, but due to display bugs
+                    # it's necessary
+                    new_lines.append('\n<br>\n')
+
+                    if p == '```':
+                        _re = re.compile(r'\```(.*)')
+                        syntax = _re.findall(line)[0]
+                        if syntax and not syntax.isspace():
+                            new_lines.append(self._codeblock_syntax(syntax))
                     in_block = not in_block
                     nextline = True
                     break
@@ -33,14 +37,9 @@ 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('    '):
                     # 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
@@ -53,16 +52,6 @@ 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.
@@ -83,10 +72,10 @@ class GitHubMarkdownConverter(object):
         _re = re.compile(r'(\b)(\S+)@([0-9a-f]{40})(\b)')
         text = _re.sub(self._convert_user_sha, text)
 
-        _re = re.compile(r'(\b)([0-9a-f]{40})(\b)')
+        _re = re.compile(r'(\s|^)([0-9a-f]{40})(\s|$)')
         text = _re.sub(self._convert_sha, text)
 
-        _re = re.compile(r'~~(.*)~~',)
+        _re = re.compile(r'~~(.*?)~~',)
         text = _re.sub(self._convert_strikethrough, text)
 
         return text
@@ -141,7 +130,7 @@ class GitHubMarkdownConverter(object):
         return '<s>%s</s>' % m.group(1)
 
     def _codeblock_syntax(self, text):
-        return '\n    :::%s' % text
+        return '    :::%s' % text
 
     def _convert_inline_codeblock(self, m):
         text = m.group(0)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ad1f2c33/ForgeImporters/forgeimporters/tests/github/test_tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/test_tracker.py b/ForgeImporters/forgeimporters/tests/github/test_tracker.py
index bac2a1a..e305943 100644
--- a/ForgeImporters/forgeimporters/tests/github/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/github/test_tracker.py
@@ -195,10 +195,14 @@ def hello(name):
 
 Hello
 
-~~~~
-def hello(name):
-    print "Hello, " + name
-~~~~'''
+
+<br>
+
+    :::python
+    def hello(name):
+        print "Hello, " + name
+
+<br>'''
         issue = {
             'body': body,
             'title': 'title',
@@ -229,10 +233,15 @@ def hello(name):
 
 Hello
 
-~~~~
-def hello(name):
-    print "Hello, " + name
-~~~~'''
+
+<br>
+
+    :::python
+    def hello(name):
+        print "Hello, " + name
+
+<br>
+'''
         issue = {'comments_url': '/comments'}
         extractor.iter_comments.return_value = [
                 {