docstr: Rewrite deep links to the Read the Docs documentation to point to the relevant page in this
  build.
  
  Having full URLs is good when viewing the docs without rendering, such as with `help(...)`
  or `?...`, but internal links make for a more consistent experience (no jumping from
  .../1.2/ or .../latest/ to .../stable/) as well as allowing checks for validity. The
  rewriting done here gives the best of both worlds: full URLs without rendering, internal
  links within Sphinx.
docstr_tok: ["Rewrite","deep","links","to","the","Read","the","Docs","documentation","to","point","to","the","relevant","page","in","this","build",".","Having","full","URLs","is","good","when","viewing","the","docs","without","rendering",",","such","as","with","`","help","(","...",")","`","or","`","?","...","`",",","but","internal","links","make","for","a","more","consistent","experience","(","no","jumping","from","...","\/1.2\/","or","...","\/latest\/","to","...","\/stable\/",")","as","well","as","allowing","checks","for","validity",".","The","rewriting","done","here","gives","the","best","of","both","worlds",":","full","URLs","without","rendering",",","internal","links","within","Sphinx","."]
code: def _rewrite_rtd_link(self, node, refuri, parsed):
      """
      Rewrite deep links to the Read the Docs documentation to point to the relevant page in this
      build.
  
      Having full URLs is good when viewing the docs without rendering, such as with `help(...)`
      or `?...`, but internal links make for a more consistent experience (no jumping from
      .../1.2/ or .../latest/ to .../stable/) as well as allowing checks for validity. The
      rewriting done here gives the best of both worlds: full URLs without rendering, internal
      links within Sphinx.
      """
      env = self.document.settings.env
      match = self.RTD_PATH_RE.match(parsed.path)
      if not match:
          return
  
      lang = match["lang"]
      version = match["version"]
      rest = match["rest"]
      fragment = parsed.fragment
  
      # validate that the links all have the same basic structure:
      if (
          lang != "en"
          or version != "stable"
          or not rest.endswith(".html")
      ):
          self.document.reporter.warning(
              f"Links to stellargraph.readthedocs.io should always be to the stable english form <https://stellargraph.readthedocs.io/en/stable/...> and have the path end with a .html file extension, found language {lang!r}, version {version!r} and path ending with {rest[-8:]!r} in <{refuri}>"
          )
          return
  
      if rest == "api.html" and fragment:
          # a link to a Python element in the API: infer which one from the fragment. Examples:
          # - https://stellargraph.readthedocs.io/en/stable/api.html#module-stellargraph
          # - https://stellargraph.readthedocs.io/en/stable/api.html#stellargraph.StellarGraph
          # - https://stellargraph.readthedocs.io/en/stable/api.html#stellargraph.StellarGraph.to_networkx
          new_domain = "py"
  
          module_prefix = "module-"
          if fragment.startswith(module_prefix):
              new_type = "mod"
              new_target = fragment[len(module_prefix) :]
          else:
              new_type = "any"
              new_target = fragment
      else:
          # a link to a file (e.g. a demo)
          if fragment:
              self.document.reporter.warning(
                  f"Link <{refuri}> to stellargraph.readthedocs.io has a fragment {fragment!r} after #, which isn't yet supported for rewriting; remove the fragment, or search for this message in conf.py and extend it"
              )
              return
  
          html_suffix = ".html"
          new_domain = "std"
          new_type = "doc"
          new_target = "/" + rest[: -len(html_suffix)]
  
      xref = sphinx.addnodes.pending_xref(
          refdomain=new_domain,
          reftype=new_type,
          reftarget=new_target,
          refwarn=True,
          refexplicit=True,
          refdoc=env.docname,
      )
  
      linktext = node.astext()
      xref += docutils.nodes.Text(linktext, linktext)
  
      node.replace_self(xref)
  
file_path: stellargraph/docs/conf.py
imports: import urllib.parse
  import docutils
  import sphinx
  import os
  import sys
  import re
label_desc: Use image node_id 1 for calling the RewriteLinks obj's underlying member method code with example usage: obj._rewrite_rtd_link(node, refuri, parsed) without return types