Skip to content

Commit

Permalink
chore: highlight HTML code (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt authored Dec 22, 2024
1 parent 2b5464f commit 4f44ba7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"bierner.lit-html"
]
}
4 changes: 2 additions & 2 deletions src/locatorsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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`
<!DOCTYPE html>
<html lang="en">
<head>
Expand Down
4 changes: 2 additions & 2 deletions src/settingsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 `<!DOCTYPE html>
return html`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
Expand Down
5 changes: 5 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 4f44ba7

Please sign in to comment.