-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clicking links to local files inside a preview window does not work #435
Comments
The fix in #455 would be functional but doesn't provide strong integration with the VS Code security model. I think previously these links were rewritten with
I'm going to comment on this issue about what I learn as I research the VS Code security model so we can provide a better integration:
Within Asciidoctor.js we can create a template that extends the default html5 converter which will process links (and other resources) where we can build the required logic (see the Docs). I think we need to have templates which handle:
I don't think it's possible to support arbitrary content in passthroughs. I need to study the Markdown extension to look through implementation in more detail. |
Thanks for gathering all these information.
I don't think that's true. As far as I understand, In microsoft/vscode#126402 (comment), Matt Bierner suggests:
So maybe we should resolve relative paths to use absolue path, but I guess it won't work in a web environment (https://github.dev/) or use a |
For reference, here's what the Markdown extension generates: # Index
![Image](./sunset.jpg)
[MDN Web Docs](https://developer.mozilla.org/)
[relative](./index.html) <head>
<!-- ... -->
<base href="https://file%2B.vscode-resource.vscode-webview.net/c%3A/my%20documentation/index.md">
</head>
<body class=".." data-vscode-theme-name="Dark+ (default dark)">
<h1 id="index" data-line="0" class="code-line code-active-line">Index</h1>
<p data-line="2" class="code-line"><img src="./sunset.jpg" alt="Image" class="" id="image-hash-696037171" data-src="./sunset.jpg"></p>
<p data-line="4" class="code-line"><a href="https://developer.mozilla.org/" data-href="https://developer.mozilla.org/" title="https://developer.mozilla.org/">MDN Web Docs</a></p>
<p data-line="6" class="code-line"><a href="./index.html" data-href="./index.html" title="./index.html">relative</a></p>
<!-- ... -->
</body> So links are relative and the document has a Using the Asciidoctor extension: = Index
image:sunset.jpg[]
https://developer.mozilla.org/[MDN Web Docs]
link:./index.html[relative] <html>
<head>
<!-- ... -->
<base href="vscode-resource:/c:/my documentation/index.adoc">
</head>
<body class="..." data-vscode-theme-name="Dark+ (default dark)">
<title>Index</title>
<div id="header">
<h1>Index</h1>
</div>
<div id="content">
<div class="paragraph data-line-3">
<p><span class="image"><img src="sunset.jpg" alt="sunset"></span></p>
</div>
<div class="paragraph data-line-5">
<p><a href="https://developer.mozilla.org/" title="https://developer.mozilla.org/">MDN Web Docs</a></p>
</div>
<div class="paragraph data-line-7">
<p><a href="./index.html" title="./index.html">relative</a></p>
</div>
</div>
<div id="footer">
<div id="footer-text">Last updated 2021-10-03 22:45:26 +0200</div>
</div>
<!-- ... -->
</body
</html> As you can see the |
Nice comparison. If we're going to change the I guess we should keep the scope tight and discuss links here and deal with images in #436 |
You're right of course... but also the Markdown preview uses And that is also insufficient. The other thing I noticed about the above and also fixes on other extensions is that they also set I have corrected the asciidoctor-vscode/preview-src/index.ts Lines 130 to 168 in 23f80e6
My next task is to read code for some time to try and understand why the Markdown extension works the way it does (why put the |
Restoring links to working in preview pane, closes #435
This issue seems to be happening again, it is happening to me using the last version of vscode (also in vscodium) and the last version of the extension (v2.9.8). In the developers tool console I get the following error when I click on a link to a local file:
So for some reason the extension is trying to open the file "/[object Object].md'", I tried to create this file and indeed it is opened when I click on any link to a local file. The extension ".md" always appears here, independently of the actual path and extension of the file that I try to link. This is the information of my system: Version: 1.67.2 |
@tombolano do you have the complete stacktrace? could you please share a minimal document and the steps to reproduce this issue? |
Yes, the steps to reproduce are almost the same as in the original post. To reproduce
Errors and stacktraceWhen a link is clicked these are the errors that appear on the console:
Additional commentsInitially I tested this on a Linux system (what I normally use), I have also tested it now on a Windows machine with the last versions of VSCode and the asciidoc-vscode extension and the results are the same. Clearly something is wrong, but in the stacktrace it seems that only Node.js and vscode functions are called. |
Thanks! asciidoctor-vscode/src/features/preview.ts Line 454 in 5853aa9
But the command is definitely wrong: asciidoctor-vscode/src/commands/openDocumentLink.ts Lines 33 to 43 in 5853aa9
I believe that return this.tryOpen(p + '.md', args) |
Yes, thank you, it seems that the problem is in the function onDidClickPreviewLink: asciidoctor-vscode/src/features/preview.ts Lines 436 to 455 in 5853aa9
I have looked into this problem and the So Also, I noticed that there is a related subtle bug in the same function in line 445: asciidoctor-vscode/src/features/preview.ts Line 445 in 5853aa9
This line is used to decide if opening AsciiDoc files in the preview window or in the editor following the option The bug here is that the string in the code is wrong, the D in the option This is the diff with the fixes to these problems: diff --git a/src/features/preview.ts b/src/features/preview.ts
index d235117..1a7e190 100644
--- a/src/features/preview.ts
+++ b/src/features/preview.ts
@@ -435,7 +435,7 @@ export class AsciidocPreview {
// Handle any normalized file paths
hrefPath = vscode.Uri.parse(hrefPath.replace('/file', '')).fsPath
}
- const openLinks = this.config.get<string>('preview.openAsciidocLinks', 'inPreview')
+ const openLinks = this.config.get<string>('preview.openAsciiDocLinks', 'inPreview')
if (openLinks === 'inPreview') {
const asciidocLink = await resolveLinkToAsciidocFile(hrefPath)
if (asciidocLink) {
@@ -444,7 +444,7 @@ export class AsciidocPreview {
}
}
- vscode.commands.executeCommand('_asciidoc.openDocumentLink', { path, fragment })
+ vscode.commands.executeCommand('_asciidoc.openDocumentLink', { path: hrefPath, fragment })
}
private async onCacheImageSizes (imageInfo: { id: string, width: number, height: number }[]) { I have checked and with these fixes everything seems to be working fine. |
Thanks for the thorough investigation! |
Fixed in #572 |
Happens to me in v2.9.8. Am I doing something wrong? |
No, nothing wrong, the bug was actually fixed in the 3.0.0 version, last version is 3.0.1 (see releases: https://github.com/asciidoctor/asciidoctor-vscode/releases), however these versions are marked as prereleases, that's why in the front page still 2.9.8 appears as the last version. |
Description
Clicking links to local files inside a preview window does not work.
System Information
Version: 1.59.1 (system setup)
Commit: 3866c3553be8b268c8a7f8c0482c0c0177aa8bfa
Date: 2021-08-19T11:56:46.957Z
Electron: 13.1.7
Chrome: 91.0.4472.124
Node.js: 14.16.0
V8: 9.1.269.36-electron.0
OS: Windows_NT x64 10.0.17763
Running asciidoctor extension 2.8.9
To Reproduce
<N>
\Downloads\test where<N>
is your user account name. (In other words, create a folder named 'test' inside your Download directory.)Yes, I trust the authors
.<N>
\Downloads\test\test1.adoc. (Remember to substitute your user account name for<N>
, including the content below):<N>
\Downloads\test\test2.adoc:Screenshots & Files
This is what the browser window looks like
Additional Context
I expect a tab to be opened for test2.adoc when any link inside test1.adoc is clicked in the preview window.
The text was updated successfully, but these errors were encountered: