@@ -50,21 +50,22 @@ class HelpParser(HTMLParser):
50
50
"""
51
51
def __init__ (self , text ):
52
52
HTMLParser .__init__ (self , convert_charrefs = True )
53
- self .text = text # text widget we're rendering into
54
- self .tags = '' # current block level text tags to apply
55
- self .chartags = '' # current character level text tags
56
- self .show = False # used so we exclude page navigation
57
- self .hdrlink = False # used so we don't show header links
58
- self .level = 0 # indentation level
59
- self .pre = False # displaying preformatted text
60
- self .hprefix = '' # prefix such as '25.5' to strip from headings
61
- self .nested_dl = False # if we're in a nested <dl>
62
- self .simplelist = False # simple list (no double spacing)
63
- self .toc = [] # pair headers with text indexes for toc
64
- self .header = '' # text within header tags for toc
65
- self .prevtag = None # info about previous tag (was opener, tag)
53
+ self .text = text # Text widget we're rendering into.
54
+ self .tags = '' # Current block level text tags to apply.
55
+ self .chartags = '' # Current character level text tags.
56
+ self .show = False # Exclude html page navigation.
57
+ self .hdrlink = False # Exclude html header links.
58
+ self .level = 0 # Track indentation level.
59
+ self .pre = False # Displaying preformatted text?
60
+ self .hprefix = '' # Heading prefix (like '25.5'?) to remove.
61
+ self .nested_dl = False # In a nested <dl>?
62
+ self .simplelist = False # In a simple list (no double spacing)?
63
+ self .toc = [] # Pair headers with text indexes for toc.
64
+ self .header = '' # Text within header tags for toc.
65
+ self .prevtag = None # Previous tag info ( opener? , tag).
66
66
67
67
def indent (self , amt = 1 ):
68
+ "Change indent (+1, 0, -1) and tags."
68
69
self .level += amt
69
70
self .tags = '' if self .level == 0 else 'l' + str (self .level )
70
71
@@ -76,12 +77,12 @@ def handle_starttag(self, tag, attrs):
76
77
class_ = v
77
78
s = ''
78
79
if tag == 'div' and class_ == 'section' :
79
- self .show = True # start of main content
80
+ self .show = True # Start main content.
80
81
elif tag == 'div' and class_ == 'sphinxsidebar' :
81
- self .show = False # end of main content
82
+ self .show = False # End main content.
82
83
elif tag == 'p' and self .prevtag and not self .prevtag [0 ]:
83
- # begin a new block for <p> tags after a closed tag
84
- # avoid extra lines, e.g. after <pre> tags
84
+ # Begin a new block for <p> tags after a closed tag.
85
+ # Avoid extra lines, e.g. after <pre> tags.
85
86
lastline = self .text .get ('end-1c linestart' , 'end-1c' )
86
87
s = '\n \n ' if lastline and not lastline .isspace () else '\n '
87
88
elif tag == 'span' and class_ == 'pre' :
@@ -103,7 +104,7 @@ def handle_starttag(self, tag, attrs):
103
104
elif tag == 'li' :
104
105
s = '\n * ' if self .simplelist else '\n \n * '
105
106
elif tag == 'dt' :
106
- s = '\n \n ' if not self .nested_dl else '\n ' # avoid extra line
107
+ s = '\n \n ' if not self .nested_dl else '\n ' # Avoid extra line.
107
108
self .nested_dl = False
108
109
elif tag == 'dd' :
109
110
self .indent ()
@@ -129,12 +130,13 @@ def handle_starttag(self, tag, attrs):
129
130
def handle_endtag (self , tag ):
130
131
"Handle endtags in help.html."
131
132
if tag in ['h1' , 'h2' , 'h3' ]:
132
- self .indent ( 0 ) # clear tag, reset indent
133
+ assert self .level == 0
133
134
if self .show :
134
135
indent = (' ' if tag == 'h3' else
135
136
' ' if tag == 'h2' else
136
137
'' )
137
138
self .toc .append ((indent + self .header , self .text .index ('insert' )))
139
+ self .tags = ''
138
140
elif tag in ['span' , 'em' ]:
139
141
self .chartags = ''
140
142
elif tag == 'a' :
@@ -143,7 +145,7 @@ def handle_endtag(self, tag):
143
145
self .pre = False
144
146
self .tags = ''
145
147
elif tag in ['ul' , 'dd' , 'ol' ]:
146
- self .indent (amt = - 1 )
148
+ self .indent (- 1 )
147
149
self .prevtag = (False , tag )
148
150
149
151
def handle_data (self , data ):
@@ -169,7 +171,7 @@ def __init__(self, parent, filename):
169
171
"Configure tags and feed file to parser."
170
172
uwide = idleConf .GetOption ('main' , 'EditorWindow' , 'width' , type = 'int' )
171
173
uhigh = idleConf .GetOption ('main' , 'EditorWindow' , 'height' , type = 'int' )
172
- uhigh = 3 * uhigh // 4 # lines average 4/3 of editor line height
174
+ uhigh = 3 * uhigh // 4 # Lines average 4/3 of editor line height.
173
175
Text .__init__ (self , parent , wrap = 'word' , highlightthickness = 0 ,
174
176
padx = 5 , borderwidth = 0 , width = uwide , height = uhigh )
175
177
@@ -209,15 +211,14 @@ class HelpFrame(Frame):
209
211
"Display html text, scrollbar, and toc."
210
212
def __init__ (self , parent , filename ):
211
213
Frame .__init__ (self , parent )
212
- # keep references to widgets for test access.
213
214
self .text = text = HelpText (self , filename )
214
215
self ['background' ] = text ['background' ]
215
216
self .toc = toc = self .toc_menu (text )
216
217
self .scroll = scroll = Scrollbar (self , command = text .yview )
217
218
text ['yscrollcommand' ] = scroll .set
218
219
219
220
self .rowconfigure (0 , weight = 1 )
220
- self .columnconfigure (1 , weight = 1 ) # text
221
+ self .columnconfigure (1 , weight = 1 ) # Only expand the text widget.
221
222
toc .grid (row = 0 , column = 0 , sticky = 'nw' )
222
223
text .grid (row = 0 , column = 1 , sticky = 'nsew' )
223
224
scroll .grid (row = 0 , column = 2 , sticky = 'ns' )
@@ -279,7 +280,7 @@ def show_idlehelp(parent):
279
280
"Create HelpWindow; called from Idle Help event handler."
280
281
filename = join (abspath (dirname (__file__ )), 'help.html' )
281
282
if not isfile (filename ):
282
- # try copy_strip, present message
283
+ # Try copy_strip, present message.
283
284
return
284
285
HelpWindow (parent , filename , 'IDLE Help (%s)' % python_version ())
285
286
0 commit comments