MCPcopy Index your code
hub / github.com/clips/pattern / encode_entities

Function encode_entities

pattern/db/__init__.py:236–247  ·  view source on GitHub ↗

Encodes HTML entities in the given string ("<" => "&lt;"). For example, to display " hello " in a browser, we need to pass "&lt;em&gt;hello&lt;/em&gt;" (otherwise "hello" in italic is displayed).

(string)

Source from the content-addressed store, hash-verified

234RE_UNICODE = re.compile(r'&(#?)(x|X?)(\w+);') # &#201;
235
236def encode_entities(string):
237 """ Encodes HTML entities in the given string ("<" => "&lt;").
238 For example, to display "<em>hello</em>" in a browser,
239 we need to pass "&lt;em&gt;hello&lt;/em&gt;" (otherwise "hello" in italic is displayed).
240 """
241 if isinstance(string, (str, unicode)):
242 string = RE_AMPERSAND.sub("&amp;", string)
243 string = string.replace("<", "&lt;")
244 string = string.replace(">", "&gt;")
245 string = string.replace('"', "&quot;")
246 string = string.replace("'", "&#39;")
247 return string
248
249def decode_entities(string):
250 """ Decodes HTML entities in the given string ("&lt;" => "<").

Callers 4

xml_formatFunction · 0.70
xmlFunction · 0.70
tagsMethod · 0.50
__repr__Method · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…