@@ -50,21 +50,22 @@ class HelpParser(HTMLParser):
5050 """
5151 def __init__ (self , text ):
5252 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).
6666
6767 def indent (self , amt = 1 ):
68+ "Change indent (+1, 0, -1) and tags."
6869 self .level += amt
6970 self .tags = '' if self .level == 0 else 'l' + str (self .level )
7071
@@ -76,12 +77,12 @@ def handle_starttag(self, tag, attrs):
7677 class_ = v
7778 s = ''
7879 if tag == 'div' and class_ == 'section' :
79- self .show = True # start of main content
80+ self .show = True # Start main content.
8081 elif tag == 'div' and class_ == 'sphinxsidebar' :
81- self .show = False # end of main content
82+ self .show = False # End main content.
8283 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.
8586 lastline = self .text .get ('end-1c linestart' , 'end-1c' )
8687 s = '\n \n ' if lastline and not lastline .isspace () else '\n '
8788 elif tag == 'span' and class_ == 'pre' :
@@ -103,7 +104,7 @@ def handle_starttag(self, tag, attrs):
103104 elif tag == 'li' :
104105 s = '\n * ' if self .simplelist else '\n \n * '
105106 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.
107108 self .nested_dl = False
108109 elif tag == 'dd' :
109110 self .indent ()
@@ -129,12 +130,13 @@ def handle_starttag(self, tag, attrs):
129130 def handle_endtag (self , tag ):
130131 "Handle endtags in help.html."
131132 if tag in ['h1' , 'h2' , 'h3' ]:
132- self .indent ( 0 ) # clear tag, reset indent
133+ assert self .level == 0
133134 if self .show :
134135 indent = (' ' if tag == 'h3' else
135136 ' ' if tag == 'h2' else
136137 '' )
137138 self .toc .append ((indent + self .header , self .text .index ('insert' )))
139+ self .tags = ''
138140 elif tag in ['span' , 'em' ]:
139141 self .chartags = ''
140142 elif tag == 'a' :
@@ -143,7 +145,7 @@ def handle_endtag(self, tag):
143145 self .pre = False
144146 self .tags = ''
145147 elif tag in ['ul' , 'dd' , 'ol' ]:
146- self .indent (amt = - 1 )
148+ self .indent (- 1 )
147149 self .prevtag = (False , tag )
148150
149151 def handle_data (self , data ):
@@ -169,7 +171,7 @@ def __init__(self, parent, filename):
169171 "Configure tags and feed file to parser."
170172 uwide = idleConf .GetOption ('main' , 'EditorWindow' , 'width' , type = 'int' )
171173 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.
173175 Text .__init__ (self , parent , wrap = 'word' , highlightthickness = 0 ,
174176 padx = 5 , borderwidth = 0 , width = uwide , height = uhigh )
175177
@@ -209,15 +211,14 @@ class HelpFrame(Frame):
209211 "Display html text, scrollbar, and toc."
210212 def __init__ (self , parent , filename ):
211213 Frame .__init__ (self , parent )
212- # keep references to widgets for test access.
213214 self .text = text = HelpText (self , filename )
214215 self ['background' ] = text ['background' ]
215216 self .toc = toc = self .toc_menu (text )
216217 self .scroll = scroll = Scrollbar (self , command = text .yview )
217218 text ['yscrollcommand' ] = scroll .set
218219
219220 self .rowconfigure (0 , weight = 1 )
220- self .columnconfigure (1 , weight = 1 ) # text
221+ self .columnconfigure (1 , weight = 1 ) # Only expand the text widget.
221222 toc .grid (row = 0 , column = 0 , sticky = 'nw' )
222223 text .grid (row = 0 , column = 1 , sticky = 'nsew' )
223224 scroll .grid (row = 0 , column = 2 , sticky = 'ns' )
@@ -279,7 +280,7 @@ def show_idlehelp(parent):
279280 "Create HelpWindow; called from Idle Help event handler."
280281 filename = join (abspath (dirname (__file__ )), 'help.html' )
281282 if not isfile (filename ):
282- # try copy_strip, present message
283+ # Try copy_strip, present message.
283284 return
284285 HelpWindow (parent , filename , 'IDLE Help (%s)' % python_version ())
285286
0 commit comments