code: def _escape_cdata(text) -> str:
      # escape character data
      try:
          # it's worth avoiding do-nothing calls for strings that are
          # shorter than 500 character, or so.  assume that's, by far,
          # the most common case in most applications.
          if "&" in text:
              # Only replace & when not part of an entity
              text = RE_AMP.sub("&amp;", text)
          if "<" in text:
              text = text.replace("<", "&lt;")
          if ">" in text:
              text = text.replace(">", "&gt;")
          return text
      except (TypeError, AttributeError):  # pragma: no cover
          _raise_serialization_error(text)
  
file_path: markdown/markdown/serializers.py
imports: from __future__ import annotations
  from xml.etree.ElementTree import ProcessingInstruction
  from xml.etree.ElementTree import Comment, ElementTree, Element, QName, HTML_EMPTY
  import re
  from typing import Callable, Literal, NoReturn
label_desc: Use image node_id 2 for calling a global function with example usage: _escape_cdata(text) and returns: text