code: def repr_html(klass: type) -> type:
      """Decorator to inject a ``_repr_html_`` method in a given class. Will attempt to load the jinja
      template and render to html, else returns html. Passes ``self`` onto the jinja variable ``obj``
      on the template. Template should be under ``/ipython`` (see
      ``tslumen.misc.JINJA_FILE_SEARCHPATHS`` for the full list of search paths).
      """
      from jinja2 import TemplateNotFound, TemplateError
      from tslumen.jinja_utils import create_jinja_env
      import warnings
  
      def _repr_html(self: Any) -> str:
          try:
              env = create_jinja_env(
                  paths=None,
                  search_paths=JINJA_FILE_SEARCHPATHS,
                  pkg_path="templates/ipython",
                  check="_base.html",
              )
              template = env.get_template(
                  f"{klass.__module__}.{klass.__name__}.html"
              )
              rendered = template.render(obj=self, oid=hex(id(self)))
              return rendered
          except TemplateNotFound as e:
              warnings.warn(
                  f"could not find jinja template: {e}", UserWarning
              )
          except TemplateError as e:
              warnings.warn(f"jinja template error: {e}", UserWarning)
          except Exception as e:
              warnings.warn(f"Exception _repr_html_: {e}", UserWarning)
          return str(self)
  
      setattr(klass, "_repr_html_", _repr_html)
      return klass
  
imports: from typing import Any, Callable, Type
  from functools import wraps
label_desc: Use image node_id 2 for calling a global function with example usage: repr_html(klass) and returns: klass, str, rendered