Skip to content

Commit e7759a2

Browse files
Copilotpranaygp
andcommitted
Add code highlighting for "use workflow" and "use step" directives in Effortless Setup section
Co-authored-by: pranaygp <1797812+pranaygp@users.noreply.github.com>
1 parent 141fc64 commit e7759a2

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

docs/app/(home)/components/code-block.tsx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { codeToHtml } from 'shiki';
1+
import { codeToHtml, type ShikiTransformer } from 'shiki';
22
import { cn } from '@/lib/utils';
33

44
type CodeBlockProps = {
@@ -7,16 +7,49 @@ type CodeBlockProps = {
77
codeblock?: {
88
className?: string;
99
};
10+
/**
11+
* List of strings to highlight in the code block.
12+
* These will be given a special highlight style.
13+
*/
14+
highlight?: string[];
1015
};
1116

12-
export const CodeBlock = async ({ code, lang, codeblock }: CodeBlockProps) => {
17+
/**
18+
* Creates a Shiki transformer that highlights specific strings in code.
19+
*/
20+
function createHighlightTransformer(patterns: string[]): ShikiTransformer {
21+
return {
22+
name: 'highlight-strings',
23+
span(node, _line, _col, _lineElement, token) {
24+
// Check if the token content matches any of the patterns
25+
const tokenContent = token.content;
26+
if (patterns.some((pattern) => tokenContent.includes(pattern))) {
27+
this.addClassToHast(node, 'highlighted-code');
28+
}
29+
},
30+
};
31+
}
32+
33+
export const CodeBlock = async ({
34+
code,
35+
lang,
36+
codeblock,
37+
highlight,
38+
}: CodeBlockProps) => {
39+
const transformers: ShikiTransformer[] = [];
40+
41+
if (highlight && highlight.length > 0) {
42+
transformers.push(createHighlightTransformer(highlight));
43+
}
44+
1345
const html = await codeToHtml(code, {
1446
lang,
1547
themes: {
1648
light: 'github-light-default',
1749
dark: 'github-dark-default',
1850
},
1951
defaultColor: false,
52+
transformers,
2053
});
2154

2255
return (

docs/app/(home)/components/implementation.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export const Implementation = () => (
7777
className:
7878
'shadow-none !bg-background dark:bg-sidebar h-full rounded-md with-line-numbers',
7979
}}
80+
highlight={['use workflow', 'use step']}
8081
/>
8182
</div>
8283
))}

docs/app/global.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,8 @@
157157
.with-checks.with-line-numbers code .line::before {
158158
@apply left-5!;
159159
}
160+
161+
/* Highlighted code style for directive strings like "use workflow" and "use step" */
162+
.highlighted-code {
163+
@apply bg-primary/15 rounded px-1 py-0.5;
164+
}

0 commit comments

Comments
 (0)