Skip to content
Permalink
Browse files

make tests pass

  • Loading branch information
ralsina committed May 22, 2015
1 parent 161a69e commit 902fef7d17a2166c2ea0bec9a482dceed23718e7
Showing with 12 additions and 8 deletions.
  1. +9 −2 nikola/plugins/command/import_wordpress.py
  2. +3 −6 tests/test_command_import_wordpress.py
@@ -335,7 +335,10 @@ def download_additional_image_sizes(self, item, wordpress_namespace, source_path
links[url] = '/' + dst_url
links[url] = '/' + dst_url

code_re = re.compile(r'\[(?:source)?code(?: lang(?:uage)?="(.*?)")?\](.*?)\[/code\]', re.DOTALL | re.MULTILINE)
code_re1 = re.compile(r'\[code.* lang.*?="(.*?)?".*\](.*?)\[/code\]', re.DOTALL | re.MULTILINE)
code_re2 = re.compile(r'\[sourcecode.* lang.*?="(.*?)?".*\](.*?)\[/sourcecode\]', re.DOTALL | re.MULTILINE)
code_re3 = re.compile(r'\[code.*?\](.*?)\[/code\]', re.DOTALL | re.MULTILINE)
code_re4 = re.compile(r'\[sourcecode.*?\](.*?)\[/sourcecode\]', re.DOTALL | re.MULTILINE)

def transform_code(self, content):
# http://en.support.wordpress.com/code/posting-source-code/. There are
@@ -351,7 +354,11 @@ def replacement(m):
code = code.replace('"', '"')
return '```{language}\n{code}\n```'.format(language=language, code=code)

return self.code_re.sub(replacement, content)
content = self.code_re1.sub(replacement, content)
content = self.code_re2.sub(replacement, content)
content = self.code_re3.sub(replacement, content)
content = self.code_re4.sub(replacement, content)
return content

@staticmethod
def transform_caption(content):
@@ -228,13 +228,13 @@ def test_importing_posts_and_attachments(self):
Some source code.
~~~~~~~~~~~~{.Python}
```Python
import sys
print sys.version
~~~~~~~~~~~~
```
The end.
@@ -331,15 +331,12 @@ def test_transforming_source_code(self):
self.assertFalse('[sourcecode language=' in content)

replaced_content = """Hello World.
```Python
import sys
print sys.version
```
"""

```"""
self.assertEqual(content, replaced_content)

def test_transform_caption(self):

0 comments on commit 902fef7

Please sign in to comment.
You can’t perform that action at this time.