# Buggy code
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)

    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


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/ralsina/.virtualenvs/nikola/local/lib/python2.7/site-packages/doit-0.28.0-py2.7.egg/doit/doit_cmd.py", line 165, in run
return command.parse_execute(args)
File "/home/ralsina/.virtualenvs/nikola/local/lib/python2.7/site-packages/doit-0.28.0-py2.7.egg/doit/cmd_base.py", line 122, in parse_execute
return self.execute(params, args)
File "/home/ralsina/Desktop/proyectos/nikola/master/nikola/plugin_categories.py", line 125, in execute
self._execute(options, args)
File "/home/ralsina/Desktop/proyectos/nikola/master/nikola/plugins/command/import_wordpress.py", line 162, in _execute
self.import_posts(channel)
File "/home/ralsina/Desktop/proyectos/nikola/master/nikola/plugins/command/import_wordpress.py", line 512, in import_posts
self.process_item(item)
File "/home/ralsina/Desktop/proyectos/nikola/master/nikola/plugins/command/import_wordpress.py", line 506, in process_item
self.import_item(item, wordpress_namespace, 'posts')
File "/home/ralsina/Desktop/proyectos/nikola/master/nikola/plugins/command/import_wordpress.py", line 484, in import_item
content = self.transform_content(content)
File "/home/ralsina/Desktop/proyectos/nikola/master/nikola/plugins/command/import_wordpress.py", line 369, in transform_content
content = self.transform_code(content)
File "/home/ralsina/Desktop/proyectos/nikola/master/nikola/plugins/command/import_wordpress.py", line 350, in transform_code
content = self.code_re3.sub(replacement, content)
File "/home/ralsina/Desktop/proyectos/nikola/master/nikola/plugins/command/import_wordpress.py", line 341, in replacement
code = m.group(2)
IndexError: no such group

# Fixed code
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, c=content):
        if len(m.groups()) == 1:
            language = ""
            code = m.group(0)
        else:
            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)

    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