def _format_document_link(href, title, link_text, host_or_filename):
    """Return a document link for the given components.

    Helper function for the .document_link property below.

    :returns: A document link as an HTML string, escaped and safe for
        rendering. The returned string is a Markup object so that it won't be
        double-escaped.

    """
    if href and host_or_filename and link_text in host_or_filename:
        host_or_filename = ""
    elif not href and title == host_or_filename:
        title = ""

    def truncate(content, length=55):
        """Truncate the given string to at most length chars."""
        if len(content) <= length:
            return content
        else:
            return content[:length] + jinja2.Markup("&hellip;")

    host_or_filename = truncate(host_or_filename)
    link_text = truncate(link_text)

    if href and host_or_filename:
        link = '<a href="{href}" title="{title}">{link_text}</a><br>{host_or_filename}'
    elif href:
        link = '<a href="{href}" title="{title}">{link_text}</a>'
    else:
        link = '<em>Local file:</em> {title}'
        if host_or_filename:
            link += '<br>{host_or_filename}'

    link = link.format(
        href=jinja2.escape(href),
        title=jinja2.escape(title),
        link_text=jinja2.escape(link_text),
        host_or_filename=jinja2.escape(host_or_filename))

    return jinja2.Markup(link)
dataset/ETHPy150Open hypothesis/h/h/presenters.py/_format_document_link/swapped operands of `in`