# AGENTS.md ## System Intent & Context This repository is a high-performance, rule-based **block markdown editor** built with Vue 3, TypeScript, and the Lezer parsing framework. Documents are structured as distinct, interactive **Blocks** rather than a single flat string. A 3-stage parsing pipeline bridges UI state down to ASTs, enabling real-time extraction of pages, references, task state, callouts, and inline decorations. --- ## Monorepo Structure ``` apps/dev/ Development and testing sandbox (Vue 3 + Vite + TypeScript) packages/editor/ Core headless engine — parsers, rule registries, composables, tests ``` **Component flow (editor shell):** ``` apps/dev/src/pages/EditorView.vue └── apps/dev/src/components/Editor.vue └── packages/editor/src/components/Editor.vue ← multi-block shell ├── packages/editor/src/components/InsertionZone.vue └── packages/editor/src/components/Block.vue ├── packages/editor/src/composables/useMarkdownDecorations.ts │ └── packages/editor/src/lib/markdown-parser.ts │ └── packages/editor/src/lib/markdown-rules/engine.ts │ ├── block-classifier.ts (paste only) │ ├── inline-rules.ts │ └── block-rules.ts ├── packages/editor/src/composables/useBlockKeyboardHandlers.ts └── packages/editor/src/composables/usePatternPlugin.ts ``` --- ## Parsing Pipeline All syntax features flow through a 2-stage pipeline in `packages/editor/src/lib/markdown-rules/engine.ts`: ``` [Raw Block Content String] │ ├── Phase 1: Lezer AST Visitor │ ├─ enter → block rules (headings, blockquotes, callouts, tasks) │ └─ leave → inline rules (bold, italic, code, links, refs, tags, highlights) │ ├── Phase 2: Property Extraction → Suffix Matcher (Key::Value) │ ▼ [ParsedDecorations — unified output struct] ``` > **Note**: `classifyBlock()` in `block-classifier.ts` is used only by the paste handler (`usePasteHandler.ts`), not by the main decoration engine. ### Unified Output Contract ```typescript export interface DecorationRange { type: "hidden" | "content" from: number to: number className?: string } export interface ParsedDecorations { content: (TokenDecoration | PageRefDecoration | BlockRefDecoration | TagDecoration | HighlightDecoration)[] properties: PropertyInfo[] blocks: BlockDecoration[] } ``` Do not change this interface without updating both unit tests and block render cycles. --- ## Supported Syntax ### Task States ``` TODO Fix the critical focus bug └──┘ status ``` - **Valid states:** `TODO`, `DOING`, `DONE`, `LATER`, `NOW`, `WAITING`, `CANCELLED` - **State progression:** `TODO → DOING → DONE` (linear). `LATER`, `NOW`, `WAITING`, `CANCELLED` are orthogonal. ### Obsidian-Style Elements | Syntax | Example | |---|---|---| | Page reference | `[[Page Name]]` or `[[Real Page\|Display Name]]` | | Block reference | `((block-id-1234))` | | Callout | `> [!NOTE] Description text` | | Property | `author:: John Doe` | | Table | `\| A \| B \|\n\|---\|---\|\n\| 1 \| 2 \|` | ### Tables Tables use a **two-state rendering pattern**: blurred → source hidden, HTML widget rendered via `renderTableHtml()` → `renderCellContent()` (runs each cell through the Lezer parser for inline markdown → HTML conversion); focused → `|` pipes styled as `md-decorator`, cell content editable as raw markdown. Clicking the rendered table focuses the block. **Valid callout types:** `NOTE`, `WARNING`, `TIP`, `DANGER`, `INFO` --- ## Technology Stack | Layer | Technology | Rule | |---|---|---| | Framework | Vue 3 (Composition API, `