Skip to content

Add support for internal links in previewHtml #3676

@tomi

Description

@tomi

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.

Metadata

Metadata

Assignees

Labels

apifeature-requestRequest for new features or functionality

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions