prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  jinja2 3.1.0 breaks mkdocs
  since the jinja2 3.1.0 release mkdocs does not work any more:
  
  ```
  admin@host ui % pip install jinja2==3.1.0
  Collecting jinja2==3.1.0
    Using cached Jinja2-3.1.0-py3-none-any.whl (132 kB)
  Installing collected packages: jinja2
    Attempting uninstall: jinja2
      Found existing installation: Jinja2 3.0.0
      Uninstalling Jinja2-3.0.0:
        Successfully uninstalled Jinja2-3.0.0
  Successfully installed jinja2-3.1.0
  admin@host ui % mkdocs build
  Traceback (most recent call last):
    File "/usr/local/bin/mkdocs", line 8, in <module>
      sys.exit(cli())
    File "/usr/local/lib/python3.9/site-packages/click/core.py", line 829, in __call__
      return self.main(*args, **kwargs)
    File "/usr/local/lib/python3.9/site-packages/click/core.py", line 782, in main
      rv = self.invoke(ctx)
    File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
      return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
      return ctx.invoke(self.callback, **ctx.params)
    File "/usr/local/lib/python3.9/site-packages/click/core.py", line 610, in invoke
      return callback(*args, **kwargs)
    File "/usr/local/lib/python3.9/site-packages/mkdocs/__main__.py", line 187, in build_command
      build.build(config.load_config(**kwargs), dirty=not clean)
    File "/usr/local/lib/python3.9/site-packages/mkdocs/config/base.py", line 216, in load_config
      from mkdocs.config.defaults import get_schema
    File "/usr/local/lib/python3.9/site-packages/mkdocs/config/defaults.py", line 1, in <module>
      from mkdocs.config import config_options
    File "/usr/local/lib/python3.9/site-packages/mkdocs/config/config_options.py", line 8, in <module>
      from mkdocs import utils, theme, plugins
    File "/usr/local/lib/python3.9/site-packages/mkdocs/theme.py", line 6, in <module>
      from mkdocs.utils import filters
    File "/usr/local/lib/python3.9/site-packages/mkdocs/utils/filters.py", line 13, in <module>
      @jinja2.contextfilter
  AttributeError: module 'jinja2' has no attribute 'contextfilter'
  ```
  However, if I install jinja2 3.0.0:
  ```
  admin@host ui % pip install jinja2==3.0.0
  Collecting jinja2==3.0.0
    Using cached Jinja2-3.0.0-py3-none-any.whl (133 kB)
  Requirement already satisfied: MarkupSafe>=2.0.0rc2 in /usr/local/lib/python3.9/site-packages (from jinja2==3.0.0) (2.1.1)
  Installing collected packages: jinja2
    Attempting uninstall: jinja2
      Found existing installation: Jinja2 3.1.0
      Uninstalling Jinja2-3.1.0:
        Successfully uninstalled Jinja2-3.1.0
  Successfully installed jinja2-3.0.0
  admin@host ui % mkdocs build
  INFO     -  Cleaning site directory
  INFO     -  Building documentation to directory: /Users/admin/git/searchlab/ui/site
  INFO     -  Documentation built in 0.33 seconds
  ```
  
  - mkdocs can be patched by explicitly installing jinja2 3.0.0.
  - maybe this is not a mkdocs bug, but a jinja2 bug; however, this could be patched in mkdocs as well.
  
  Prevent error with Jinja2 v3.1
  Fixes #2794
  
  See [Jinja2 v3.0.0 changes](https://jinja.palletsprojects.com/en/3.0.x/changes/#version-3-0-0):
  
  > The function and filter decorators have been renamed and unified. The old names are deprecated...
  > 
  > - `pass_context` replaces `contextfunction` and `contextfilter`.
  
  --- 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/utils/filters.py`
  Content:
  ```
  1 import jinja2
  2 
  3 from mkdocs.utils import normalize_url
  4 
  5 
  6 @jinja2.contextfilter
  7 def url_filter(context, value):
  8     """ A Template filter to normalize URLs. """
  9     return normalize_url(value, page=context['page'], base=context['base_url'])
  10
  ```
  --- 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/utils/filters.py b/mkdocs/utils/filters.py
  --- a/mkdocs/utils/filters.py
  +++ b/mkdocs/utils/filters.py
  @@ -1,9 +1,12 @@
  -import jinja2
  +try:
  +    from jinja2 import pass_context as contextfilter
  +except ImportError:
  +    from jinja2 import contextfilter
   
   from mkdocs.utils import normalize_url
   
   
  -@jinja2.contextfilter
  +@contextfilter
   def url_filter(context, value):
       """ A Template filter to normalize URLs. """
       return normalize_url(value, page=context['page'], base=context['base_url'])
  
verification_info: {"golden_diff": "diff --git a/mkdocs/utils/filters.py b/mkdocs/utils/filters.py\n--- a/mkdocs/utils/filters.py\n+++ b/mkdocs/utils/filters.py\n@@ -1,9 +1,12 @@\n-import jinja2\n+try:\n+    from jinja2 import pass_context as contextfilter\n+except ImportError:\n+    from jinja2 import contextfilter\n \n from mkdocs.utils import normalize_url\n \n \n-@jinja2.contextfilter\n+@contextfilter\n def url_filter(context, value):\n     \"\"\" A Template filter to normalize URLs. \"\"\"\n     return normalize_url(value, page=context['page'], base=context['base_url'])\n", "issue": "jinja2 3.1.0 breaks mkdocs\nsince the jinja2 3.1.0 release mkdocs does not work any more:\r\n\r\n```\r\nadmin@host ui % pip install jinja2==3.1.0\r\nCollecting jinja2==3.1.0\r\n  Using cached Jinja2-3.1.0-py3-none-any.whl (132 kB)\r\nInstalling collected packages: jinja2\r\n  Attempting uninstall: jinja2\r\n    Found existing installation: Jinja2 3.0.0\r\n    Uninstalling Jinja2-3.0.0:\r\n      Successfully uninstalled Jinja2-3.0.0\r\nSuccessfully installed jinja2-3.1.0\r\nadmin@host ui % mkdocs build\r\nTraceback (most recent call last):\r\n  File \"/usr/local/bin/mkdocs\", line 8, in <module>\r\n    sys.exit(cli())\r\n  File \"/usr/local/lib/python3.9/site-packages/click/core.py\", line 829, in __call__\r\n    return self.main(*args, **kwargs)\r\n  File \"/usr/local/lib/python3.9/site-packages/click/core.py\", line 782, in main\r\n    rv = self.invoke(ctx)\r\n  File \"/usr/local/lib/python3.9/site-packages/click/core.py\", line 1259, in invoke\r\n    return _process_result(sub_ctx.command.invoke(sub_ctx))\r\n  File \"/usr/local/lib/python3.9/site-packages/click/core.py\", line 1066, in invoke\r\n    return ctx.invoke(self.callback, **ctx.params)\r\n  File \"/usr/local/lib/python3.9/site-packages/click/core.py\", line 610, in invoke\r\n    return callback(*args, **kwargs)\r\n  File \"/usr/local/lib/python3.9/site-packages/mkdocs/__main__.py\", line 187, in build_command\r\n    build.build(config.load_config(**kwargs), dirty=not clean)\r\n  File \"/usr/local/lib/python3.9/site-packages/mkdocs/config/base.py\", line 216, in load_config\r\n    from mkdocs.config.defaults import get_schema\r\n  File \"/usr/local/lib/python3.9/site-packages/mkdocs/config/defaults.py\", line 1, in <module>\r\n    from mkdocs.config import config_options\r\n  File \"/usr/local/lib/python3.9/site-packages/mkdocs/config/config_options.py\", line 8, in <module>\r\n    from mkdocs import utils, theme, plugins\r\n  File \"/usr/local/lib/python3.9/site-packages/mkdocs/theme.py\", line 6, in <module>\r\n    from mkdocs.utils import filters\r\n  File \"/usr/local/lib/python3.9/site-packages/mkdocs/utils/filters.py\", line 13, in <module>\r\n    @jinja2.contextfilter\r\nAttributeError: module 'jinja2' has no attribute 'contextfilter'\r\n```\r\nHowever, if I install jinja2 3.0.0:\r\n```\r\nadmin@host ui % pip install jinja2==3.0.0\r\nCollecting jinja2==3.0.0\r\n  Using cached Jinja2-3.0.0-py3-none-any.whl (133 kB)\r\nRequirement already satisfied: MarkupSafe>=2.0.0rc2 in /usr/local/lib/python3.9/site-packages (from jinja2==3.0.0) (2.1.1)\r\nInstalling collected packages: jinja2\r\n  Attempting uninstall: jinja2\r\n    Found existing installation: Jinja2 3.1.0\r\n    Uninstalling Jinja2-3.1.0:\r\n      Successfully uninstalled Jinja2-3.1.0\r\nSuccessfully installed jinja2-3.0.0\r\nadmin@host ui % mkdocs build\r\nINFO     -  Cleaning site directory\r\nINFO     -  Building documentation to directory: /Users/admin/git/searchlab/ui/site\r\nINFO     -  Documentation built in 0.33 seconds\r\n```\r\n\r\n- mkdocs can be patched by explicitly installing jinja2 3.0.0.\r\n- maybe this is not a mkdocs bug, but a jinja2 bug; however, this could be patched in mkdocs as well.\r\n\nPrevent error with Jinja2 v3.1\nFixes #2794\r\n\r\nSee [Jinja2 v3.0.0 changes](https://jinja.palletsprojects.com/en/3.0.x/changes/#version-3-0-0):\r\n\r\n> The function and filter decorators have been renamed and unified. The old names are deprecated...\r\n> \r\n> - `pass_context` replaces `contextfunction` and `contextfilter`.\n", "before_files": [{"content": "import jinja2\n\nfrom mkdocs.utils import normalize_url\n\n\n@jinja2.contextfilter\ndef url_filter(context, value):\n    \"\"\" A Template filter to normalize URLs. \"\"\"\n    return normalize_url(value, page=context['page'], base=context['base_url'])\n", "path": "mkdocs/utils/filters.py"}], "after_files": [{"content": "try:\n    from jinja2 import pass_context as contextfilter\nexcept ImportError:\n    from jinja2 import contextfilter\n\nfrom mkdocs.utils import normalize_url\n\n\n@contextfilter\ndef url_filter(context, value):\n    \"\"\" A Template filter to normalize URLs. \"\"\"\n    return normalize_url(value, page=context['page'], base=context['base_url'])\n", "path": "mkdocs/utils/filters.py"}]}