Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: getnikola/nikola
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e7d37882f249^
Choose a base ref
...
head repository: getnikola/nikola
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d1dd872b21aa
Choose a head ref
  • 5 commits
  • 2 files changed
  • 2 contributors

Commits on Apr 24, 2015

  1. Copy the full SHA
    e7d3788 View commit details
  2. Copy the full SHA
    dcfa98f View commit details
  3. Make flake8 happy

    asmeurer authored and ralsina committed Apr 24, 2015
    Copy the full SHA
    10e4c2a View commit details
  4. Replace transform_sourcecode with transform_code

    The latter didn't really to a transformation, it just marked the problematic
    code.
    
    Also, don't use a new variable in transform_content, as you might forget to
    write new_content = func(new_content) instead of new_content = func(content).
    asmeurer authored and ralsina committed Apr 24, 2015
    Copy the full SHA
    6aac0ab View commit details
  5. update changelog

    ralsina committed Apr 24, 2015
    Copy the full SHA
    d1dd872 View commit details
Showing with 22 additions and 11 deletions.
  1. +1 −0 CHANGES.txt
  2. +21 −11 nikola/plugins/command/import_wordpress.py
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ New in master
Features
--------

* Support [code] in wordpress importers (Issue #1186)
* New translations (az, fil, tl, uk, zh_TW)
* Add reStructuredText transform support (Issue #1647)
* Produce Unicode output in ``nikola init`` (via Issue #1644)
32 changes: 21 additions & 11 deletions nikola/plugins/command/import_wordpress.py
Original file line number Diff line number Diff line change
@@ -335,13 +335,23 @@ def download_additional_image_sizes(self, item, wordpress_namespace, source_path
links[url] = '/' + dst_url
links[url] = '/' + dst_url

@staticmethod
def transform_sourcecode(content):
new_content = re.sub('\[sourcecode language="([^"]+)"\]',
"\n~~~~~~~~~~~~{.\\1}\n", content)
new_content = new_content.replace('[/sourcecode]',
"\n~~~~~~~~~~~~\n")
return new_content
code_re = re.compile(r'\[(?:source)?code(?: lang(?:uage)?="(.*?)")?\](.*?)\[/code\]', re.DOTALL)

def transform_code(self, content):
# http://en.support.wordpress.com/code/posting-source-code/. There are
# a ton of things not supported here. We only do a basic [code
# lang="x"] -> ```x translation, and remove quoted html entities (<,
# >, &, and ").
def replacement(m):
language = m.group(1) or ''
code = m.group(2)
code = code.replace('&amp;', '&')
code = code.replace('&gt;', '>')
code = code.replace('&lt;', '<')
code = code.replace('&quot;', '"')
return '```{language}\n{code}\n```'.format(language=language, code=code)

return self.code_re.sub(replacement, content)

@staticmethod
def transform_caption(content):
@@ -358,10 +368,10 @@ def transform_multiple_newlines(self, content):
return content

def transform_content(self, content):
new_content = self.transform_sourcecode(content)
new_content = self.transform_caption(new_content)
new_content = self.transform_multiple_newlines(new_content)
return new_content
content = self.transform_code(content)
content = self.transform_caption(content)
content = self.transform_multiple_newlines(content)
return content

def import_item(self, item, wordpress_namespace, out_folder=None):
"""Takes an item from the feed and creates a post file."""