code: def get_location(node, app):
      """
      Given a docutils node and a sphinx application, return a string
      representation of the source location of this node.
  
      Usually, this will be of the form "path/to/file:linenumber". Two
      special values can be emitted, "<external>" for paths which are
      not contained in this source tree (e.g. docstrings included from
      other modules) or "<unknown>", indicating that the sphinx application
      cannot locate the original source file (usually because an extension
      has injected text into the sphinx parsing engine).
      """
      source, line = get_source_line(node)
  
      if source:
          # 'source' can have the form '/some/path:docstring of some.api' but the
          # colons are forbidden on windows, but on posix just passes through.
          if ":docstring of" in source:
              path, *post = source.rpartition(":docstring of")
              post = "".join(post)
          else:
              path = source
              post = ""
          # We locate references relative to the parent of the doc
          # directory, which for matplotlib, will be the root of the
          # matplotlib repo. When matplotlib is not an editable install
          # weird things will happen, but we can't totally recover from
          # that.
          basepath = Path(app.srcdir).parent.resolve()
  
          fullpath = Path(path).resolve()
  
          try:
              path = fullpath.relative_to(basepath)
          except ValueError:
              # Sometimes docs directly contain e.g. docstrings
              # from installed modules, and we record those as
              # <external> so as to be independent of where the
              # module was installed
              path = Path("<external>") / fullpath.name
  
          # Ensure that all reported paths are POSIX so that docs
          # on windows result in the same warnings in the JSON file.
          path = path.as_posix()
  
      else:
          path = "<unknown>"
          post = ""
      if not line:
          line = ""
  
      return f"{path}{post}:{line}"
  
imports: from collections import defaultdict
  import json
  import logging
  from pathlib import Path
  from docutils.utils import get_source_line
  from docutils import nodes
  from sphinx.util import logging
  import matplotlib
label_desc: Use image node_id 3 for calling a global function with example usage: get_location(node, app) and returns: path, post, str, line