Skip to content

Commit

Permalink
feat: ability to disable line number for individual blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
o-az committed Sep 2, 2024
1 parent 37dc0d5 commit 6e7cbaa
Show file tree
Hide file tree
Showing 18 changed files with 517 additions and 461 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@
},
"files.exclude": {
".zed": true,
"**/build": true,
".gitignore": true,
"**/LICENSE": true,
"**/dist/**": true,
"**/.turbo/**": true,
"**/.astro/**": true,
"pnpm-lock.yaml": true,
"**/.svelte-kit": true,
"**/*.timestamp-*": true
},
"[markdown]": {
Expand Down
7 changes: 4 additions & 3 deletions docs/astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { defineConfig } from 'astro/config';
import remarkSmartypants from 'remark-smartypants';
import { rehypeHeadingIds } from '@astrojs/markdown-remark';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import starlightLinksValidator from 'starlight-links-validator';
import { transformerTwoslash, rendererRich } from '@shikijs/twoslash';
import moonlightTheme from './public/theme/moonlight-ii.json' with {
type: 'json',
Expand Down Expand Up @@ -60,7 +61,7 @@ export default defineConfig({
visibility: 'always',
feedbackDuration: 2_500,
}),
transformerLineNumbers({ autoApply: true }),
transformerLineNumbers({ autoApply: false }),
transformerNotationDiff(),
transformerNotationFocus(),
transformerMetaHighlight(),
Expand Down Expand Up @@ -89,7 +90,7 @@ export default defineConfig({
'./src/styles/tailwind.css',
'./node_modules/@shikijs/twoslash/style-rich.css',
],
plugins: [],
plugins: [starlightLinksValidator()],
head: [
{
tag: 'script',
Expand All @@ -104,8 +105,8 @@ export default defineConfig({
{
label: 'Plugins',
autogenerate: {
directory: 'plugins',
collapsed: false,
directory: 'plugins',
},
},
{
Expand Down
1 change: 1 addition & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"remark-toc": "^9.0.0",
"sharp": "^0.33.5",
"shiki": "^1.16.1",
"starlight-links-validator": "^0.11.0",
"tailwindcss": "^3.4.10"
},
"devDependencies": {
Expand Down
137 changes: 115 additions & 22 deletions docs/src/components/package-manager.astro
Original file line number Diff line number Diff line change
@@ -1,41 +1,134 @@
---
import { Code } from 'astro/components';
import type { ComponentProps } from 'astro/types';
import { Tabs, TabItem } from '@astrojs/starlight/components';
import type { NoRepetition } from '../lib/utilities/types.ts';
import { transformerCopyButton } from '@rehype-pretty/transformers';
import {
type RawTheme,
createJavaScriptRegexEngine,
createHighlighter,
} from 'shiki';
import moonlightTheme from '../../public/theme/moonlight-ii.json' with {
type: 'json',
};
const packageManager = ['pnpm', 'bun', 'npm', 'yarn', 'jsr', 'ni'] as const;
type PackageManager = (typeof packageManager)[number];
type TabItemProps = ComponentProps<typeof TabItem>;
interface Props {
packageManagers: NoRepetition<'pnpm' | 'bun' | 'npm' | 'yarn' | 'ni' | 'jsr'>;
dev?: boolean;
packageId: string;
packageManagers: NoRepetition<PackageManager>;
type?: 'add' | 'create' | 'exec' | 'run' | 'remove';
}
const packageManagers = Astro.props.packageManagers ?? [
'pnpm',
'bun',
'npm',
'yarn',
'jsr',
];
const iconMap: Record<string, TabItemProps['icon'] | undefined> = {
bun: 'bun',
pnpm: 'pnpm',
npm: 'seti:npm',
yarn: 'seti:yarn',
ni: 'seti:shell',
jsr: 'seti:shell',
};
const {
dev,
packageId,
type = 'add',
// @ts-expect-error
packageManagers = packageManager,
} = Astro.props;
const javascriptEngine = createJavaScriptRegexEngine();
const shiki = await createHighlighter({
langs: ['sh'],
engine: javascriptEngine,
themes: [moonlightTheme as unknown as RawTheme],
});
const managers = [
{
name: 'bun',
icon: 'bun',
code: shiki.codeToHtml(`bun add ${packageId}`, {
lang: 'sh',
theme: moonlightTheme as unknown as RawTheme,
transformers: [
transformerCopyButton({
visibility: 'always',
feedbackDuration: 3_000,
}),
],
}),
},
{
name: 'pnpm',
icon: 'pnpm',
code: shiki.codeToHtml(`pnpm add ${packageId}`, {
lang: 'sh',
theme: moonlightTheme as unknown as RawTheme,
transformers: [
transformerCopyButton({
visibility: 'always',
feedbackDuration: 3_000,
}),
],
}),
},
{
name: 'npm',
icon: 'seti:npm',
code: shiki.codeToHtml(`npm install ${packageId}`, {
lang: 'sh',
theme: moonlightTheme as unknown as RawTheme,
transformers: [
transformerCopyButton({
visibility: 'always',
feedbackDuration: 3_000,
}),
],
}),
},
{
name: 'yarn',
icon: 'seti:yarn',
code: shiki.codeToHtml(`yarn add ${packageId}`, {
lang: 'sh',
theme: moonlightTheme as unknown as RawTheme,
transformers: [
transformerCopyButton({
visibility: 'always',
feedbackDuration: 3_000,
}),
],
}),
},
{
name: 'jsr',
icon: 'seti:shell',
code: shiki.codeToHtml(`npx jsr add ${packageId}`, {
lang: 'sh',
theme: moonlightTheme as unknown as RawTheme,
transformers: [
transformerCopyButton({
visibility: 'always',
feedbackDuration: 3_000,
}),
],
}),
},
] satisfies Array<{
code: string;
name: PackageManager;
icon: TabItemProps['icon'];
}>;
---

<Tabs syncKey="pkg">
{
// @ts-expect-error
packageManagers.map(pkgManager => (
<TabItem label={pkgManager} icon={iconMap[pkgManager]}>
<Code lang="sh" code={`${pkgManager} add @rehype-pretty/transformers`} />
managers.map(manager => (
<TabItem label={manager.name} icon={manager.icon}>
<div set:html={manager.code} data-package-manager-code="" />
</TabItem>
))
}
</Tabs>

<style></style>
<style is:global>
div[data-package-manager-code] pre code {
margin-left: 1rem;
}
</style>
Loading

0 comments on commit 6e7cbaa

Please sign in to comment.