Skip to content
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

Add support for internal links in previewHtml #3676

Closed
tomi opened this issue Mar 3, 2016 · 6 comments
Closed

Add support for internal links in previewHtml #3676

tomi opened this issue Mar 3, 2016 · 6 comments
Assignees
Labels
api feature-request Request for new features or functionality
Milestone

Comments

@tomi
Copy link

tomi commented Mar 3, 2016

Hi,

At the moment the virtual documents created by TextDocumentContentProvider can contain links to external resources, but I would expect it to work with links that use the same scheme that was registered with registerTextDocumentContentProvider. Here's an example to show what I mean:

"use strict";
var vscode = require('vscode');

function activate(context) {

    let initUri = vscode.Uri.parse('link-test://authority/page1');

    const provider = {
        provideTextDocumentContent: function(uri) {
            if (uri.path === "/page1") {
                return `<a href="link-test://authority/page2">Page 2</a>`;
            } else {
                return `<a href="link-test://authority/page1">Page 1</a>`;
            }
        }
    };

    let registration = vscode.workspace.registerTextDocumentContentProvider('link-test', provider);

    let disposable = vscode.commands.registerCommand('extension.testLinks', () => {
        return vscode.commands.executeCommand('vscode.previewHtml', initUri, vscode.ViewColumn.Two).then((success) => {
        }, (reason) => {
            vscode.window.showErrorMessage(reason);
        });

    });
    context.subscriptions.push(disposable, registration);
}
exports.activate = activate;

When I click the link Page 2 I would expect the provideTextDocumentContent callback to be called with the URI specified in the link.

@BMGburger
Copy link

It looks great and I'm impressed...Also hoping I'm posting this in the right place.

@jrieken jrieken added feature-request Request for new features or functionality api labels Mar 7, 2016
@jrieken
Copy link
Member

jrieken commented Mar 7, 2016

I like

@jrieken jrieken added this to the April 2016 milestone Apr 7, 2016
@jrieken
Copy link
Member

jrieken commented Apr 7, 2016

strech for April - fyi @seanmcbreen

@jrieken
Copy link
Member

jrieken commented Apr 14, 2016

Tasks

  • support virtual document, file document, and commands
  • support to jump to a line in a file document

@jrieken
Copy link
Member

jrieken commented Apr 14, 2016

@tomi This is now implemented but be aware of how it works: In your case you have a virtual document that contains a link to another virtual document. Since the link only becomes a link when rendered via the vscode.previewHtml command, your link must do the same.

Therefore we have added support for command-links, like so command:vscode.previewHtml?"link-test://auth/path". It tells VS Code to execute the command using the query-part of the URI.

If your links reads like link-test://auth/path it will show the sources but not render it. When showing sources, there is support to denote the line using a fragments ala link-test://auth/path#L42.

@jrieken jrieken closed this as completed Apr 14, 2016
@tomi
Copy link
Author

tomi commented Apr 14, 2016

Cool, thanks for implementing this! It fits my needs well.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

3 participants