|
4 | 4 | Example command-line calls: |
5 | 5 |
|
6 | 6 | # Show syntax highlighted code in the terminal window |
7 | | - $ ./highlight.py -a myfile.py |
| 7 | + $ ./highlight.py myfile.py |
8 | 8 |
|
9 | 9 | # Colorize myfile.py and display in a browser |
10 | 10 | $ ./highlight.py -b myfile.py |
|
13 | 13 | ./highlight.py -s myfile.py |
14 | 14 |
|
15 | 15 | # Create a complete HTML file |
16 | | - $ ./highlight.py myfile.py > myfile.html |
| 16 | + $ ./highlight.py -c myfile.py > myfile.html |
17 | 17 |
|
18 | 18 | ''' |
19 | 19 |
|
@@ -149,31 +149,28 @@ def build_page(source, title='python', css=default_css, html=default_html): |
149 | 149 | description = 'Add syntax highlighting to Python source') |
150 | 150 | parser.add_argument('sourcefile', metavar = 'SOURCEFILE', |
151 | 151 | help = 'File containing Python sourcecode') |
152 | | - parser.add_argument('-a', '--ansi', action = 'store_true', |
153 | | - help = 'emit ANSI escape highlighted source') |
154 | 152 | parser.add_argument('-b', '--browser', action = 'store_true', |
155 | 153 | help = 'launch a browser to show results') |
| 154 | + parser.add_argument('-c', '--complete', action = 'store_true', |
| 155 | + help = 'build a complete html webpage') |
156 | 156 | parser.add_argument('-s', '--section', action = 'store_true', |
157 | 157 | help = 'show an HTML section rather than a complete webpage') |
158 | 158 | args = parser.parse_args() |
159 | 159 |
|
160 | | - if args.browser and args.section: |
| 160 | + if args.section and (args.browser or args.complete): |
161 | 161 | parser.error('The -s/--section option is incompatible with ' |
162 | | - 'the -b/--browser option') |
163 | | - if args.ansi and (args.browser or args.section): |
164 | | - parser.error('The -a/--ansi option is incompatible with ' |
165 | | - 'the -b/--browser and -s/--section options') |
| 162 | + 'the -b/--browser or -c/--complete options') |
166 | 163 |
|
167 | 164 | sourcefile = args.sourcefile |
168 | 165 | with open(sourcefile) as f: |
169 | 166 | source = f.read() |
170 | 167 |
|
171 | | - if args.ansi: |
172 | | - encoded = colorize_ansi(source) |
| 168 | + if args.complete or args.browser: |
| 169 | + encoded = build_page(source, title=sourcefile) |
173 | 170 | elif args.section: |
174 | 171 | encoded = colorize_html(source) |
175 | 172 | else: |
176 | | - encoded = build_page(source, title=sourcefile) |
| 173 | + encoded = colorize_ansi(source) |
177 | 174 |
|
178 | 175 | if args.browser: |
179 | 176 | htmlfile = os.path.splitext(os.path.basename(sourcefile))[0] + '.html' |
|
0 commit comments