Ejemplo n.º 1
0
Archivo: util.py Proyecto: m42e/pb
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
Ejemplo n.º 2
0
Archivo: util.py Proyecto: hguemar/pb
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')
Ejemplo n.º 3
0
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")
Ejemplo n.º 4
0
Archivo: util.py Proyecto: GermainZ/pb
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')
Ejemplo n.º 5
0
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