Example #1
0
def enumerate_and_color(codelines, firstlineno, enc):
    snippet = H.SourceBlock()
    tokenizer = source_color.Tokenizer(source_color.PythonSchema)
    for i, line in enumerate(codelines):
        try:
            snippet.add_line(i + firstlineno + 1,
                             source_html.prepare_line([line], tokenizer, enc))
        except py.error.ENOENT:
            # error reading source code, giving up
            snippet = codelines
            break
    return snippet
Example #2
0
def prepare_line_helper(line, tokenizer=None, encoding='ascii'):
    if tokenizer is None:
        tokenizer = Tokenizer(PythonSchema)
    l = prepare_line(line, tokenizer, encoding)
    return ''.join([unicode(i) for i in l])