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/14 16:37:09 UTC

[17/41] git commit: [#6622] ticket:469 not handling inline blocks, fixed parser

[#6622] ticket:469 not handling inline blocks, fixed parser


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

Branch: refs/heads/cj/6845
Commit: 11e262165802abb0506ceb85750d88a120384f7a
Parents: ad1f2c3
Author: coldmind <so...@yandex.ru>
Authored: Fri Nov 8 13:49:11 2013 +0200
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:57 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_utils.py   | 13 ++------
 .../forgeimporters/github/tests/test_wiki.py    |  5 ---
 ForgeImporters/forgeimporters/github/utils.py   | 32 +++++++++++---------
 .../forgeimporters/tests/github/test_tracker.py | 11 ++-----
 4 files changed, 22 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/11e26216/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 cc02e6b..f426d6b 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_utils.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_utils.py
@@ -85,22 +85,13 @@ for (var i = 0; i < a.length; i++) {
     console.log(i);
 }
 ```'''
-        result = u'''<br>
-
-    :::python
+        result = u''':::python
     print "Hello!"
 
-<br>
-
-
 Two code blocks here!
 
-
-<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/11e26216/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 ee37c38..e0c83bb 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -319,14 +319,9 @@ Our website is <http://sf.net>.
 [[Escaped Tag]]
 
 
-<br>
-
     :::python
     codeblock
 
-<br>
-
-
 ticket [#1]
 
 #1 header

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/11e26216/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
index 5d64666..d509aa7 100644
--- a/ForgeImporters/forgeimporters/github/utils.py
+++ b/ForgeImporters/forgeimporters/github/utils.py
@@ -19,14 +19,9 @@ class GitHubMarkdownConverter(object):
             nextline = False
             for p in self.code_patterns:
                 if line.lstrip().startswith(p):
-                    # 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():
+                        syntax = line.lstrip().lstrip('`').strip()
+                        if syntax:
                             new_lines.append(self._codeblock_syntax(syntax))
                     in_block = not in_block
                     nextline = True
@@ -37,9 +32,22 @@ class GitHubMarkdownConverter(object):
             if in_block:
                 new_lines.append(self._handle_code(line))
             else:
-                if line.lstrip().startswith('    '):
+                _re = re.compile(r'`\s*(.*?)`')
+                inline_matches = _re.findall(line)
+
+                if line.startswith('    '):
                     # code block due to github syntax
-                    continue
+                    new_lines.append(line)
+                elif inline_matches and not inline_matches[0].isspace():
+                    # need to not handle inline blocks as a text
+                    for i, m in enumerate(inline_matches):
+                        line = line.replace('`%s`' % m, '<inline_block>%s</inline_block>' % i)
+
+                    line = self._handle_non_code(line)
+                    for i, m in enumerate(inline_matches):
+                        line = line.replace('<inline_block>%s</inline_block>' % i, inline_matches[i])
+
+                    new_lines.append(line)
                 else:
                     new_lines.append(self._handle_non_code(line))
         return new_lines
@@ -130,8 +138,4 @@ class GitHubMarkdownConverter(object):
         return '<s>%s</s>' % m.group(1)
 
     def _codeblock_syntax(self, text):
-        return '    :::%s' % text
-
-    def _convert_inline_codeblock(self, m):
-        text = m.group(0)
-        return '**%s**' % text
+        return '\n    :::%s' % text

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/11e26216/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 e305943..e991382 100644
--- a/ForgeImporters/forgeimporters/tests/github/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/github/test_tracker.py
@@ -196,13 +196,10 @@ def hello(name):
 Hello
 
 
-<br>
-
     :::python
     def hello(name):
-        print "Hello, " + name
+        print "Hello, " + name'''
 
-<br>'''
         issue = {
             'body': body,
             'title': 'title',
@@ -234,14 +231,10 @@ def hello(name):
 Hello
 
 
-<br>
-
     :::python
     def hello(name):
-        print "Hello, " + name
+        print "Hello, " + name'''
 
-<br>
-'''
         issue = {'comments_url': '/comments'}
         extractor.iter_comments.return_value = [
                 {