code: def escape(
      markup: str,
      _escape: _EscapeSubMethod = re.compile(
          r"(\\*)(\[[a-z#/@][^[]*?])"
      ).sub,
  ) -> str:
      """Escapes text so that it won't be interpreted as markup.
  
      Args:
          markup (str): Content to be inserted in to markup.
  
      Returns:
          str: Markup with square brackets escaped.
      """
  
      def escape_backslashes(match: Match[str]) -> str:
          """Called by re.sub replace matches."""
          backslashes, text = match.groups()
          return f"{backslashes}{backslashes}\\{text}"
  
      markup = _escape(escape_backslashes, markup)
      if markup.endswith("\\") and not markup.endswith("\\\\"):
          return markup + "\\"
  
      return markup
  
file_path: rich/rich/markup.py
imports: import re
  from ast import literal_eval
  from operator import attrgetter
  from typing import Callable, Iterable, List, Match, NamedTuple, Optional, Tuple, Union
  from ._emoji_replace import _emoji_replace
  from .emoji import EmojiVariant
  from .errors import MarkupError
  from .style import Style
  from .text import Span, Text
label_desc: Use image node_id 1 for calling a global function with example usage: escape(markup, _escape) and returns: markup, backslashes, backslashes, str, text, unknown