code: def _str_escape(x, escape):
      """if escaping: only use on str, else return input"""
      if isinstance(x, str):
          if escape == "html":
              return escape_html(x)
          elif escape == "latex":
              return _escape_latex(x)
          elif escape == "latex-math":
              return _escape_latex_math(x)
          else:
              raise ValueError(
                  f"`escape` only permitted in {{'html', 'latex', 'latex-math'}}, \
  got {escape}"
              )
      return x
  
imports: from __future__ import annotations
  from collections import defaultdict
  from collections.abc import Sequence
  from functools import partial
  import re
  from typing import TYPE_CHECKING, Any, Callable, DefaultDict, Optional, TypedDict, Union
  from uuid import uuid4
  import numpy
  from pandas._config import get_option
  from pandas._libs import lib
  from pandas.compat._optional import import_optional_dependency
  from pandas.core.dtypes.common import is_complex, is_float, is_integer
  from pandas.core.dtypes.generic import ABCSeries
  from pandas import DataFrame, Index, IndexSlice, MultiIndex, Series, isna
  from pandas.api.types import is_list_like
  import pandas.core.common
  from markupsafe import escape
label_desc: Use image node_id 8 for calling a global function with example usage: _str_escape(x, escape) and returns: x, escape_html, _escape_latex, _escape_latex_math