MCPcopy
hub / github.com/caronc/apprise / escape_html

Method escape_html

apprise/url.py:552–577  ·  view source on GitHub ↗

Takes html text as input and escapes it so that it won't conflict with any xml/html wrapping characters. Args: html (str): The HTML code to escape convert_new_lines (:obj:`bool`, optional): escape new lines (\n) whitespace (:obj:`bool`, optional):

(html, convert_new_lines=False, whitespace=True)

Source from the content-addressed store, hash-verified

550
551 @staticmethod
552 def escape_html(html, convert_new_lines=False, whitespace=True):
553 """Takes html text as input and escapes it so that it won't conflict
554 with any xml/html wrapping characters.
555
556 Args:
557 html (str): The HTML code to escape
558 convert_new_lines (:obj:`bool`, optional): escape new lines (\n)
559 whitespace (:obj:`bool`, optional): escape whitespace
560
561 Returns:
562 str: The escaped html
563 """
564 if not isinstance(html, str) or not html:
565 return ""
566
567 # Escape HTML
568 escaped = sax_escape(html, {"'": "'", '"': """})
569
570 if whitespace:
571 # Tidy up whitespace too
572 escaped = escaped.replace("\t", " ").replace(" ", " ")
573
574 if convert_new_lines:
575 return escaped.replace("\n", "<br/>")
576
577 return escaped
578
579 @staticmethod
580 def unquote(content, encoding="utf-8", errors="replace"):

Callers 8

test_notify_baseFunction · 0.80
text_to_htmlFunction · 0.80
sendMethod · 0.80
sendMethod · 0.80
_e2ee_send_to_roomMethod · 0.80

Calls

no outgoing calls

Tested by 1

test_notify_baseFunction · 0.64