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)
| 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"): |
no outgoing calls