简体   繁体   English

Windows 上 Atom / JavaScript 的路径分隔符

[英]Path separator for Atom / JavaScript on Windows

I have developed an Atom package which calls SyncTeX (a utility for reverse lookup for LaTeX), and then opens in Atom the file specified in the SyncTeX response.我开发了一个 Atom 包,它调用 SyncTeX(一个用于反向查找 LaTeX 的实用程序),然后在 Atom 中打开 SyncTeX 响应中指定的文件。 I'm developing on Linux, but now a user on Windows tells me that this doesn't work.我正在 Linux 上开发,但现在 Windows 上的用户告诉我这不起作用。

In detail: SyncTeX returns a pathname like C:\\data\\tex\\main.tex , with Windows-appropriate backslash separators.详细说明:SyncTeX 返回一个路径名,如C:\\data\\tex\\main.tex ,带有适用于 Windows 的反斜杠分隔符。 My package then calls atom.workspace.open with exactly that returned string, which leads to a JavaScript error (file not found).我的包然后使用返回的字符串调用atom.workspace.open ,这会导致 JavaScript 错误(找不到文件)。

Strangely, if the string is modified to use forward slashes instead, C:/data/tex/main.tex , the call works and the file is opened.奇怪的是,如果字符串被修改为使用正斜杠, C:/data/tex/main.tex ,调用工作并打开文件。

My questions:我的问题:

  1. Is this behavior specific to Atom, or to some underlying technology (JavaScript, Electron, Node, ...)?这种行为是特定于 Atom 的,还是特定于某些底层技术(JavaScript、Electron、Node 等)的? I was unable to find any documentation on this.我找不到任何关于此的文档。

  2. Since the replacement \\/ is apparently necessary, is there a preferred way to implement it?由于替换\\/显然是必要的,有没有一种首选的方法来实现它? Would a simple String.replace be adequate?一个简单的String.replace就足够了吗?

  3. Do I risk breaking compatibility with other platforms if I always do the replacement?如果我总是进行替换,我是否有可能破坏与其他平台的兼容性?

根据我最好的知识路径,带正斜杠“/”的路径在除 Windows XP 之外的任何地方都能很好地工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM