summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTerry Jan Reedy <tjreedy@udel.edu>2015-09-24 21:31:54 (GMT)
committerTerry Jan Reedy <tjreedy@udel.edu>2015-09-24 21:31:54 (GMT)
commit49095e238078d4d41835c7b092a159a40b7017f3 (patch)
treeaa8f924b56884fe92ca47f13f20844522ad638fe /Lib
parent7cca4e5ba2ccdbbf2b58a030ff4160e15bfc5f23 (diff)
downloadcpython-49095e238078d4d41835c7b092a159a40b7017f3.zip
cpython-49095e238078d4d41835c7b092a159a40b7017f3.tar.gz
cpython-49095e238078d4d41835c7b092a159a40b7017f3.tar.bz2
Issue #25198: In Idle doc viewer, fix indent of fixed-pitch <pre> text
by adding a new tag. Patch by Mark Roseman. Also give <pre> text a very light blueish-gray background similar to that used by Sphinx html.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/idlelib/help.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/Lib/idlelib/help.py b/Lib/idlelib/help.py
index fa5cdc4..c146db4 100644
--- a/Lib/idlelib/help.py
+++ b/Lib/idlelib/help.py
@@ -48,7 +48,8 @@ class HelpParser(HTMLParser):
def __init__(self, text):
HTMLParser.__init__(self)
self.text = text # text widget we're rendering into
- self.tags = '' # current text tags to apply
+ 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
@@ -78,11 +79,11 @@ class HelpParser(HTMLParser):
elif tag == 'p' and class_ != 'first':
s = '\n\n'
elif tag == 'span' and class_ == 'pre':
- self.tags = 'pre'
+ self.chartags = 'pre'
elif tag == 'span' and class_ == 'versionmodified':
- self.tags = 'em'
+ self.chartags = 'em'
elif tag == 'em':
- self.tags = 'em'
+ self.chartags = 'em'
elif tag in ['ul', 'ol']:
if class_.find('simple') != -1:
s = '\n'
@@ -120,16 +121,18 @@ class HelpParser(HTMLParser):
self.text.insert('end', '\n\n')
self.tags = tag
if self.show:
- self.text.insert('end', s, self.tags)
+ self.text.insert('end', s, (self.tags, self.chartags))
def handle_endtag(self, tag):
"Handle endtags in help.html."
- if tag in ['h1', 'h2', 'h3', 'span', 'em']:
+ if tag in ['h1', 'h2', 'h3']:
self.indent(0) # clear tag, reset indent
if self.show and tag in ['h1', 'h2', 'h3']:
title = self.data
self.contents.append(('toc'+str(self.tocid), title))
self.tocid += 1
+ elif tag in ['span', 'em']:
+ self.chartags = ''
elif tag == 'a':
self.hdrlink = False
elif tag == 'pre':
@@ -148,7 +151,7 @@ class HelpParser(HTMLParser):
if d[0:len(self.hprefix)] == self.hprefix:
d = d[len(self.hprefix):].strip()
self.data += d
- self.text.insert('end', d, self.tags)
+ self.text.insert('end', d, (self.tags, self.chartags))
def handle_charref(self, name):
self.text.insert('end', unichr(int(name)))
@@ -168,7 +171,7 @@ class HelpText(Text):
self.tag_configure('h1', font=(normalfont, 20, 'bold'))
self.tag_configure('h2', font=(normalfont, 18, 'bold'))
self.tag_configure('h3', font=(normalfont, 15, 'bold'))
- self.tag_configure('pre', font=(fixedfont, 12))
+ self.tag_configure('pre', font=(fixedfont, 12), background='#f6f6ff')
self.tag_configure('preblock', font=(fixedfont, 10), lmargin1=25,
borderwidth=1, relief='solid', background='#eeffcc')
self.tag_configure('l1', lmargin1=25, lmargin2=25)