Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0712f40

Browse files
committed
Add examples to the module docstring
1 parent 1087d9c commit 0712f40

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

Tools/scripts/highlight.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
#!/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+
'''
319

420
__all__ = ['colorize', 'build_page', 'default_css', 'default_html',
521
'ansi_colorize', 'default_ansi']
@@ -150,14 +166,14 @@ def build_page(source, title='python', css=default_css, html=default_html):
150166

151167
sourcefile = args.sourcefile
152168
with open(sourcefile) as f:
153-
page = f.read()
169+
source = f.read()
154170

155171
if args.ansi:
156-
encoded = colorize_ansi(page)
172+
encoded = colorize_ansi(source)
157173
elif args.section:
158-
encoded = colorize_html(page)
174+
encoded = colorize_html(source)
159175
else:
160-
encoded = build_page(page, title=sourcefile)
176+
encoded = build_page(source, title=sourcefile)
161177

162178
if args.browser:
163179
htmlfile = os.path.splitext(os.path.basename(sourcefile))[0] + '.html'

0 commit comments

Comments
 (0)