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:52 UTC
[27/50] git commit: [#6622] ticket:469 A little refactoring and
regexes fix
[#6622] ticket:469 A little refactoring and regexes fix
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/05de134f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/05de134f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/05de134f
Branch: refs/heads/cj/6777
Commit: 05de134fbe059dd5b8b6c17d04dee9127ab52aaf
Parents: 11e2621
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Nov 11 13:07:47 2013 +0200
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:57 2013 +0000
----------------------------------------------------------------------
.../forgeimporters/github/tests/test_utils.py | 12 +++++-----
ForgeImporters/forgeimporters/github/utils.py | 23 +++++++++-----------
2 files changed, 16 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/05de134f/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 f426d6b..f31bba8 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_utils.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_utils.py
@@ -42,12 +42,7 @@ class TestGitHubMarkdownConverter(object):
text = 'Ticket #1'
result = self.conv.convert(text)
assert_equal(result, 'Ticket [#1]')
-
- # github treats '#' in the begining as a header
- text = '#1'
- assert_equal(self.conv.convert(text), '#1')
- text = ' #1'
- assert_equal(self.conv.convert(text), ' #1')
+ assert_equal(self.conv.convert('#1'), '[#1]')
def test_convert_user_ticket(self):
text = 'user#1'
@@ -73,6 +68,11 @@ class TestGitHubMarkdownConverter(object):
text = '~~mistake~~'
assert_equal(self.conv.convert(text), '<s>mistake</s>')
+ def test_inline_code_block(self):
+ text = u'This `~~some text~~` converts to this ~~strike out~~.'
+ result = u'This `~~some text~~` converts to this <s>strike out</s>.'
+ assert_equal(self.conv.convert(text).strip(), result)
+
def test_convert_code_blocks(self):
text = u'''```python
print "Hello!"
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/05de134f/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
index d509aa7..cfc3a59 100644
--- a/ForgeImporters/forgeimporters/github/utils.py
+++ b/ForgeImporters/forgeimporters/github/utils.py
@@ -18,9 +18,9 @@ class GitHubMarkdownConverter(object):
for line in lines:
nextline = False
for p in self.code_patterns:
- if line.lstrip().startswith(p):
+ if line.startswith(p):
if p == '```':
- syntax = line.lstrip().lstrip('`').strip()
+ syntax = line.lstrip('`').strip()
if syntax:
new_lines.append(self._codeblock_syntax(syntax))
in_block = not in_block
@@ -31,22 +31,19 @@ class GitHubMarkdownConverter(object):
if in_block:
new_lines.append(self._handle_code(line))
+ elif line.startswith(' '):
+ # indentation syntax code block - leave as is
+ new_lines.append(line)
else:
- _re = re.compile(r'`\s*(.*?)`')
+ _re = re.compile(r'`.*?`')
inline_matches = _re.findall(line)
-
- if line.startswith(' '):
- # code block due to github syntax
- new_lines.append(line)
- elif inline_matches and not inline_matches[0].isspace():
+ if inline_matches:
# 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 = line.replace(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])
-
+ line = line.replace('<inline_block>%s</inline_block>' % i, m)
new_lines.append(line)
else:
new_lines.append(self._handle_non_code(line))
@@ -71,7 +68,7 @@ class GitHubMarkdownConverter(object):
_re = re.compile(r'(\b)(\S+)#(\d+)(\b)')
text = _re.sub(self._convert_user_ticket, text)
- _re = re.compile(r'(\S+\s+)(#\d+)')
+ _re = re.compile(r'(\s|^)(#\d+)')
text = _re.sub(self._convert_ticket, text)
_re = re.compile(r'(\b)(\S+)/(\S+)@([0-9a-f]{40})(\b)')