Remark NPM
Generate code blocks for package managers
Usage
Remark NPM is a remark plugin. Fumadocs MDX enables it by default. Pass options with remarkNpmOptions.
Define the required components:
import { CodeBlockTabs, CodeBlockTab, CodeBlockTabsList, CodeBlockTabsTrigger } from 'my-ui';
import type { MDXComponents } from 'mdx/types';
export function getMDXComponents(components?: MDXComponents) {
return {
CodeBlockTabs,
CodeBlockTab,
CodeBlockTabsList,
CodeBlockTabsTrigger,
...components,
} satisfies MDXComponents;
}Input
Create code blocks with npm as language.
```npm
npm i my-package
```
```npm
npm i my-package -D
```package-install code blocks work too. They take package names, like my-package, and turn them into npm install commands.
Output
The following structure should be generated by the plugin.
<CodeBlockTabs defaultValue="npm">
<CodeBlockTabsList>
<CodeBlockTabsTrigger value="npm">npm</CodeBlockTabsTrigger>
<CodeBlockTabsTrigger value="pnpm">pnpm</CodeBlockTabsTrigger>
<CodeBlockTabsTrigger value="yarn">yarn</CodeBlockTabsTrigger>
<CodeBlockTabsTrigger value="bun">bun</CodeBlockTabsTrigger>
</CodeBlockTabsList>
<CodeBlockTab value="npm">...</CodeBlockTab>
<CodeBlockTab value="pnpm">...</CodeBlockTab>
<CodeBlockTab value="yarn">...</CodeBlockTab>
<CodeBlockTab value="bun">...</CodeBlockTab>
</CodeBlockTabs>npm i my-packagePersistent
When using with Fumadocs UI, you can persist the selected value with the persist option.
import { defineConfig } from 'fumadocs-mdx/config';
export default defineConfig({
mdxOptions: {
remarkNpmOptions: {
persist: {
id: 'package-manager',
},
},
},
});This will generate a persist prop to <CodeBlockTabs />.
How is this guide?
Last updated on
