Skip to content

mkdocs_page_input_path uses backslashes on Windows #850

Closed

Description

@styfle

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

Activity

  1. waylan commented on Mar 1, 2016

    @waylan
    Contributor

    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.

  2. styfle commented on Mar 1, 2016

    @styfle
    ContributorAuthor

    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";
  3. waylan commented on Mar 1, 2016

    @waylan
    Contributor

    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.

  4. added a commit that references this issue on Mar 1, 2016
    e52944e
  5. styfle commented on Mar 1, 2016

    @styfle
    ContributorAuthor

    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! 💯

  6. added 2 commits that reference this issue on Mar 2, 2016
    784c74f
    1c252ba
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions