Skip to content

Commit

Permalink
canonical lang
Browse files Browse the repository at this point in the history
  • Loading branch information
JSerZANP committed Jul 9, 2024
1 parent f04624d commit 0d5555d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 42 deletions.
21 changes: 20 additions & 1 deletion examples/web/app/snippet/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import Head from "next/head";
import { CodeSnippet } from "../../components/CodeSnippet";

const langMap = {
js: "javascript",
ts: "typescript",
yml: "yaml",
rb: "ruby",
rs: "rust",
ps1: "powershell",
fs: "f#",
fsharp: "f#",
docker: "dockerfile",
bat: "batch",
};
function getCanonicalLang(lang?: string | null) {
if (lang == null) return null;
return langMap[lang] ?? lang;
}

export default async function Page({
searchParams,
}: {
Expand All @@ -9,7 +26,9 @@ export default async function Page({
const codeFromParams = searchParams?.code;
const langFromParams = searchParams?.lang;
const code = typeof codeFromParams === "string" ? codeFromParams : null;
const lang = typeof langFromParams === "string" ? langFromParams : null;
const lang = getCanonicalLang(
typeof langFromParams === "string" ? langFromParams : null
);

return (
<>
Expand Down
4 changes: 3 additions & 1 deletion examples/web/components/CodeSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export function CodeSnippet({
code?: string;
lang?: string;
}) {
const [lang, setLang] = useState<string>(_lang ?? "javascript");
const [lang, setLang] = useState<string>(
_lang in defaultCode ? _lang : "javascript"
);
const [code, setCode] = useState(_code ?? defaultCode[lang] ?? "");

const share = () => {
Expand Down
40 changes: 0 additions & 40 deletions packages/shaku-code-annotate-shiki/src/defaultCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,47 +503,7 @@ export default function Counter() {
</button>
);
}`,
js: `// @highlight
import { useState } from 'react';
// ( ) (2 ) ( 3 )
export default function Counter() {
// @highlight
const [count, setCount] = useState(0);
//~~~~~~~~
// @diff + start
// This
// is
// Comment
// @diff + end
function handleClick() {
setCount(count + 1);
//-------------------
// ^
//[Underline and callout!]
}

// @class clickable
// @data jser=dev
const blog = "https://jser.dev"
// @diff -
console.log('jser.dev')
// @cut v
// comment to cut
// @cut ^
return (
<button onClick={handleClick}>
{/* ^ */}
{/* [Supports JSX] */}
{/* [Awesome,right?] */}
You pressed me {count} times
</button>
);
}`,
imba: `
# @highlight
# coffee
Expand Down

0 comments on commit 0d5555d

Please sign in to comment.