codeImport()
बाहरी फ़ाइलों से code को fenced code blocks में import करें।
import { codeImport } from "@unifast/node";Signature
function codeImport(options?: CodeImportPluginOptions): UnifastPluginParameters
options?
Code import व्यवहार के लिए Configuration
| Property | Type | Default | विवरण |
|---|---|---|---|
rootDir | string | — | file 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
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 होते हैं