Repository: mkdocs/mkdocs

Issue:
Error when using a unicode filename on Windows
I am not totally sure this is the right place, but you will tell me :) 
In a mkdocs-material-project I wanted to use diacritics in the filename, like this: 

```
/Kapitel
  1. Einstieg
  2. Übersicht
  3. Etcetera
```

And such an **"Ü"** seems to break everything: 

```
C:\Python27\lib\urllib.py:1303: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  return ''.join(map(quoter, s))
ERROR   -  Error building page Allgemeines\1. Richtlinien.md
Traceback (most recent call last):
  File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\Scripts\mkdocs.exe\__main__.py", line 9, in <module>
  File "C:\Python27\lib\site-packages\click\core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "C:\Python27\lib\site-packages\click\core.py", line 696, in main
    rv = self.invoke(ctx)
  File "C:\Python27\lib\site-packages\click\core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Python27\lib\site-packages\click\core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Python27\lib\site-packages\click\core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "C:\Python27\lib\site-packages\mkdocs\__main__.py", line 115, in serve_command
    livereload=livereload,
  File "C:\Python27\lib\site-packages\mkdocs\commands\serve.py", line 78, in serve
    config = builder()
  File "C:\Python27\lib\site-packages\mkdocs\commands\serve.py", line 74, in builder
    build(config, live_server=True, clean_site_dir=True)
  File "C:\Python27\lib\site-packages\mkdocs\commands\build.py", line 289, in build
    build_pages(config)
  File "C:\Python27\lib\site-packages\mkdocs\commands\build.py", line 249, in build_pages
    dump_json)
  File "C:\Python27\lib\site-packages\mkdocs\commands\build.py", line 184, in _build_page
    output_content = template.render(context)
  File "C:\Python27\lib\site-packages\jinja2\environment.py", line 989, in render
    return self.environment.handle_exception(exc_info, True)
  File "C:\Python27\lib\site-packages\jinja2\environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Python27\lib\site-packages\material\base.html", line 102, in top-level template code
    {% include "drawer.html" %}
  File "C:\Python27\lib\site-packages\material\drawer.html", line 41, in top-level template code
    {% include "nav.html" %}
  File "C:\Python27\lib\site-packages\material\nav.html", line 6, in top-level template code
    {% include 'nav.html' %}
  File "C:\Python27\lib\site-packages\material\nav.html", line 12, in top-level template code
    <a class="{% if nav_item.active %}current{% endif %}" title="{{ nav_item.title }}" href="{{ nav_item.url }}">
  File "C:\Python27\lib\site-packages\jinja2\environment.py", line 408, in getattr
    return getattr(obj, attribute)
  File "C:\Python27\lib\site-packages\mkdocs\nav.py", line 153, in url
    return self.url_context.make_relative(self.abs_url)
  File "C:\Python27\lib\site-packages\mkdocs\nav.py", line 105, in make_relative
    return utils.path_to_url(relative_path)
  File "C:\Python27\lib\site-packages\mkdocs\utils\__init__.py", line 324, in path_to_url
    return pathname2url(path)
  File "C:\Python27\lib\nturl2path.py", line 54, in pathname2url
    return urllib.quote('/'.join(components))
  File "C:\Python27\lib\urllib.py", line 1303, in quote
    return ''.join(map(quoter, s))
KeyError: u'\xdc'
```

Is this already known? 



Discussion:
I just checked your example and this works fine on Linux (and last time I checked it did on OSX too). So I am fairly sure this is an issue with how we support Windows.

Unfortunately Windows is a best effort support, as I don't use windows.


Resolving patch:
diff --git a/mkdocs/utils/__init__.py b/mkdocs/utils/__init__.py
--- a/mkdocs/utils/__init__.py
+++ b/mkdocs/utils/__init__.py
@@ -321,6 +321,8 @@ def path_to_url(path):
     if os.path.sep == '/':
         return path
 
+    if sys.version_info < (3, 0):
+        path = path.encode('utf8')
     return pathname2url(path)
 
 


Test patch:
diff --git a/mkdocs/tests/integration.py b/mkdocs/tests/integration.py
--- a/mkdocs/tests/integration.py
+++ b/mkdocs/tests/integration.py
@@ -35,17 +35,20 @@
               required=True)
 def main(output=None):
 
+    print("Building themes.")
     for theme in sorted(MKDOCS_THEMES):
+        print("Building theme: {0}".format(theme))
         project_dir = os.path.dirname(MKDOCS_CONFIG)
         out = os.path.join(output, theme)
         command = ['mkdocs', 'build', '-v', '--site-dir', out, '--theme', theme]
         subprocess.check_call(command, cwd=project_dir)
 
+    print("Building test projects.")
     for project in os.listdir(TEST_PROJECTS):
-
+        print("Building test project: {0}".format(project))
         project_dir = os.path.join(TEST_PROJECTS, project)
         out = os.path.join(output, project)
-        command = ['mkdocs', 'build', '--site-dir', out]
+        command = ['mkdocs', 'build', '-v', '--site-dir', out]
         subprocess.check_call(command, cwd=project_dir)
 
     print("Theme and integration builds are available in {0}".format(output))
diff --git a/mkdocs/tests/integration/unicode/docs/index.md b/mkdocs/tests/integration/unicode/docs/index.md
new file mode 100644
--- /dev/null
+++ b/mkdocs/tests/integration/unicode/docs/index.md
@@ -0,0 +1,2 @@
+# Unicode Test Documentation 📖
+
diff --git "a/mkdocs/tests/integration/unicode/docs/\303\234bersicht.md" "b/mkdocs/tests/integration/unicode/docs/\303\234bersicht.md"
new file mode 100644
--- /dev/null
+++ "b/mkdocs/tests/integration/unicode/docs/\303\234bersicht.md"
@@ -0,0 +1,17 @@
+# Welcome to MkDocs
+
+For full documentation visit [mkdocs.org](http://mkdocs.org).
+
+## Commands
+
+* `mkdocs new [dir-name]` - Create a new project.
+* `mkdocs serve` - Start the live-reloading docs server.
+* `mkdocs build` - Build the documentation site.
+* `mkdocs help` - Print this help message.
+
+## Project layout
+
+    mkdocs.yml    # The configuration file.
+    docs/
+        index.md  # The documentation homepage.
+        ...       # Other markdown pages, images and other files.
diff --git "a/mkdocs/tests/integration/unicode/docs/\342\231\252.md" "b/mkdocs/tests/integration/unicode/docs/\342\231\252.md"
new file mode 100644
--- /dev/null
+++ "b/mkdocs/tests/integration/unicode/docs/\342\231\252.md"
@@ -0,0 +1,17 @@
+# Welcome to MkDocs
+
+For full documentation visit [mkdocs.org](http://mkdocs.org).
+
+## Commands
+
+* `mkdocs new [dir-name]` - Create a new project.
+* `mkdocs serve` - Start the live-reloading docs server.
+* `mkdocs build` - Build the documentation site.
+* `mkdocs help` - Print this help message.
+
+## Project layout
+
+    mkdocs.yml    # The configuration file.
+    docs/
+        index.md  # The documentation homepage.
+        ...       # Other markdown pages, images and other files.
diff --git a/mkdocs/tests/integration/unicode/mkdocs.yml b/mkdocs/tests/integration/unicode/mkdocs.yml
new file mode 100644
--- /dev/null
+++ b/mkdocs/tests/integration/unicode/mkdocs.yml
@@ -0,0 +1 @@
+site_name: My Docs