def escape(string, quote=True):
    """Returns a string where HTML metacharacters are properly escaped.

    Compatibility layer to avoid incompatibilities between Python versions,
    Qt versions and Qt bindings.

    >>> import silx.utils.html
    >>> silx.utils.html.escape("<html>")
    >>> "&lt;html&gt;"

    .. note:: Since Python 3.3 you can use the `html` module. For previous
        version, it is provided by `sgi` module.
    .. note:: Qt4 provides it with `Qt.escape` while Qt5 provide it with
        `QString.toHtmlEscaped`. But `QString` is not exposed by `PyQt` or
        `PySide`.

    :param str string: Human readable string.
    :param bool quote: Escape quote and double quotes (default behaviour).
    :returns: Valid HTML syntax to display the input string.
    :rtype: str
    """
    string = string.replace('&', '&amp;')
    string = string.replace('<', '&lt;')
    string = string.replace('>', '&gt;')
    if quote:
        string = string.replace("'", '&apos;')
        string = string.replace('"', '&quot;')
    return string
