Markdown Integration
Embed diagrams in .md files with remark or markdown-it
שילוב Markdown
הטמעת דיאגרמות Datro ישירות בקבצי Markdown באמצעות בלוקי קוד מגודרים סטנדרטיים. שרשרת הכלים מספקת תוסף הערה (עבור MDX, Next.js, Astro ו-Vite) ו-תוסף markdown-it (עבור VitePress, Docusaurus וצינורות מותאמים אישית).
הטמעת דיאגרמה
סמן כל בלוק קוד מגודר עם מזהה השפה datro. הבלוק חייב להתחיל עם כותרת הקסם #!DATRO 1.0. הפלאגין מנתח, מאמת ומחליף את הבלוק ב-SVG מוטבע (או <img> המצביע על PNG מעובד).
# System Architecture
The diagram below is generated automatically from source:
```datro
#!DATRO 1.0
meta { title: "Auth Service" }
node client { type: web label: "Browser" }
node api_gw { type: gateway label: "API Gateway" }
node auth { type: service label: "Auth Service" }
node user_db { type: database label: "User DB" }
edge client -> api_gw { kind: http label: "POST /login" }
edge api_gw -> auth { kind: http }
edge auth -> user_db { kind: query }
layout { direction: LR algo: dagre }
theme {
palette { gateway: "#FFD0D0" service: "#D0E8FF" database: "#FFE8C0" }
accessibility { min_contrast: AA }
}
```
> Rendered inline by the datro remark plugin.אימות בזמן בנייה
שני התוספים מריצים את אימות ארבעת המעבר המלא במהלך הבנייה. אם לבלוק כלשהו יש אבחון של חומרת שגיאה, הבנייה נכשלת מיד עם המיקום file:line:col.
מאפיין מזהה חסום
הוסף id="name" אחרי גדר הפתיחה כדי לתת לבלוק מזהה יציב. ה-CLI משתמש בזה בעת מתן שמות לקבצי פלט, והתוספים חושפים אותו כתכונת נתונים באלמנט המעובד.
```datro id="auth-flow"
#!DATRO 1.0
node a { type: service label: "A" }
node b { type: service label: "B" }
edge a -> b { kind: http }
```תוסף הערה
השתמש עם כל צינור המבוסס על הערות: Next.js MDX, Astro, Gatsby, הערה מאוחדת או רגילה.
npm install datro remark remark-html// remark.config.mjs
import remarkDatro from "datro/remark";
const config = {
plugins: [
// Transforms ```datro blocks to inline SVG
[remarkDatro, { format: "svg" }],
],
};
export default config;Next.js MDX
// next.config.mjs
import remarkDatro from "datro/remark";
import createMDX from "@next/mdx";
const withMDX = createMDX({
options: {
remarkPlugins: [[remarkDatro, { format: "svg" }]],
},
});
export default withMDX({
pageExtensions: ["js", "jsx", "ts", "tsx", "md", "mdx"],
});| Field | Type | Required | Default | Description |
|---|---|---|---|---|
format | string "svg""png" | No | svg | פורמט פלט מעובד. |
failOnError | boolean | No | true | כאשר false, בלוקים עם שגיאות נשארים כקוד מגודר במקום להיכשל בבנייה. |
outDir | string | No | — | ספרייה לקובצי PNG (מצב PNG בלבד). ברירת המחדל לאותה ספרייה כמו קובץ המקור. |
תוסף markdown-it
השתמש עם כל צינור של markdown-it: VitePress, Docusaurus או כל שרת Node.js שמשתמש ישירות ב-markdown-it.
import MarkdownIt from "markdown-it";
import datroPLugin from "datro/markdown-it";
const md = new MarkdownIt();
md.use(datroPLugin, { format: "svg" });
const html = md.render(source);VitePress / Vite
ב-VitePress, הוסף את הפלאגין ל-defineConfig({ markdown: { config: md => md.use(datroPlugin) } }). עבור Vite עם vite-plugin-markdown עיין בדוגמה של תצורת Vite למטה.
// vite.config.ts
import { defineConfig } from "vite";
import mdPlugin from "vite-plugin-markdown";
import remarkDatro from "datro/remark";
export default defineConfig({
plugins: [
mdPlugin({
remarkPlugins: [[remarkDatro, { format: "svg" }]],
}),
],
});צינור CLI (ללא צרור)
אם אינך משתמש ב-bundler, השתמש בפקודות CLI datro md כדי לעבד קבצי Markdown ישירות. זה דורש Graphviz עבור פלט SVG/PNG, אבל md check פועל בלעדיו.
# Render all datro blocks in a markdown file to SVG
datro md render docs/architecture.md --out-dir public/diagrams
# Validate all blocks without rendering (fast, no Graphviz needed)
datro md check docs/architecture.md- קבצי הפלט נקראים
{markdown-basename}-{block-id}.{svg|png}. - השתמש ב-
--no-failכדי לעבד את כל הבלוקים גם כאשר לחלקם יש שגיאות - שימושי עבור צינורות הגירה. - השתמש ב-
--jsonעםmd checkעבור פלט מובנה במערכות הערות CI.
השלבים הבאים
- קרא את Language Reference עבור תחביר
.dtroהמלא. - קרא את CLI Reference עבור דגלי
datro md renderושילוב CI.
בנה ותצוגה מקדימה של דיאגרמות בדפדפן ללא כל הגדרה מקומית.