示例#1
0
文件: util.py 项目: 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
示例#2
0
文件: util.py 项目: 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')
示例#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")
示例#4
0
文件: util.py 项目: 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')
示例#5
0
文件: util.py 项目: jetpacktuxedo/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:
        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