New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mkdocs_page_input_path uses backslashes on Windows #850

Closed
styfle opened this Issue Feb 29, 2016 · 4 comments

Comments

Projects
None yet
3 participants
@styfle
Contributor

styfle commented Feb 29, 2016

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

<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

console.log(mkdocs_page_input_path);
// client-supportCity.md
@waylan

This comment has been minimized.

Member

waylan commented Mar 1, 2016

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, 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.

@styfle

This comment has been minimized.

Contributor

styfle commented Mar 1, 2016

I think the code you linked to is fine. I believe the problem is in readthedocs/base.html. The backslashes should be escaped before it is injected into the string. I would expect the output to have two backslashes.

var mkdocs_page_input_path = "client-support\\City.md";
@waylan

This comment has been minimized.

Member

waylan commented Mar 1, 2016

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.

@styfle

This comment has been minimized.

Contributor

styfle commented Mar 1, 2016

I would definitely do that if I understood a little more about python. The JSON Serialization fix that @d0ugal just made should solve this problem (among others). Thanks for the quick response and fix! 💯

d0ugal added a commit to d0ugal/mkdocs that referenced this issue Mar 2, 2016

d0ugal added a commit to d0ugal/mkdocs that referenced this issue Mar 2, 2016

@d0ugal d0ugal closed this in #853 Mar 2, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment