|
1 | 1 | #!/usr/bin/env python3 |
2 | | -'Add syntax highlighting to Python source code' |
| 2 | +'''Add syntax highlighting to Python source code |
| 3 | +
|
| 4 | +Example command-line calls: |
| 5 | +
|
| 6 | + # Show syntax highlighted code in the terminal window |
| 7 | + $ ./highlight.py -a myfile.py |
| 8 | +
|
| 9 | + # Colorize myfile.py and display in a browser |
| 10 | + $ ./highlight.py -b myfile.py |
| 11 | +
|
| 12 | + # Create an HTML section that can be embedded in an existing webpage |
| 13 | + ./highlight.py -s myfile.py |
| 14 | +
|
| 15 | + # Create a complete HTML file |
| 16 | + $ ./highlight.py myfile.py > myfile.html |
| 17 | +
|
| 18 | +''' |
3 | 19 |
|
4 | 20 | __all__ = ['colorize', 'build_page', 'default_css', 'default_html', |
5 | 21 | 'ansi_colorize', 'default_ansi'] |
@@ -150,14 +166,14 @@ def build_page(source, title='python', css=default_css, html=default_html): |
150 | 166 |
|
151 | 167 | sourcefile = args.sourcefile |
152 | 168 | with open(sourcefile) as f: |
153 | | - page = f.read() |
| 169 | + source = f.read() |
154 | 170 |
|
155 | 171 | if args.ansi: |
156 | | - encoded = colorize_ansi(page) |
| 172 | + encoded = colorize_ansi(source) |
157 | 173 | elif args.section: |
158 | | - encoded = colorize_html(page) |
| 174 | + encoded = colorize_html(source) |
159 | 175 | else: |
160 | | - encoded = build_page(page, title=sourcefile) |
| 176 | + encoded = build_page(source, title=sourcefile) |
161 | 177 |
|
162 | 178 | if args.browser: |
163 | 179 | htmlfile = os.path.splitext(os.path.basename(sourcefile))[0] + '.html' |
|
0 commit comments