def do_meta(self, attrs): # CONTENT='...' is required; # at least one of HTTP-EQUIV=xyz or NAME=xyz is required. if not attrs.has_key("content") \ or not (attrs.has_key("http-equiv") or attrs.has_key("name")): self.badhtml = 1 return name = extract_keyword("name", attrs, conv=grailutil.conv_normstring) http_equiv = extract_keyword("http-equiv", attrs, conv=grailutil.conv_normstring) key = name or http_equiv if not key: self.badhtml = 1 return content = extract_keyword("content", attrs, conv=string.strip) item = (name, http_equiv, content) if self._metadata.has_key(key): self._metadata[key].append(item) else: entries = self._metadata[key] = [item] if key == "grail:parse-mode": content = grailutil.conv_normstring(content) strict = self.sgml_parser.strict_p() if content == "strict" and not strict: self.sgml_parser.restrict(0) self.context.message("Entered strict parsing mode on" " document request.") elif content == "forgiving" and strict: self.sgml_parser.restrict(1) self.context.message("Exited strict parsing mode on" " document request.")
def do_hr(self, attrs): if attrs.has_key('src') and self.app.load_images: align = extract_keyword('align', attrs, default='center', conv=lambda s,gu=grailutil: gu.conv_enumeration( gu.conv_normstring(s), ['left', 'center', 'right'])) self.implied_end_p() self.formatter.push_alignment(align) self.do_img({'border': '0', 'src': attrs['src']}) self.formatter.pop_alignment() self.formatter.add_line_break() return HTMLParser.do_hr(self, attrs) color = extract_keyword('color', attrs) rule = self.viewer.rules[-1] if attrs.has_key('noshade') and self.viewer.rules: if color: if not self.configcolor('background', color, widget=rule): self.configcolor('background', self.viewer.text['foreground'], widget=rule) else: # this color is known to work already rule.config(background=self.viewer.text['foreground']) rule.config(relief=FLAT) size = extract_keyword('size', attrs, 2, conv=grailutil.conv_integer) if size == 1: # could not actually set it to 1 unless it was flat; do it now: width = string.atoi(rule.cget('width')) rule.config(borderwidth=0, height=1, width=width+2) elif color: self.configcolor('background', color, widget=rule)
def do_isindex(parser, attrs): prompt = extract_keyword( 'prompt', attrs, "This is a searchable index. Enter search keywords:") IndexWidget( parser, prompt, (extract_keyword('href', attrs) or extract_keyword('action', attrs) or parser.context.get_baseurl()))
def do_isindex(parser, attrs): prompt = extract_keyword( 'prompt', attrs, "This is a searchable index. Enter search keywords:") IndexWidget(parser, prompt, (extract_keyword('href', attrs) or extract_keyword('action', attrs) or parser.context.get_baseurl()))
def start_a(self, attrs): if self.get_object(): # expensive! self.get_object().anchor(attrs) return name = type = target = title = '' id = None has_key = attrs.has_key # href = string.strip(attrs.get("urn", "")) scheme, resturl = urllib.splittype(href) if scheme == "urn": scheme, resturl = urllib.splittype(resturl) if scheme not in ("doi", "hdl", "ietf"): # this is an unknown URN scheme or there wasn't a URN href = string.strip(attrs.get("href", "")) name = extract_keyword('name', attrs, conv=grailutil.conv_normstring) if has_key('type'): type = string.lower(attrs['type'] or '') if has_key('target'): target = attrs['target'] if has_key('id'): id = attrs['id'] self.anchor_bgn(href, name, type, target, id) # Delay this at least a little, since we don't want to add the title # to the history until the last possible moment. We need a non-history # way to do this; a resources database would be much better. if has_key('title'): title = string.join(string.split(attrs['title'] or '')) if title: url = self.context.get_baseurl( string.joinfields(string.split(href), '')) old_title, when = self.app.global_history.lookup_url(url) if not old_title: # Only do this if there's not already a title in the # history. If the URL wasn't in the history, it will # be given a timestamp, which is bad. ;-( self.app.global_history.set_title(url, title)
def header_bgn(self, tag, level, attrs): HTMLParser.header_bgn(self, tag, level, attrs) dingbat = extract_keyword('dingbat', attrs) if dingbat: self.unknown_entityref(dingbat, '') self.formatter.add_flowing_data(' ') elif attrs.has_key('src'): self.do_img(attrs) self.formatter.add_flowing_data(' ')
def do_col(self, parser, attrs): ti = self._lasttable if ti: span = grailutil.extract_keyword('span', attrs, default=1, conv=grailutil.conv_integer) if span < 1: span = 1 # if = 0, ignore. Not quite right... while span: span = span - 1 if ti.colgroups: last_colgroup = ti.colgroups[-1] col = Col(attrs, last_colgroup) else: col = Col(attrs) ti.cols.append(col)
def start_body(self, attrs): HTMLParser.start_body(self, attrs) if not self.app.prefs.GetBoolean('parsing-html', 'honor-colors'): return from grailutil import conv_normstring bgcolor = extract_keyword('bgcolor', attrs, conv=conv_normstring) if bgcolor: clr = self.configcolor('background', bgcolor) if clr: # Normally not important, but ISINDEX would cause # these to be non-empty, as would all sorts of illegal stuff: for hr in self.viewer.rules + self.viewer.subwindows: hr.config(highlightbackground=clr) self.configcolor('foreground', extract_keyword('text', attrs, conv=conv_normstring)) self.configcolor('foreground', extract_keyword('link', attrs, conv=conv_normstring), 'a') self.configcolor('foreground', extract_keyword('vlink', attrs, conv=conv_normstring), 'ahist') self.configcolor('foreground', extract_keyword('alink', attrs, conv=conv_normstring), 'atemp')
def start_body(self, attrs): HTMLParser.start_body(self, attrs) if not self.app.prefs.GetBoolean('parsing-html', 'honor-colors'): return from grailutil import conv_normstring bgcolor = extract_keyword('bgcolor', attrs, conv=conv_normstring) if bgcolor: clr = self.configcolor('background', bgcolor) if clr: # Normally not important, but ISINDEX would cause # these to be non-empty, as would all sorts of illegal stuff: for hr in self.viewer.rules + self.viewer.subwindows: hr.config(highlightbackground = clr) self.configcolor('foreground', extract_keyword('text', attrs, conv=conv_normstring)) self.configcolor('foreground', extract_keyword('link', attrs, conv=conv_normstring), 'a') self.configcolor('foreground', extract_keyword('vlink', attrs, conv=conv_normstring), 'ahist') self.configcolor('foreground', extract_keyword('alink', attrs, conv=conv_normstring), 'atemp')