瀏覽代碼

fix(hyperlink): fix hyperlinks on Windows

Fixes #335
Steven Davies 2 年之前
父節點
當前提交
5eaebebd43
共有 1 個文件被更改,包括 9 次插入0 次删除
  1. 9 0
      src/output/file_name.rs

+ 9 - 0
src/output/file_name.rs

@@ -351,6 +351,7 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
         let mut display_hyperlink = false;
         if self.options.embed_hyperlinks == EmbedHyperlinks::On {
             if let Some(abs_path) = self.file.absolute_path.as_ref().and_then(|p| p.as_os_str().to_str()) {
+                #[cfg(not(target_os = "windows"))]
                 bits.insert(0, ANSIString::from(format!(
                     "{}file://{}{}{}",
                     HYPERLINK_START,
@@ -358,6 +359,14 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
                     urlencoding::encode(abs_path).replace("%2F", "/"),
                     HYPERLINK_END,
                 )));
+                #[cfg(target_os = "windows")]
+                bits.insert(0, ANSIString::from(format!(
+                    "{}file://{}{}",
+                    HYPERLINK_START,
+                    abs_path.replace("\\\\?\\", ""),
+                    HYPERLINK_END,
+                )));
+
                 display_hyperlink = true;
             }
         }