Commit 498734ea authored by Raymond Hettinger's avatar Raymond Hettinger

Set title to the source filename

parent 3d0e030c
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
'Convert Python source code to HTML with colorized markup' 'Convert Python source code to HTML with colorized markup'
__all__ = ['colorize', 'build_page', 'default_css', 'default_html'] __all__ = ['colorize', 'build_page', 'default_css', 'default_html']
__author__ = 'Raymond Hettinger' __author__ = 'Raymond Hettinger'
import keyword, tokenize, cgi, functools import keyword, tokenize, cgi, functools
...@@ -71,7 +71,7 @@ default_html = '''\ ...@@ -71,7 +71,7 @@ default_html = '''\
<html> <html>
<head> <head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8"> <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title> Python Code </title> <title> %s </title>
<style type="text/css"> <style type="text/css">
%s %s
</style> </style>
...@@ -82,11 +82,12 @@ default_html = '''\ ...@@ -82,11 +82,12 @@ default_html = '''\
</html> </html>
''' '''
def build_page(source, html=default_html, css=default_css): def build_page(source, title='python', css=default_css, html=default_html):
'Create a complete HTML page with colorized Python source code' 'Create a complete HTML page with colorized Python source code'
css_str = '\n'.join(['%s %s' % item for item in css.items()]) css_str = '\n'.join(['%s %s' % item for item in css.items()])
result = colorize(source) result = colorize(source)
return html % (css_str, result) title = cgi.escape(title)
return html % (title, css_str, result)
if __name__ == '__main__': if __name__ == '__main__':
...@@ -108,7 +109,7 @@ if __name__ == '__main__': ...@@ -108,7 +109,7 @@ if __name__ == '__main__':
sourcefile = args.sourcefile[0] sourcefile = args.sourcefile[0]
with open(sourcefile) as f: with open(sourcefile) as f:
page = f.read() page = f.read()
html = colorize(page) if args.standalone else build_page(page) html = colorize(page) if args.standalone else build_page(page, title=sourcefile)
if args.browser: if args.browser:
htmlfile = os.path.splitext(os.path.basename(sourcefile))[0] + '.html' htmlfile = os.path.splitext(os.path.basename(sourcefile))[0] + '.html'
with open(htmlfile, 'w') as f: with open(htmlfile, 'w') as f:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment