Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
make tests pass
  • Loading branch information
ralsina committed May 22, 2015
1 parent 161a69e commit 902fef7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
11 changes: 9 additions & 2 deletions nikola/plugins/command/import_wordpress.py
Expand Up @@ -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
Expand All @@ -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):
Expand Down
9 changes: 3 additions & 6 deletions tests/test_command_import_wordpress.py
Expand Up @@ -228,13 +228,13 @@ def test_importing_posts_and_attachments(self):
Some source code.
~~~~~~~~~~~~{.Python}
```Python
import sys
print sys.version
~~~~~~~~~~~~
```
The end.
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 902fef7

Please sign in to comment.