You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
mkdocs_page_input_path uses backslashes on Windows #850
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 datavarmkdocs_page_name="City";varmkdocs_page_input_path="client-support\City.md";varmkdocs_page_url="/client-support/City/index.html";</script>
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.
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.
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.
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! 💯
Activity
waylan commentedon 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.sepis replaced with the forward slash (/) when building the page URL. On Windows,os.path.sepis 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 commentedon 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.
waylan commentedon 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.
Convert context to JSON when it is being passed to JavaScript
styfle commentedon 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! 💯
Convert context to JSON when it is being passed to JavaScript
Convert context to JSON when it is being passed to JavaScript