prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Mailto links not correctly interpreted
  Hi, 
  I've noticed "mailto" links are not correctly interpreted.
  - This code:
  
  ```
  Contact us at <foo@bar>
  ```
  - Renders the following link:  
    http://localhost//mailto:foo@bar  
  
  ---
  - This code:
  
  ```
  You can [contact us](foo@bar)
  ```
  - Renders the following link:  
    http://localhost/page/permalink/foo@bar
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `mkdocs/relative_path_ext.py`
  Content:
  ```
  1 """
  2 # Relative Path Markdown Extension
  3 
  4 During the MkDocs build we rewrite URLs that link to local
  5 Markdown or media files. Using the following pages configuration
  6 we can look at how the output is changed.
  7 
  8     pages:
  9     - ['index.md']
  10     - ['tutorial/install.md']
  11     - ['tutorial/intro.md']
  12 
  13 ## Markdown URLs
  14 
  15 When linking from `install.md` to `intro.md` the link would
  16 simply be `[intro](intro.md)`. However, when we build
  17 `install.md` we place it in a directory to create nicer URLs.
  18 This means that the path to `intro.md` becomes `../intro/`
  19 
  20 ## Media URLs
  21 
  22 To make it easier to work with media files and store them all
  23 under one directory we re-write those to all be based on the
  24 root. So, with the following markdown to add an image.
  25 
  26     ![The initial MkDocs layout](img/initial-layout.png)
  27 
  28 The output would depend on the location of the Markdown file it
  29 was added too.
  30 
  31 Source file         | Generated Path    | Image Path                   |
  32 ------------------- | ----------------- | ---------------------------- |
  33 index.md            | /                 | ./img/initial-layout.png     |
  34 tutorial/install.md | tutorial/install/ | ../img/initial-layout.png    |
  35 tutorial/intro.md   | tutorial/intro/   | ../../img/initial-layout.png |
  36 
  37 """
  38 
  39 from __future__ import unicode_literals
  40 
  41 import logging
  42 import os
  43 
  44 from markdown.extensions import Extension
  45 from markdown.treeprocessors import Treeprocessor
  46 
  47 from mkdocs import utils
  48 from mkdocs.exceptions import MarkdownNotFound
  49 
  50 log = logging.getLogger(__name__)
  51 
  52 
  53 def _iter(node):
  54     # TODO: Remove when dropping Python 2.6. Replace this
  55     # function call with note.iter()
  56     return [node] + node.findall('.//*')
  57 
  58 
  59 def path_to_url(url, nav, strict):
  60 
  61     scheme, netloc, path, params, query, fragment = (
  62         utils.urlparse(url))
  63 
  64     if scheme or netloc or not path:
  65         # Ignore URLs unless they are a relative link to a markdown file.
  66         return url
  67 
  68     if nav and not utils.is_markdown_file(path):
  69         path = utils.create_relative_media_url(nav, path)
  70     elif nav:
  71         # If the site navigation has been provided, then validate
  72         # the internal hyperlink, making sure the target actually exists.
  73         target_file = nav.file_context.make_absolute(path)
  74 
  75         if target_file.startswith(os.path.sep):
  76             target_file = target_file[1:]
  77 
  78         if target_file not in nav.source_files:
  79             source_file = nav.file_context.current_file
  80             msg = (
  81                 'The page "%s" contained a hyperlink to "%s" which '
  82                 'is not listed in the "pages" configuration.'
  83             ) % (source_file, target_file)
  84 
  85             # In strict mode raise an error at this point.
  86             if strict:
  87                 raise MarkdownNotFound(msg)
  88             # Otherwise, when strict mode isn't enabled, log a warning
  89             # to the user and leave the URL as it is.
  90             log.warning(msg)
  91             return url
  92         path = utils.get_url_path(target_file, nav.use_directory_urls)
  93         path = nav.url_context.make_relative(path)
  94     else:
  95         path = utils.get_url_path(path).lstrip('/')
  96 
  97     # Convert the .md hyperlink to a relative hyperlink to the HTML page.
  98     fragments = (scheme, netloc, path, params, query, fragment)
  99     url = utils.urlunparse(fragments)
  100     return url
  101 
  102 
  103 class RelativePathTreeprocessor(Treeprocessor):
  104 
  105     def __init__(self, site_navigation, strict):
  106         self.site_navigation = site_navigation
  107         self.strict = strict
  108 
  109     def run(self, root):
  110         """Update urls on anchors and images to make them relative
  111 
  112         Iterates through the full document tree looking for specific
  113         tags and then makes them relative based on the site navigation
  114         """
  115 
  116         for element in _iter(root):
  117 
  118             if element.tag == 'a':
  119                 key = 'href'
  120             elif element.tag == 'img':
  121                 key = 'src'
  122             else:
  123                 continue
  124 
  125             url = element.get(key)
  126             new_url = path_to_url(url, self.site_navigation, self.strict)
  127             element.set(key, new_url)
  128 
  129         return root
  130 
  131 
  132 class RelativePathExtension(Extension):
  133     """
  134     The Extension class is what we pass to markdown, it then
  135     registers the Treeprocessor.
  136     """
  137 
  138     def __init__(self, site_navigation, strict):
  139         self.site_navigation = site_navigation
  140         self.strict = strict
  141 
  142     def extendMarkdown(self, md, md_globals):
  143         relpath = RelativePathTreeprocessor(self.site_navigation, self.strict)
  144         md.treeprocessors.add("relpath", relpath, "_end")
  145
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/mkdocs/relative_path_ext.py b/mkdocs/relative_path_ext.py
  --- a/mkdocs/relative_path_ext.py
  +++ b/mkdocs/relative_path_ext.py
  @@ -43,6 +43,7 @@
   
   from markdown.extensions import Extension
   from markdown.treeprocessors import Treeprocessor
  +from markdown.util import AMP_SUBSTITUTE
   
   from mkdocs import utils
   from mkdocs.exceptions import MarkdownNotFound
  @@ -61,8 +62,10 @@
       scheme, netloc, path, params, query, fragment = (
           utils.urlparse(url))
   
  -    if scheme or netloc or not path:
  +    if scheme or netloc or not path or AMP_SUBSTITUTE in url:
           # Ignore URLs unless they are a relative link to a markdown file.
  +        # AMP_SUBSTITUTE is used internally by Markdown only for email,which is
  +        # not a relative link. As urlparse errors on them, skip explicitly
           return url
   
       if nav and not utils.is_markdown_file(path):
  
verification_info: {"golden_diff": "diff --git a/mkdocs/relative_path_ext.py b/mkdocs/relative_path_ext.py\n--- a/mkdocs/relative_path_ext.py\n+++ b/mkdocs/relative_path_ext.py\n@@ -43,6 +43,7 @@\n \n from markdown.extensions import Extension\n from markdown.treeprocessors import Treeprocessor\n+from markdown.util import AMP_SUBSTITUTE\n \n from mkdocs import utils\n from mkdocs.exceptions import MarkdownNotFound\n@@ -61,8 +62,10 @@\n     scheme, netloc, path, params, query, fragment = (\n         utils.urlparse(url))\n \n-    if scheme or netloc or not path:\n+    if scheme or netloc or not path or AMP_SUBSTITUTE in url:\n         # Ignore URLs unless they are a relative link to a markdown file.\n+        # AMP_SUBSTITUTE is used internally by Markdown only for email,which is\n+        # not a relative link. As urlparse errors on them, skip explicitly\n         return url\n \n     if nav and not utils.is_markdown_file(path):\n", "issue": "Mailto links not correctly interpreted\nHi, \nI've noticed \"mailto\" links are not correctly interpreted.\n- This code:\n\n```\nContact us at <foo@bar>\n```\n- Renders the following link:  \n  http://localhost//mailto:foo@bar  \n\n---\n- This code:\n\n```\nYou can [contact us](foo@bar)\n```\n- Renders the following link:  \n  http://localhost/page/permalink/foo@bar\n\n", "before_files": [{"content": "\"\"\"\n# Relative Path Markdown Extension\n\nDuring the MkDocs build we rewrite URLs that link to local\nMarkdown or media files. Using the following pages configuration\nwe can look at how the output is changed.\n\n    pages:\n    - ['index.md']\n    - ['tutorial/install.md']\n    - ['tutorial/intro.md']\n\n## Markdown URLs\n\nWhen linking from `install.md` to `intro.md` the link would\nsimply be `[intro](intro.md)`. However, when we build\n`install.md` we place it in a directory to create nicer URLs.\nThis means that the path to `intro.md` becomes `../intro/`\n\n## Media URLs\n\nTo make it easier to work with media files and store them all\nunder one directory we re-write those to all be based on the\nroot. So, with the following markdown to add an image.\n\n    ![The initial MkDocs layout](img/initial-layout.png)\n\nThe output would depend on the location of the Markdown file it\nwas added too.\n\nSource file         | Generated Path    | Image Path                   |\n------------------- | ----------------- | ---------------------------- |\nindex.md            | /                 | ./img/initial-layout.png     |\ntutorial/install.md | tutorial/install/ | ../img/initial-layout.png    |\ntutorial/intro.md   | tutorial/intro/   | ../../img/initial-layout.png |\n\n\"\"\"\n\nfrom __future__ import unicode_literals\n\nimport logging\nimport os\n\nfrom markdown.extensions import Extension\nfrom markdown.treeprocessors import Treeprocessor\n\nfrom mkdocs import utils\nfrom mkdocs.exceptions import MarkdownNotFound\n\nlog = logging.getLogger(__name__)\n\n\ndef _iter(node):\n    # TODO: Remove when dropping Python 2.6. Replace this\n    # function call with note.iter()\n    return [node] + node.findall('.//*')\n\n\ndef path_to_url(url, nav, strict):\n\n    scheme, netloc, path, params, query, fragment = (\n        utils.urlparse(url))\n\n    if scheme or netloc or not path:\n        # Ignore URLs unless they are a relative link to a markdown file.\n        return url\n\n    if nav and not utils.is_markdown_file(path):\n        path = utils.create_relative_media_url(nav, path)\n    elif nav:\n        # If the site navigation has been provided, then validate\n        # the internal hyperlink, making sure the target actually exists.\n        target_file = nav.file_context.make_absolute(path)\n\n        if target_file.startswith(os.path.sep):\n            target_file = target_file[1:]\n\n        if target_file not in nav.source_files:\n            source_file = nav.file_context.current_file\n            msg = (\n                'The page \"%s\" contained a hyperlink to \"%s\" which '\n                'is not listed in the \"pages\" configuration.'\n            ) % (source_file, target_file)\n\n            # In strict mode raise an error at this point.\n            if strict:\n                raise MarkdownNotFound(msg)\n            # Otherwise, when strict mode isn't enabled, log a warning\n            # to the user and leave the URL as it is.\n            log.warning(msg)\n            return url\n        path = utils.get_url_path(target_file, nav.use_directory_urls)\n        path = nav.url_context.make_relative(path)\n    else:\n        path = utils.get_url_path(path).lstrip('/')\n\n    # Convert the .md hyperlink to a relative hyperlink to the HTML page.\n    fragments = (scheme, netloc, path, params, query, fragment)\n    url = utils.urlunparse(fragments)\n    return url\n\n\nclass RelativePathTreeprocessor(Treeprocessor):\n\n    def __init__(self, site_navigation, strict):\n        self.site_navigation = site_navigation\n        self.strict = strict\n\n    def run(self, root):\n        \"\"\"Update urls on anchors and images to make them relative\n\n        Iterates through the full document tree looking for specific\n        tags and then makes them relative based on the site navigation\n        \"\"\"\n\n        for element in _iter(root):\n\n            if element.tag == 'a':\n                key = 'href'\n            elif element.tag == 'img':\n                key = 'src'\n            else:\n                continue\n\n            url = element.get(key)\n            new_url = path_to_url(url, self.site_navigation, self.strict)\n            element.set(key, new_url)\n\n        return root\n\n\nclass RelativePathExtension(Extension):\n    \"\"\"\n    The Extension class is what we pass to markdown, it then\n    registers the Treeprocessor.\n    \"\"\"\n\n    def __init__(self, site_navigation, strict):\n        self.site_navigation = site_navigation\n        self.strict = strict\n\n    def extendMarkdown(self, md, md_globals):\n        relpath = RelativePathTreeprocessor(self.site_navigation, self.strict)\n        md.treeprocessors.add(\"relpath\", relpath, \"_end\")\n", "path": "mkdocs/relative_path_ext.py"}], "after_files": [{"content": "\"\"\"\n# Relative Path Markdown Extension\n\nDuring the MkDocs build we rewrite URLs that link to local\nMarkdown or media files. Using the following pages configuration\nwe can look at how the output is changed.\n\n    pages:\n    - ['index.md']\n    - ['tutorial/install.md']\n    - ['tutorial/intro.md']\n\n## Markdown URLs\n\nWhen linking from `install.md` to `intro.md` the link would\nsimply be `[intro](intro.md)`. However, when we build\n`install.md` we place it in a directory to create nicer URLs.\nThis means that the path to `intro.md` becomes `../intro/`\n\n## Media URLs\n\nTo make it easier to work with media files and store them all\nunder one directory we re-write those to all be based on the\nroot. So, with the following markdown to add an image.\n\n    ![The initial MkDocs layout](img/initial-layout.png)\n\nThe output would depend on the location of the Markdown file it\nwas added too.\n\nSource file         | Generated Path    | Image Path                   |\n------------------- | ----------------- | ---------------------------- |\nindex.md            | /                 | ./img/initial-layout.png     |\ntutorial/install.md | tutorial/install/ | ../img/initial-layout.png    |\ntutorial/intro.md   | tutorial/intro/   | ../../img/initial-layout.png |\n\n\"\"\"\n\nfrom __future__ import unicode_literals\n\nimport logging\nimport os\n\nfrom markdown.extensions import Extension\nfrom markdown.treeprocessors import Treeprocessor\nfrom markdown.util import AMP_SUBSTITUTE\n\nfrom mkdocs import utils\nfrom mkdocs.exceptions import MarkdownNotFound\n\nlog = logging.getLogger(__name__)\n\n\ndef _iter(node):\n    # TODO: Remove when dropping Python 2.6. Replace this\n    # function call with note.iter()\n    return [node] + node.findall('.//*')\n\n\ndef path_to_url(url, nav, strict):\n\n    scheme, netloc, path, params, query, fragment = (\n        utils.urlparse(url))\n\n    if scheme or netloc or not path or AMP_SUBSTITUTE in url:\n        # Ignore URLs unless they are a relative link to a markdown file.\n        # AMP_SUBSTITUTE is used internally by Markdown only for email,which is\n        # not a relative link. As urlparse errors on them, skip explicitly\n        return url\n\n    if nav and not utils.is_markdown_file(path):\n        path = utils.create_relative_media_url(nav, path)\n    elif nav:\n        # If the site navigation has been provided, then validate\n        # the internal hyperlink, making sure the target actually exists.\n        target_file = nav.file_context.make_absolute(path)\n\n        if target_file.startswith(os.path.sep):\n            target_file = target_file[1:]\n\n        if target_file not in nav.source_files:\n            source_file = nav.file_context.current_file\n            msg = (\n                'The page \"%s\" contained a hyperlink to \"%s\" which '\n                'is not listed in the \"pages\" configuration.'\n            ) % (source_file, target_file)\n\n            # In strict mode raise an error at this point.\n            if strict:\n                raise MarkdownNotFound(msg)\n            # Otherwise, when strict mode isn't enabled, log a warning\n            # to the user and leave the URL as it is.\n            log.warning(msg)\n            return url\n        path = utils.get_url_path(target_file, nav.use_directory_urls)\n        path = nav.url_context.make_relative(path)\n    else:\n        path = utils.get_url_path(path).lstrip('/')\n\n    # Convert the .md hyperlink to a relative hyperlink to the HTML page.\n    fragments = (scheme, netloc, path, params, query, fragment)\n    url = utils.urlunparse(fragments)\n    return url\n\n\nclass RelativePathTreeprocessor(Treeprocessor):\n\n    def __init__(self, site_navigation, strict):\n        self.site_navigation = site_navigation\n        self.strict = strict\n\n    def run(self, root):\n        \"\"\"Update urls on anchors and images to make them relative\n\n        Iterates through the full document tree looking for specific\n        tags and then makes them relative based on the site navigation\n        \"\"\"\n\n        for element in _iter(root):\n\n            if element.tag == 'a':\n                key = 'href'\n            elif element.tag == 'img':\n                key = 'src'\n            else:\n                continue\n\n            url = element.get(key)\n            new_url = path_to_url(url, self.site_navigation, self.strict)\n            element.set(key, new_url)\n\n        return root\n\n\nclass RelativePathExtension(Extension):\n    \"\"\"\n    The Extension class is what we pass to markdown, it then\n    registers the Treeprocessor.\n    \"\"\"\n\n    def __init__(self, site_navigation, strict):\n        self.site_navigation = site_navigation\n        self.strict = strict\n\n    def extendMarkdown(self, md, md_globals):\n        relpath = RelativePathTreeprocessor(self.site_navigation, self.strict)\n        md.treeprocessors.add(\"relpath\", relpath, \"_end\")\n", "path": "mkdocs/relative_path_ext.py"}]}