def render(self): rendered_children = [child.render() for child in self.children] return '<{tag}{attrs}>{children}{closing_tag}'.format( tag = html_escape(self.tag), attrs = self._render_attrs(), children=''.join(rendered_children), closing_tag = '' if self.tag in _singleton_tags else '</{0}>'.format(self.tag) )
def advisory_escape_html(advisory): start = '\nWorkaround\n==========\n\n' end = '\n\nReferences\n==========\n\n' if start not in advisory or end not in advisory: return None start_index = advisory.index(start) + len(start) end_index = advisory.index(end) advisory = advisory[:start_index] + str( html_escape(advisory[start_index:end_index])) + advisory[end_index:] return advisory
def _render_attrs(self): strings = [] for k, v in self.attrs.items(): if v is None: continue # e.g. class_ => class, data_foo => data-foo k = k.rstrip('_').replace('_', '-') if k in _boolean_attrs: if v: strings.append(k) else: if k == 'class': v = _render_val_for_class_attr(v) strings.append('%s="%s"' % (html_escape(k), html_escape(v))) return '' if len(strings) == 0 else ' ' + ' '.join(strings)
def linkfy(text, escape=True, **attributes): html = HTMLBuilder() words = [] skip_parts = 0 for w in url_schema.split(text): if skip_parts: skip_parts -= 1 continue search = url_schema.search(w) if search and search.group('url') == w: t = str(html.a(href=w, body=w, **attributes)) skip_parts = 7 elif escape: t = html_escape(w) else: t = w words.append(t) return ''.join(words)
def render(self, container_id='flash', use_js=False, container_class='', *args, **kwargs): payload = self.pop_payload(request, response) if not payload: return '' if isinstance(payload, dict): payload = [payload] r = [] for i, p in enumerate(payload): p['i'] = i if 'no_escape' in p: p['message'] = p.get('message', '') else: p['message'] = html_escape(p.get('message', '')) vars = copy_and_call(self.message_vars, p) vars.update(p) r.append(self.message_template % vars) return self.container_template % { 'container_id': container_id, 'container_class': container_class, 'content': '\n'.join(r)}
def render(self): return html_escape(self.val)