MCPcopy Index your code
hub / github.com/python/cpython / handle_starttag

Method handle_starttag

Lib/idlelib/help.py:77–126  ·  view source on GitHub ↗

Handle starttags in help.html.

(self, tag, attrs)

Source from the content-addressed store, hash-verified

75 self.tags = '' if self.level == 0 else 'l'+str(self.level)
76
77 def handle_starttag(self, tag, attrs):
78 "Handle starttags in help.html."
79 class_ = ''
80 for a, v in attrs:
81 if a == 'class':
82 class_ = v
83 s = ''
84 if tag == 'p' and self.prevtag and not self.prevtag[0]:
85 # Begin a new block for <p> tags after a closed tag.
86 # Avoid extra lines, e.g. after <pre> tags.
87 lastline = self.text.get('end-1c linestart', 'end-1c')
88 s = '\n\n' if lastline and not lastline.isspace() else '\n'
89 elif tag == 'span' and class_ == 'pre':
90 self.chartags = 'pre'
91 elif tag == 'span' and class_ == 'versionmodified':
92 self.chartags = 'em'
93 elif tag == 'em':
94 self.chartags = 'em'
95 elif tag in ['ul', 'ol']:
96 if class_.find('simple') != -1:
97 s = '\n'
98 self.simplelist = True
99 else:
100 self.simplelist = False
101 self.indent()
102 elif tag == 'dl':
103 if self.level > 0:
104 self.nested_dl = True
105 elif tag == 'li':
106 s = '\n* '
107 elif tag == 'dt':
108 s = '\n\n' if not self.nested_dl else '\n' # Avoid extra line.
109 self.nested_dl = False
110 elif tag == 'dd':
111 self.indent()
112 s = '\n'
113 elif tag == 'pre':
114 self.pre = True
115 self.text.insert('end', '\n\n')
116 self.tags = 'preblock'
117 elif tag == 'a' and class_ == 'headerlink':
118 self.hdrlink = True
119 elif tag == 'h1':
120 self.tags = tag
121 elif tag in ['h2', 'h3']:
122 self.header = ''
123 self.text.insert('end', '\n\n')
124 self.tags = tag
125 self.text.insert('end', s, (self.tags, self.chartags))
126 self.prevtag = (True, tag)
127
128 def handle_endtag(self, tag):
129 "Handle endtags in help.html."

Callers

nothing calls this directly

Calls 5

indentMethod · 0.95
isspaceMethod · 0.80
getMethod · 0.45
findMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected