import * as vscode from "vscode"; import * as path from "path"; export function webViewPanel(context: vscode.ExtensionContext, code: string) { // 1. 使用 createWebviewPanel 创建一个 panel,然后给 panel 放入 html 即可展示 web view const panel = vscode.window.createWebviewPanel( "shareWeb", "分享题目", vscode.ViewColumn.One, // web view 显示位置 { enableScripts: true, // 允许 JavaScript retainContextWhenHidden: true, // 在 hidden 的时候保持不关闭 } ); const template = { background: "#101213", width: "auto", height: "auto", borderRadius: "5px", }; // 获取npm包 const onDiskPath = vscode.Uri.file( path.join(context.extensionPath, "media", "painterhighlight.js") ); const URI = onDiskPath.with({ scheme: "vscode-resource" }); panel.webview.html = getWebviewContent(code, JSON.stringify(template), URI); } function getWebviewContent( code: string, template: string, scriptUri: vscode.Uri ) { // console.log(code); return `