@staticmethod
def escape(text, quote=True):
    """
        Returns a string with special characters converted to HTML entities.

        :param str text: The string with optionally special characters.
        :param bool quote: If true the quotation mark characters, both double quote (") and single quote (')
                           characters are also translated.

        :rtype: str
        """
    text = text.replace('&', '&amp;')
    text = text.replace('<', '&lt;')
    text = text.replace('>', '&gt;')
    if quote:
        text = text.replace('"', '&quot;')
        text = text.replace("'", '&#x27;')
    return text
