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:
class="linenodiv">1
2
3
4
5
6
7class="cp">#include
int mainclass="p">(int class="n">argc, char
* argvclass="p">[])
{
printf(class="s">"This is a test!\nclass="s">");
return 0class="p">;
}
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: n...@netfront.net ---
--
http://mail.python.org/mailman/listinfo/python-list