Skip to content

Commit

Permalink
Fix idlelib.help comments (pythonGH-15669)
Browse files Browse the repository at this point in the history
  • Loading branch information
terryjreedy authored and lisroach committed Sep 9, 2019
1 parent 647d99d commit cf72635
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions Lib/idlelib/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,22 @@ class HelpParser(HTMLParser):
"""
def __init__(self, text):
HTMLParser.__init__(self, convert_charrefs=True)
self.text = text # text widget we're rendering into
self.tags = '' # current block level text tags to apply
self.chartags = '' # current character level text tags
self.show = False # used so we exclude page navigation
self.hdrlink = False # used so we don't show header links
self.level = 0 # indentation level
self.pre = False # displaying preformatted text
self.hprefix = '' # prefix such as '25.5' to strip from headings
self.nested_dl = False # if we're in a nested <dl>
self.simplelist = False # simple list (no double spacing)
self.toc = [] # pair headers with text indexes for toc
self.header = '' # text within header tags for toc
self.prevtag = None # info about previous tag (was opener, tag)
self.text = text # Text widget we're rendering into.
self.tags = '' # Current block level text tags to apply.
self.chartags = '' # Current character level text tags.
self.show = False # Exclude html page navigation.
self.hdrlink = False # Exclude html header links.
self.level = 0 # Track indentation level.
self.pre = False # Displaying preformatted text?
self.hprefix = '' # Heading prefix (like '25.5'?) to remove.
self.nested_dl = False # In a nested <dl>?
self.simplelist = False # In a simple list (no double spacing)?
self.toc = [] # Pair headers with text indexes for toc.
self.header = '' # Text within header tags for toc.
self.prevtag = None # Previous tag info (opener?, tag).

def indent(self, amt=1):
"Change indent (+1, 0, -1) and tags."
self.level += amt
self.tags = '' if self.level == 0 else 'l'+str(self.level)

Expand All @@ -76,12 +77,12 @@ def handle_starttag(self, tag, attrs):
class_ = v
s = ''
if tag == 'div' and class_ == 'section':
self.show = True # start of main content
self.show = True # Start main content.
elif tag == 'div' and class_ == 'sphinxsidebar':
self.show = False # end of main content
self.show = False # End main content.
elif tag == 'p' and self.prevtag and not self.prevtag[0]:
# begin a new block for <p> tags after a closed tag
# avoid extra lines, e.g. after <pre> tags
# Begin a new block for <p> tags after a closed tag.
# Avoid extra lines, e.g. after <pre> tags.
lastline = self.text.get('end-1c linestart', 'end-1c')
s = '\n\n' if lastline and not lastline.isspace() else '\n'
elif tag == 'span' and class_ == 'pre':
Expand All @@ -103,7 +104,7 @@ def handle_starttag(self, tag, attrs):
elif tag == 'li':
s = '\n* ' if self.simplelist else '\n\n* '
elif tag == 'dt':
s = '\n\n' if not self.nested_dl else '\n' # avoid extra line
s = '\n\n' if not self.nested_dl else '\n' # Avoid extra line.
self.nested_dl = False
elif tag == 'dd':
self.indent()
Expand All @@ -129,12 +130,13 @@ def handle_starttag(self, tag, attrs):
def handle_endtag(self, tag):
"Handle endtags in help.html."
if tag in ['h1', 'h2', 'h3']:
self.indent(0) # clear tag, reset indent
assert self.level == 0
if self.show:
indent = (' ' if tag == 'h3' else
' ' if tag == 'h2' else
'')
self.toc.append((indent+self.header, self.text.index('insert')))
self.tags = ''
elif tag in ['span', 'em']:
self.chartags = ''
elif tag == 'a':
Expand All @@ -143,7 +145,7 @@ def handle_endtag(self, tag):
self.pre = False
self.tags = ''
elif tag in ['ul', 'dd', 'ol']:
self.indent(amt=-1)
self.indent(-1)
self.prevtag = (False, tag)

def handle_data(self, data):
Expand All @@ -169,7 +171,7 @@ def __init__(self, parent, filename):
"Configure tags and feed file to parser."
uwide = idleConf.GetOption('main', 'EditorWindow', 'width', type='int')
uhigh = idleConf.GetOption('main', 'EditorWindow', 'height', type='int')
uhigh = 3 * uhigh // 4 # lines average 4/3 of editor line height
uhigh = 3 * uhigh // 4 # Lines average 4/3 of editor line height.
Text.__init__(self, parent, wrap='word', highlightthickness=0,
padx=5, borderwidth=0, width=uwide, height=uhigh)

Expand Down Expand Up @@ -209,15 +211,14 @@ class HelpFrame(Frame):
"Display html text, scrollbar, and toc."
def __init__(self, parent, filename):
Frame.__init__(self, parent)
# keep references to widgets for test access.
self.text = text = HelpText(self, filename)
self['background'] = text['background']
self.toc = toc = self.toc_menu(text)
self.scroll = scroll = Scrollbar(self, command=text.yview)
text['yscrollcommand'] = scroll.set

self.rowconfigure(0, weight=1)
self.columnconfigure(1, weight=1) # text
self.columnconfigure(1, weight=1) # Only expand the text widget.
toc.grid(row=0, column=0, sticky='nw')
text.grid(row=0, column=1, sticky='nsew')
scroll.grid(row=0, column=2, sticky='ns')
Expand Down Expand Up @@ -279,7 +280,7 @@ def show_idlehelp(parent):
"Create HelpWindow; called from Idle Help event handler."
filename = join(abspath(dirname(__file__)), 'help.html')
if not isfile(filename):
# try copy_strip, present message
# Try copy_strip, present message.
return
HelpWindow(parent, filename, 'IDLE Help (%s)' % python_version())

Expand Down

0 comments on commit cf72635

Please sign in to comment.