Пример #1
0
def highlight(filename, code):
    try:
        lexer = guess_lexer(code)
    except ClassNotFound:
        try:
            lexer = guess_lexer_for_filename(filename, code)
        except ClassNotFound:
            return code
    return highlight_(code, lexer, get_output_type())
Пример #2
0
def highlight(code, lexer=None):
    if not isinstance(lexer, Lexer):
        try:
            if lexer == None:
                lexer = lexers.guess_lexer(code)
            else:
                lexer = lexers.get_lexer_by_name(lexer)
        except lexers.ClassNotFound:
            lexer = lexers.get_lexer_by_name('text')

    formatter = CodeHtmlFormatter()

    return highlight_(code, lexer, formatter), lexer.aliases[0]
Пример #3
0
def highlight(code, lexer=None):
    if lexer == 'ansi':
        return ansi2html(code), 'ansi'

    if lexer == None:
        lexer = lexers.guess_lexer(code)
    else:
        try:
            lexer = lexers.get_lexer_by_name(lexer)
        except lexers.ClassNotFound:
            lexer = lexers.get_lexer_by_name('text')

    formatter = CodeHtmlFormatter()

    return highlight_(code, lexer, formatter), lexer.aliases[0]
Пример #4
0
def highlight(code, lexer=None):
    if lexer == "ansi":
        return ansi2html(code), "ansi"

    if lexer == None:
        lexer = lexers.guess_lexer(code)
    else:
        try:
            lexer = lexers.get_lexer_by_name(lexer)
        except lexers.ClassNotFound:
            lexer = lexers.get_lexer_by_name("text")

    formatter = CodeHtmlFormatter()

    return highlight_(code, lexer, formatter), lexer.aliases[0]
Пример #5
0
 def highlight(text):
     return highlight_(text, lexer, formatter)
Пример #6
0
 def highlight(text):
     return highlight_(text, lexer, formatter)