Core: fix multi-line in remark-npm

This commit is contained in:
Fuma Nama
2026-04-14 22:52:09 +08:00
parent 563edd9993
commit 9a200c8de6
2 changed files with 16 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-core': patch
---
fix multi-line in remark-npm
+11 -4
View File
@@ -33,16 +33,23 @@ export interface RemarkNpmOptions {
packageManagers?: PackageManager[];
}
function convertLines(cmd: string, to: 'yarn' | 'pnpm' | 'bun') {
return cmd
.split('\n')
.map((l) => convert(l, to))
.join('\n');
}
/**
* It generates multiple tabs of codeblocks for different package managers from a npm command codeblock.
*/
export function remarkNpm({
persist = false,
packageManagers = [
{ command: (cmd) => convert(cmd, 'npm'), name: 'npm' },
{ command: (cmd) => convert(cmd, 'pnpm'), name: 'pnpm' },
{ command: (cmd) => convert(cmd, 'yarn'), name: 'yarn' },
{ command: (cmd) => convert(cmd, 'bun'), name: 'bun' },
{ command: (cmd) => cmd, name: 'npm' },
{ command: (cmd) => convertLines(cmd, 'pnpm'), name: 'pnpm' },
{ command: (cmd) => convertLines(cmd, 'yarn'), name: 'yarn' },
{ command: (cmd) => convertLines(cmd, 'bun'), name: 'bun' },
],
}: RemarkNpmOptions = {}): Transformer<Root, Root> {
return (tree) => {