codeImport()

बाहरी फ़ाइलों से code को fenced code blocks में import करें।

import { codeImport } from "@unifast/node";

Signature

function codeImport(options?: CodeImportPluginOptions): UnifastPlugin

Parameters

options?

Code import व्यवहार के लिए Configuration

PropertyTypeDefaultविवरण
rootDirstringfile paths को resolve करने के लिए root directory। जब omit किया जाता है, तो paths current working directory के सापेक्ष resolve होते हैं।

उपयोग

import { compile, codeImport } from "@unifast/node";

const md = `
\`\`\`ts file="./src/example.ts"
\`\`\`
`;

const result = compile(md, {
  plugins: [
    codeImport({
      rootDir: "/path/to/project",
    }),
  ],
});

console.log(result.output);
// code block ./src/example.ts की सामग्री से replace हो जाता है

उदाहरण

मूल file import

```ts file="./src/utils.ts"
```

code block content फ़ाइल की सामग्री से replace हो जाता है, syntax highlighting के लिए language को preserve करते हुए।

rootDir के साथ

import { compile, codeImport } from "@unifast/node";

const result = compile(md, {
  plugins: [
    codeImport({ rootDir: "/home/user/project" }),
  ],
});

console.log(result.output);
// File paths rootDir के सापेक्ष resolve होते हैं

rootDir के बिना

import { compile, codeImport } from "@unifast/node";

const result = compile(md, {
  plugins: [codeImport()],
});

console.log(result.output);
// File paths current working directory के सापेक्ष resolve होते हैं