def render_code(code, filetype, pygments_style):
    """Renders a piece of code into HTML. Highlights syntax if filetype is specfied"""
    if filetype:
        lexer = pygments.lexers.get_lexer_by_name(filetype)
        formatter = pygments.formatters.HtmlFormatter(style=pygments_style)
        return pygments.highlight(code, lexer, formatter)
    else:
        return "<pre><code>{}</code></pre>".format(code)
Renders a piece of code into HTML. Highlights syntax if filetype is specfied