Skip to content

Instantly share code, notes, and snippets.

@sdhjl2000
Created October 25, 2012 01:21
Show Gist options
  • Save sdhjl2000/3949945 to your computer and use it in GitHub Desktop.
Save sdhjl2000/3949945 to your computer and use it in GitHub Desktop.
generate html
# 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