def highlight(content, lexer_name, formatter): try: lexer = get_lexer_by_name(lexer_name) except ClassNotFound: if lexer_name != '': return "No such lexer.", 400 if formatter and formatter != 'html': formatter = get_formatter_by_name(formatter) else: formatter = HtmlFormatter(linenos='table', anchorlinenos=True, lineanchors='L', linespans='L') if lexer_name == '': tokens = ((Token.Text, '{}\n'.format(c.decode('utf-8'))) for c in content.splitlines()) content = _format(tokens, formatter) else: content = _highlight(content, lexer, formatter) if not isinstance(formatter, HtmlFormatter): return content template = render_template("generic.html", cc='container-fluid', content=content, **style_args()) return template
def highlight(content, lexer_name): try: lexer = get_lexer_by_name(lexer_name) except ClassNotFound: if lexer_name != '': return "No such lexer.", 400 formatter = HtmlFormatter(linenos='table', anchorlinenos=True, lineanchors='L', linespans='L') if lexer_name == '': tokens = ((Token.Text, '{}\n'.format(c.decode('utf-8'))) for c in content.splitlines()) content = _format(tokens, formatter) else: content = _highlight(content, lexer, formatter) template = render_template('generic.html', cc='container-fluid', content=content) return Response(template, mimetype='text/html')
def highlight(content, lexer_name): try: lexer = get_lexer_by_name(lexer_name) except ClassNotFound: if lexer_name != "": return "No such lexer.", 400 formatter = HtmlFormatter(linenos="table", anchorlinenos=True, lineanchors="L", linespans="L") if lexer_name == "": tokens = ((Token.Text, "{}\n".format(c.decode("utf-8"))) for c in content.splitlines()) content = _format(tokens, formatter) else: content = _highlight(content, lexer, formatter) template = render_template("generic.html", cc="container-fluid", content=content, **style_args()) return Response(template, mimetype="text/html")
def highlight(content, lexer_name): try: lexer = get_lexer_by_name(lexer_name) except ClassNotFound: if lexer_name != '': return "No such lexer.", 400 formatter = HtmlFormatter(linenos='table', anchorlinenos=True, lineanchors='L', linespans='L') if lexer_name == '': tokens = ((Token.Text, '{}\n'.format(c.decode('utf-8'))) for c in content.splitlines()) content = _format(tokens, formatter) else: content = _highlight(content, lexer, formatter) template = render_template('highlight.html', content=content) return Response(template, mimetype='text/html')
def highlight(content, lexer_name, formatter): try: lexer = get_lexer_by_name(lexer_name) except ClassNotFound: if lexer_name != '': return "No such lexer.", 400 if formatter: formatter = get_formatter_by_name(formatter) else: formatter = HtmlFormatter(linenos='table', anchorlinenos=True, lineanchors='L', linespans='L') if lexer_name == '': tokens = ((Token.Text, '{}\n'.format(c.decode('utf-8'))) for c in content.splitlines()) content = _format(tokens, formatter) else: content = _highlight(content, lexer, formatter) if not isinstance(formatter, HtmlFormatter): return content template = render_template("generic.html", cc='container-fluid', content=content, **style_args()) return template