如何从文件的html字符串中评估vscode-resource

时间:2019-07-16 05:20:35

标签: visual-studio-code

我正在尝试评估(或替换)使用vscode-resource uri从文件读取的html字符串的占位符${key}

下面的示例https://code.visualstudio.com/api/extension-guides/webview#loading-local-content中,它们在同一文件中具有html内容(作为字符串)。我正在从文件读取html内容,现在需要用vscode-resource uri替换占位符(${key})。

有没有不使用htmlString.replace('${key}', vscodeResourceString)的方法?我的html很大,更喜欢从外部文件中读取它。

我的样品:

 private async _getHtmlForWebview() {
    // Get path to resource on disk
    const onDiskPath = vscode.Uri.file(path.join(WelcomePage.resourcesDir,'m,deia', 'run.svg'));
    // And get the special URI to use with the webview
    const runIconSrc = onDiskPath.with({ scheme: 'vscode-resource' });

    let content: string = await fileUtils.readFileToString(path.join(WelcomePage.resourcesDir, 'welcome', "welcomePage.html"));

    return content.replace('${runIconSrc}', runIconSrc.toString());
}

谢谢!

0 个答案:

没有答案