def _webtext_format_line(line, do_html_quote=1, do_links=1, do_whitespace=0): """ Turn URLs into links, and html_quote everything else.""" if do_links: urlmatches = list_search_hits(line, urlexp) else: urlmatches = [] got = [] cursor = 0 lenline = len(line) while cursor < lenline: if urlmatches: urlmatch = urlmatches.pop(0) curstart, curend = urlmatch.start(), urlmatch.end() else: urlmatch = None curstart = curend = lenline nonurl = line[cursor:curstart] if do_html_quote: nonurl = html_quote(nonurl) if do_whitespace: nonurl = nonurl.replace(" ", " ") got.append(nonurl) if urlmatch: url = line[curstart:curend] got.append('<a href="%s">%s</a>' % (url, url)) cursor = curend return "".join(got)