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/15 16:42:47 UTC

[22/50] git commit: [#6622] ticket:494 handle ``` without a blank line before it

[#6622] ticket:494 handle ``` without a blank line before it


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

Branch: refs/heads/cj/6777
Commit: 479c43e4cb025e4751a27871e1307ab7f382c963
Parents: 9efb689
Author: Igor Bondarenko <je...@gmail.com>
Authored: Wed Nov 13 12:11:42 2013 +0200
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:57 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_utils.py   | 32 ++++++++++++++++++++
 .../forgeimporters/github/tests/test_wiki.py    |  1 -
 ForgeImporters/forgeimporters/github/utils.py   |  9 ++++--
 .../forgeimporters/tests/github/test_tracker.py |  2 --
 4 files changed, 38 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/479c43e4/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 f31bba8..432c536 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_utils.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_utils.py
@@ -95,3 +95,35 @@ Two code blocks here!
     }'''
 
         assert_equal(self.conv.convert(text).strip(), result)
+
+    def test_code_blocks_without_newline_before(self):
+        text = u'''
+There are some code snippet:
+```
+print 'Hello'
+```
+Pretty cool, ha?'''
+
+        result = u'''
+There are some code snippet:
+
+    print 'Hello'
+Pretty cool, ha?'''
+        assert_equal(self.conv.convert(text).strip(), result.strip())
+        text = text.replace('```', '~~~')
+        assert_equal(self.conv.convert(text).strip(), result.strip())
+
+        text = u'''
+There are some code snippet:
+```python
+print 'Hello'
+```
+Pretty cool, ha?'''
+
+        result = u'''
+There are some code snippet:
+
+    :::python
+    print 'Hello'
+Pretty cool, ha?'''
+        assert_equal(self.conv.convert(text).strip(), result.strip())

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/479c43e4/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 b9b18bd..dec92a4 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -318,7 +318,6 @@ Our website is <http://sf.net>.
 
 [[Escaped Tag]]
 
-
     :::python
     codeblock
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/479c43e4/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
index cfc3a59..0beaba6 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'))
@@ -15,10 +15,13 @@ class GitHubMarkdownConverter(object):
     def _parse_lines(self, lines):
         in_block = False
         new_lines = []
-        for line in lines:
+        for i, line in enumerate(lines):
             nextline = False
             for p in self.code_patterns:
                 if line.startswith(p):
+                    prev_line = lines[i-1].strip() if (i-1) >= 0 else ''
+                    if len(prev_line) > 0 and not in_block:
+                        new_lines.append('')
                     if p == '```':
                         syntax = line.lstrip('`').strip()
                         if syntax:
@@ -135,4 +138,4 @@ class GitHubMarkdownConverter(object):
         return '<s>%s</s>' % m.group(1)
 
     def _codeblock_syntax(self, text):
-        return '\n    :::%s' % text
+        return '    :::%s' % text

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/479c43e4/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 e991382..e3da3c7 100644
--- a/ForgeImporters/forgeimporters/tests/github/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/github/test_tracker.py
@@ -195,7 +195,6 @@ def hello(name):
 
 Hello
 
-
     :::python
     def hello(name):
         print "Hello, " + name'''
@@ -230,7 +229,6 @@ def hello(name):
 
 Hello
 
-
     :::python
     def hello(name):
         print "Hello, " + name'''