Skip to content

Commit

Permalink
transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
JSerZANP committed Jul 4, 2024
1 parent b7d13a2 commit 263bd8f
Show file tree
Hide file tree
Showing 174 changed files with 15,276 additions and 7,955 deletions.
6 changes: 6 additions & 0 deletions .changeset/purple-walls-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"shaku-code-annotate-shiki": minor
"shaku-code-annotate-core": minor
---

transformer
22 changes: 22 additions & 0 deletions examples/web/app/snippet-transformer/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Head from "next/head";
import { CodeSnippet } from "../../components/CodeSnippet";

export default async function Page({
searchParams,
}: {
searchParams: { [key: string]: string | string[] | undefined };
}) {
const codeFromParams = searchParams?.code;
const langFromParams = searchParams?.lang;
const code = typeof codeFromParams === "string" ? codeFromParams : null;
const lang = typeof langFromParams === "string" ? langFromParams : null;

return (
<>
<Head>
<title>Shaku Code Snippet</title>
</Head>
<CodeSnippet code={code} lang={lang} useTransformer />
</>
);
}
15 changes: 14 additions & 1 deletion examples/web/components/CodeSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@ const CodeSnippetPreview = dynamic(() => import("./CodeSnippetPreview"), {
ssr: false,
});

const CodeSnippetPreviewTransformer = dynamic(
() => import("./CodeSnippetPreviewTransformer"),
{
ssr: false,
}
);

export function CodeSnippet({
code: _code,
lang: _lang,
useTransformer,
}: {
code?: string;
lang?: string;
useTransformer?: boolean;
}) {
const [lang, setLang] = useState<string>(_lang ?? "javascript");
const [code, setCode] = useState(_code ?? defaultCode[lang] ?? "");
Expand Down Expand Up @@ -104,7 +113,11 @@ export function CodeSnippet({
}}
/>
</Column>
<CodeSnippetPreview code={code} lang={lang} />
{useTransformer ? (
<CodeSnippetPreviewTransformer code={code} lang={lang} />
) : (
<CodeSnippetPreview code={code} lang={lang} />
)}
</Row>
</Column>
);
Expand Down
Loading

0 comments on commit 263bd8f

Please sign in to comment.