Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.netfront.net!not-for-mail From: "dabaichi" Newsgroups: comp.lang.python Subject: Anybody familiar with pygments ? Date: Thu, 9 May 2013 12:10:40 +0800 Organization: Netfront http://www.netfront.net/ Lines: 96 Message-ID: NNTP-Posting-Host: 222.36.104.10 Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="gb2312"; reply-type=original Content-Transfer-Encoding: 7bit X-Trace: adenine.netfront.net 1368072399 79942 222.36.104.10 (9 May 2013 04:06:39 GMT) X-Complaints-To: news@netfront.net NNTP-Posting-Date: Thu, 9 May 2013 04:06:39 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal Importance: Normal X-Newsreader: Microsoft Windows Live Mail 16.4.3505.912 X-MimeOLE: Produced By Microsoft MimeOLE V16.4.3505.912 Xref: csiph.com comp.lang.python:45000 Hello guys: pygments version: 1.6 python version :3.3.1(64bits, use msi installer install) os:windows 7 (64bits) Hereis my python source code: #!/usr/bin/env python #-*- coding=utf-8 -*- import os import sys from pygments import highlight as html_highlight from pygments.lexers import get_lexer_by_name from pygments.formatters import HtmlFormatter from pygments.styles import get_style_by_name def highlight(filename): formatter = HtmlFormatter(linenos=True, style="vim") filename_split = filename.split('.') if len(filename_split) == 1: return None lexer = get_lexer_by_name(filename_split[len(filename_split) - 1]) try: with open(filename, 'r') as fp: content = fp.read() except Exception: return None html_content = html_highlight(content, lexer, formatter) return html_content def main(): filename = r'test.c' print(highlight(filename)) if __name__ == "__main__": main() Here is test.c source code: #include int main(int argc, char * argv[]) { printf("This is a test!\n"); return 0; } And hereis the output file:
1
2
3
4
5
6
7
#include <stdio.h>

int main(int argc, char 
* argv[])
{
    printf("This is a test!\n");
    return 0;
}
It looks like: 1 #include 2 3 int main(int argc, char * argv[]) 4 { 5 printf("This is a test!\n"); 6 return 0; 7 } 8 with no color in firefox (20.0.1) I want to know why output html file with no color ? Is my code error ? Best regard! --peipei --- news://freenews.netfront.net/ - complaints: news@netfront.net ---