From 4f44ba784f9e5ab9a96fd12093b7be89e75f1f47 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Sun, 22 Dec 2024 12:45:17 +0100 Subject: [PATCH] chore: highlight HTML code (#581) --- .vscode/extensions.json | 5 +++++ src/locatorsView.ts | 4 ++-- src/settingsView.ts | 4 ++-- src/utils.ts | 5 +++++ 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 .vscode/extensions.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000000..35069c86c7 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "bierner.lit-html" + ] +} \ No newline at end of file diff --git a/src/locatorsView.ts b/src/locatorsView.ts index bd0f93c8bb..8ffdd4b4f4 100644 --- a/src/locatorsView.ts +++ b/src/locatorsView.ts @@ -17,7 +17,7 @@ import { DisposableBase } from './disposableBase'; import { ReusedBrowser } from './reusedBrowser'; import { pickElementAction } from './settingsView'; -import { getNonce } from './utils'; +import { getNonce, html } from './utils'; import * as vscodeTypes from './vscodeTypes'; export class LocatorsView extends DisposableBase implements vscodeTypes.WebviewViewProvider { @@ -115,7 +115,7 @@ function htmlForWebview(vscode: vscodeTypes.VSCode, extensionUri: vscodeTypes.Ur const script = webview.asWebviewUri(vscode.Uri.joinPath(extensionUri, 'out', 'locatorsView.script.js')); const nonce = getNonce(); - return ` + return html` diff --git a/src/settingsView.ts b/src/settingsView.ts index 5960935a15..c8cf31a5a1 100644 --- a/src/settingsView.ts +++ b/src/settingsView.ts @@ -18,7 +18,7 @@ import { DisposableBase } from './disposableBase'; import type { ReusedBrowser } from './reusedBrowser'; import type { SettingsModel } from './settingsModel'; import type { TestModelCollection } from './testModel'; -import { getNonce } from './utils'; +import { getNonce, html } from './utils'; import * as vscodeTypes from './vscodeTypes'; import path from 'path'; @@ -202,7 +202,7 @@ function htmlForWebview(vscode: vscodeTypes.VSCode, extensionUri: vscodeTypes.Ur const script = webview.asWebviewUri(vscode.Uri.joinPath(extensionUri, 'out', 'settingsView.script.js')); const nonce = getNonce(); - return ` + return html` diff --git a/src/utils.ts b/src/utils.ts index bb0c0c80aa..727b3c5495 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -170,3 +170,8 @@ export function getNonce() { text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } + +// this is a no-op template tag. it instructs the "bierner.lit-html" vscode extension to highlight the string as HTML. +export function html(strings: TemplateStringsArray, ...expressions: unknown[]) { + return strings.reduce((acc, str, i) => acc + expressions[i - 1] + str); +} \ No newline at end of file