Loading…
import * as vscode from 'vscode'; import { findTheme, paletteToCss } from '../themes/themes'; import { hljsCssFor } from '../../packages/core/src/themes/hljsCss'; const NONCE_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; function nonce(): string { let s = ''; for (let i = 0; i < 32; i++) s += NONCE_CHARS.charAt(Math.floor(Math.random() * NONCE_CHARS.length)); return s; } export function buildWebviewHtml( webview: vscode.Webview, extensionUri: vscode.Uri, theme: string, ): string { const n = nonce(); const scriptUri = webview.asWebviewUri( vscode.Uri.joinPath(extensionUri, 'out', 'webview', 'main.js'), ); // Custom theme overrides — only emitted when a non-auto theme is selected. const themeDef = theme === 'auto' ? undefined : findTheme(theme); const themeOverride = themeDef ? `:root[data-theme="${theme}"] { ${paletteToCss(themeDef.palette)} color-scheme: ${themeDef.kind}; }` : ''; const hljsOverride = themeDef ? hljsCssFor(themeDef) : ''; return /* html */ `
Loading…