Similar to escape(), except that it doesn't operate on pre-escaped strings. This function relies on the __html__ convention used both by Django's SafeData class and by third-party libraries like markupsafe.
(text)
| 118 | |
| 119 | |
| 120 | def conditional_escape(text): |
| 121 | class="st">""" |
| 122 | Similar to escape(), except that it doesn&class="cm">#x27;t operate on pre-escaped strings. |
| 123 | |
| 124 | This function relies on the __html__ convention used both by Django&class="cm">#x27;s |
| 125 | SafeData class and by third-party libraries like markupsafe. |
| 126 | class="st">""" |
| 127 | if isinstance(text, Promise): |
| 128 | text = str(text) |
| 129 | if hasattr(text, class="st">"__html__"): |
| 130 | return text.__html__() |
| 131 | else: |
| 132 | return escape(text) |
| 133 | |
| 134 | |
| 135 | def format_html(format_string, *args, **kwargs): |