code: def path_to_url(self, url: str) -> str:
      scheme, netloc, path, query, anchor = urlsplit(url)
  
      absolute_link = None
      warning_level, warning = 0, ""
  
      # Ignore URLs unless they are a relative link to a source file.
      if scheme or netloc:  # External link.
          return url
      elif url.startswith(("/", "\\")):  # Absolute link.
          absolute_link = self.config.validation.links.absolute_links
          if (
              absolute_link
              is not _AbsoluteLinksValidationValue.RELATIVE_TO_DOCS
          ):
              warning_level = absolute_link
              warning = f"Doc file '{self.file.src_uri}' contains an absolute link '{url}', it was left as is."
      elif (
          AMP_SUBSTITUTE in url
      ):  # AMP_SUBSTITUTE is used internally by Markdown only for email.
          return url
      elif not path:  # Self-link containing only query or anchor.
          if anchor:
              # Register that the page links to itself with an anchor.
              self.links_to_anchors.setdefault(
                  self.file, {}
              ).setdefault(anchor, url)
          return url
  
      path = urlunquote(path)
      # Determine the filepath of the target.
      possible_target_uris = self._possible_target_uris(
          self.file, path, self.config.use_directory_urls
      )
  
      if warning:
          # For absolute path (already has a warning), the primary lookup path should be preserved as a tip option.
          target_uri = url
          target_file = None
      else:
          # Validate that the target exists in files collection.
          target_uri = next(possible_target_uris)
          target_file = self.files.get_file_from_path(target_uri)
  
      if target_file is None and not warning:
          # Primary lookup path had no match, definitely produce a warning, just choose which one.
          if not posixpath.splitext(path)[-1] and absolute_link is None:
              # No '.' in the last part of a path indicates path does not point to a file.
              warning_level = (
                  self.config.validation.links.unrecognized_links
              )
              warning = (
                  f"Doc file '{self.file.src_uri}' contains an unrecognized relative link '{url}', "
                  f"it was left as is."
              )
          else:
              target = (
                  f" '{target_uri}'"
                  if target_uri != url.lstrip("/")
                  else ""
              )
              warning_level = self.config.validation.links.not_found
              warning = (
                  f"Doc file '{self.file.src_uri}' contains a link '{url}', "
                  f"but the target{target} is not found among documentation files."
              )
  
      if warning:
          if self.file.inclusion.is_excluded():
              warning_level = min(logging.INFO, warning_level)
  
          # There was no match, so try to guess what other file could've been intended.
          if warning_level > logging.DEBUG:
              suggest_url = ""
              for path in possible_target_uris:
                  if self.files.get_file_from_path(path) is not None:
                      if anchor and path == self.file.src_uri:
                          path = ""
                      elif (
                          absolute_link
                          is _AbsoluteLinksValidationValue.RELATIVE_TO_DOCS
                      ):
                          path = "/" + path
                      else:
                          path = utils.get_relative_url(
                              path, self.file.src_uri
                          )
                      suggest_url = urlunsplit(
                          ("", "", path, query, anchor)
                      )
                      break
              else:
                  if "@" in url and "." in url and "/" not in url:
                      suggest_url = f"mailto:{url}"
              if suggest_url:
                  warning += f" Did you mean '{suggest_url}'?"
          log.log(warning_level, warning)
          return url
  
      assert target_uri is not None
      assert target_file is not None
  
      if anchor:
          # Register that this page links to the target file with an anchor.
          self.links_to_anchors.setdefault(target_file, {}).setdefault(
              anchor, url
          )
  
      if target_file.inclusion.is_excluded():
          if self.file.inclusion.is_excluded():
              warning_level = logging.DEBUG
          else:
              warning_level = min(
                  logging.INFO, self.config.validation.links.not_found
              )
          warning = (
              f"Doc file '{self.file.src_uri}' contains a link to "
              f"'{target_uri}' which is excluded from the built site."
          )
          log.log(warning_level, warning)
      path = utils.get_relative_url(target_file.url, self.file.url)
      return urlunsplit(("", "", path, query, anchor))
  
imports: from __future__ import annotations
  import copy
  import enum
  import logging
  import posixpath
  import warnings
  from typing import TYPE_CHECKING, Any, Callable, Iterator, MutableMapping, Sequence
  from urllib.parse import unquote
  from urllib.parse import urljoin, urlsplit, urlunsplit
  import markdown
  import markdown.htmlparser
  import markdown.postprocessors
  import markdown.treeprocessors
  from markdown.util import AMP_SUBSTITUTE
  from mkdocs import utils
  from mkdocs.structure import StructureItem
  from mkdocs.structure.toc import get_toc
  from mkdocs.utils import _removesuffix, get_build_date, get_markdown_title, meta, weak_property
label_desc: Use image node_id 5 for calling the _RelativePathTreeprocessor obj's underlying member method code with example usage: obj.path_to_url(url) and returns: urlunsplit, url, url, url, url