Created
October 25, 2012 01:21
-
-
Save sdhjl2000/3949945 to your computer and use it in GitHub Desktop.
generate html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=gbk | |
from pygments import highlight | |
from pygments.lexers import PythonLexer,CSharpLexer | |
from pygments.formatters import HtmlFormatter | |
from pygments.lexers import get_lexer_by_name | |
import os | |
import sys | |
reload(sys) | |
sys.setdefaultencoding('utf8') | |
path = os.path.expanduser("~/Projects/apsptouch/jstouch2") | |
outpath=os.path.expanduser("~/Projects/apsptouch/html") | |
formatter = HtmlFormatter(full=False) | |
lexer=CSharpLexer(encoding='utf-8') | |
outstr="" | |
for parent,dirnames,filenames in os.walk(path): | |
for f in filenames: | |
if f.endswith('.cs'): | |
file = open(os.path.join(parent, f)) | |
code = file.read() | |
#print f | |
outcode= highlight(code, lexer, formatter) | |
outstr=outstr+ outcode | |
#print os.path.join(parent, f) | |
#open(os.path.join(outpath, f)+".html","w").write(outcode) | |
file.close() | |
print outstr | |
open(os.path.join(outpath,"out.html"),"a").write(outstr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment