Ejemplo n.º 1
0
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(" ", "&nbsp;")
        got.append(nonurl)

        if urlmatch:
            url = line[curstart:curend]
            got.append('<a href="%s">%s</a>' % (url, url))

        cursor = curend

    return "".join(got)
Ejemplo n.º 2
0
Archivo: util.py Proyecto: goschtl/zope
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(" ", "&nbsp;")
        got.append(nonurl)

        if urlmatch:
            url = line[curstart:curend]
            got.append('<a href="%s">%s</a>' % (url, url))

        cursor = curend

    return "".join(got)