Repository: mkdocs/mkdocs

Issue:
mkdocs_page_input_path uses backslashes on Windows
When building on Windows, it looks like the `mkdocs_page_input_path` uses backslashes instead of forward slashes. I'm writing a script to get the original source file and I can't because it gets malformed since '\c` is a non-printable character.
## HTML emitted on page

``` html
<script>
    // Current page data
    var mkdocs_page_name = "City";
    var mkdocs_page_input_path = "client-support\City.md";
    var mkdocs_page_url = "/client-support/City/index.html";
  </script>
```
## My extra.js script

``` js
console.log(mkdocs_page_input_path);
// client-supportCity.md
```



Discussion:
Windows uses backslashes for file paths. The value of the input path is the string returned by Windows itself. MkDocs converts it to a properly formed URL when creating the page URL, but not before. After all, when MkDocs reads the contents of the file, it uses the value of the input path  which needs to be formatted for the local file system. Note that [here](https://github.com/mkdocs/mkdocs/blob/master/mkdocs/utils/__init__.py#L179), the `os.path.sep` is replaced with the forward slash (`/`) when building the page URL. On Windows, `os.path.sep` is a backslash (`\`).

Therefore, this is not a bug, but intended behavior. If you want to work with that value, then you will need to convert it to something that you can use first.

I think the code you linked to is fine. I believe the problem is in [readthedocs/base.html](https://github.com/mkdocs/mkdocs/blob/master/mkdocs/themes/readthedocs/base.html#L31). The backslashes should be escaped before it is injected into the string. I would expect the output to have two backslashes.

``` js
var mkdocs_page_input_path = "client-support\\City.md";
```

Ah, I see what you are getting at. Another one of those annoying Windows edge cases that those of us who don't work on the platform easily miss. I suppose a template filter could address this. Or perhaps the value could be modified when building the template context. Patches are of course welcome. Its always best when a person who actually uses the platform provides a solution.


Resolving patch:
diff --git a/mkdocs/commands/build.py b/mkdocs/commands/build.py
--- a/mkdocs/commands/build.py
+++ b/mkdocs/commands/build.py
@@ -11,6 +11,7 @@
 import json
 
 from mkdocs import nav, search, utils
+from mkdocs.utils import filters
 from mkdocs.relative_path_ext import RelativePathExtension
 import mkdocs
 
@@ -228,6 +229,7 @@ def build_pages(config, dump_json=False):
     site_navigation = nav.SiteNavigation(config['pages'], config['use_directory_urls'])
     loader = jinja2.FileSystemLoader(config['theme_dir'] + [config['mkdocs_templates'], ])
     env = jinja2.Environment(loader=loader)
+    env.filters['tojson'] = filters.tojson
     search_index = search.SearchIndex()
 
     build_template('404.html', env, config, site_navigation)
diff --git a/mkdocs/utils/filters.py b/mkdocs/utils/filters.py
new file mode 100644
--- /dev/null
+++ b/mkdocs/utils/filters.py
@@ -0,0 +1,6 @@
+import json
+import jinja2
+
+
+def tojson(obj, **kwargs):
+    return jinja2.Markup(json.dumps(obj, **kwargs))


Test patch: