Commits

Vlad Riscutia  committed 0ca4630

Fix patch.py issue on Windows where we end up with backslash in URL

  • Participants
  • Parent commits 11b9a8c

Comments (0)

Files changed (1)

File tinkerer/ext/patch.py

 
 
 
+def collapse_path(path_url):
+    '''
+    Normalize relative path and patch protocol prefix and Windows path separator
+    '''
+    return path.normpath(path_url).replace("\\", "/").replace(":/", "://")
+
+
+
 def patch_node(node, docpath, docname=None):
     '''
     Recursively patches links in nodes.
         # if this is relative path (internal link)
         if src.value.startswith(".."):
             src.value = docpath + src.value
-        src.value = path.normpath(src.value).replace(":/", "://")
+        src.value = collapse_path(src.value)
     # if node is hyperlink
     elif node_name == "a":
         ref = node.getAttributeNode("href")
             # "_static/" - we can use normpath for this, just make sure
             # to revert change on protocol prefix as normpath deduplicates
             # // (http:// becomes http:/)
-            ref.value = path.normpath(ref.value).replace(":/", "://")
+            ref.value = collapse_path(ref.value)
 
     # recurse
     for node in node.childNodes: