diff options
-rwxr-xr-x | highlight.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/highlight.py b/highlight.py index a26d239..c48831d 100755 --- a/highlight.py +++ b/highlight.py @@ -106,6 +106,14 @@ infile = open(sys.argv[1], 'r') text = infile.read() infile.close() + +if re.match('.*\.html$', sys.argv[2]): + style = TuplrStyleDark + formatter = HtmlFormatter(style=style) +elif re.match('.*\.tex$', sys.argv[2]): + style = TuplrStyleLight + formatter = LatexFormatter(style=style) + if re.match('.*\.html$', sys.argv[2]): outfile = open(sys.argv[2], 'w') print >>outfile, '''<?xml version="1.0" encoding="UTF-8"?> @@ -115,12 +123,12 @@ if re.match('.*\.html$', sys.argv[2]): <head> <title>%s</title> <style type="text/css">''' % sys.argv[1] - print >>outfile, HtmlFormatter(style=TuplrStyleDark).get_style_defs('.highlight') + print >>outfile, formatter.get_style_defs('.highlight') print >>outfile, ''' </style> </head> <body> ''' - print >>outfile, highlight(text, TuplrLexer(), HtmlFormatter(style=TuplrStyleDark)) + print >>outfile, highlight(text, TuplrLexer(), formatter) print >>outfile, '''</body> </html> ''' @@ -131,16 +139,13 @@ if re.match('.*\.tex$', sys.argv[2]): print >>outfile, '''\\documentclass[10pt]{article} \\usepackage{fancyvrb} \\usepackage{color}''' - print >>outfile, LatexFormatter(style=TuplrStyleLight).get_style_defs() + print >>outfile, formatter.get_style_defs() print >>outfile, '\\newcommand\\PYlambda{$\\lambda$}' print >>outfile, '\\newcommand\\PYbiglambda{$\\Lambda$}' print >>outfile, '\\begin{document}' - out = highlight(text, TuplrLexer(), LatexFormatter(style=TuplrStyleLight)) - print out - print "******************************************************************************" + out = highlight(text, TuplrLexer(), formatter) out = out.replace('[fn', '[@PYlambda') out = out.replace('[Fn', '[@PYbiglambda') - print out print >>outfile, out print >>outfile, '\\end{document}' outfile.close() |