

@register.simple_tag
def pygments(filename):
    fqfn = os.path.abspath(os.path.join(settings.PROJECT_DIR, filename))
    with open(fqfn, 'r') as f:
        readlines = f.readlines()
    startfrom = 0
    prevline = True
    content = []
    for (lno, line) in enumerate(readlines):
        if ('start tutorial' in line):
            startfrom = (lno + 1)
        if ('end tutorial' in line):
            break
        if (bool(line) and (not line.isspace())):
            content.append(line)
            prevline = True
        else:
            if prevline:
                content.append(line)
            prevline = False
    code = ''.join(content[startfrom:])
    if filename.endswith('.py'):
        lexer = PythonLexer()
    elif filename.endswith('.html'):
        lexer = HtmlDjangoLexer()
    elif filename.endswith('.js'):
        lexer = JavascriptLexer()
    return highlight(code, lexer, HtmlFormatter())

dataset/ETHPy150Open jrief/django-angular/examples/server/templatetags/tutorial_tags.py pygments/original