html

Utils function relative to HTML

escape(string, quote=True)[source]

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.

Parameters:
  • string (str) – Human readable string.
  • quote (bool) – Escape quote and double quotes (default behaviour).
Returns:

Valid HTML syntax to display the input string.

Return type:

str