Skip to content

Commit beb1eb3

Browse files
committed
refactor: Move createHighlighter functions to own file
1 parent 9eaaed3 commit beb1eb3

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { createHighlighter as shikiCreateHighlighter, createCssVariablesTheme } from "shiki";
2+
3+
const myTheme = createCssVariablesTheme({
4+
name: "css-variables",
5+
variablePrefix: "--shiki-",
6+
variableDefaults: {},
7+
fontStyle: true,
8+
});
9+
10+
export function createHighlighter() {
11+
return shikiCreateHighlighter({
12+
themes: [myTheme],
13+
langs: ["javascript", "typescript", "python", "markdown"],
14+
});
15+
}

packages/test-case-component/src/generateHtml.ts

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,21 @@
1-
import { createHighlighter, createCssVariablesTheme } from "shiki";
1+
import { createHighlighter } from "./createHighlighter";
22
import type { BundledLanguage } from "shiki";
33
import type { Lang, StepNameType, ExtendedTestCaseSnapshot, DataFixture } from "./types";
44
import type { Command, CommandLatest, TestCaseFixture } from "@cursorless/common";
55

66
import { createDecorations } from "./helpers";
77

8-
const myTheme = createCssVariablesTheme({
9-
name: "css-variables",
10-
variablePrefix: "--shiki-",
11-
variableDefaults: {},
12-
fontStyle: true,
13-
});
14-
158
/**
169
* Generates HTML content based on the provided state, language, command, and ide.
1710
*
1811
* @param {DataFixture} data - The state object containing the necessary data for HTML generation.
19-
* @returns {Promise<string>} A promise that resolves to the generated HTML content.
12+
* @returns {Promise<{ before: string; during: string; after: string }>} A promise that resolves to the generated HTML content for each step.
2013
*/
2114
export async function generateHtml(data: DataFixture) {
22-
const HTMLOBject = await new HTMLGenerator(data)
23-
const returnObject = HTMLOBject.generateAll()
24-
return returnObject;
15+
return new HTMLGenerator(data).generateAll()
2516
}
2617

27-
const highlighter = createHighlighter({
28-
themes: [myTheme],
29-
langs: ["javascript", "typescript", "python", "markdown"],
30-
});
18+
const highlighter = createHighlighter();
3119

3220
class HTMLGenerator {
3321
private testCaseStates: {
@@ -38,22 +26,12 @@ class HTMLGenerator {
3826
private lang: Lang;
3927
private command?: CommandLatest | Command;
4028
private raw: TestCaseFixture;
41-
private rendered: {
42-
before: string;
43-
during: string;
44-
after: string;
45-
}
4629

4730
constructor(data: DataFixture) {
4831
const { languageId, command } = data;
4932
this.lang = languageId as BundledLanguage;
5033
this.command = command; // Optional command parameter
5134
this.raw = data
52-
this.rendered = {
53-
before: "",
54-
during: "",
55-
after: "",
56-
}
5735
this.testCaseStates = {
5836
before: data.initialState,
5937
during: {

0 commit comments

Comments
 (0)