def nl2br(value): """nl2br(value : any) -> htmltext Insert <br /> tags before newline characters. """ text = htmlescape(value) return htmltext(text.s.replace('\n', '<br />\n'))
def htmltag(tag, xml_end=0, css_class=None, **attrs): """Create a HTML tag. """ r = ["<%s" % tag] if css_class is not None: attrs['class'] = css_class for (attr, val) in attrs.items(): if val is ValuelessAttr: val = attr if val is not None: r.append(' %s="%s"' % (attr, htmlescape(val))) if xml_end: r.append(" />") else: r.append(">") return htmltext("".join(r))
def htmltag(tag, xml_end=0, css_class=None, **attrs): """Create a HTML tag. """ r = ["<%s" % tag] if css_class is not None: attrs['class'] = css_class for (attr, val) in attrs.items(): if val is ValuelessAttr: val = attr if val is not None: r.append(' %s="%s"' % (attr, _escape_string(str(val)))) if xml_end: r.append(" />") else: r.append(">") return htmltext("".join(r))
def href(url, text, title=None, **attrs): return (htmltag("a", href=url, title=title, **attrs) + htmlescape(text) + htmltext("</a>"))