How nuxt-modules/mdc works
Project Type and Purpose
• This is a Nuxt/Vue module (“@nuxtjs/mdc”) that extends Markdown by deeply integrating Vue components (MDC = “MarkDown Components”).
• It provides two core runtime capabilities: parsing raw Markdown into an intermediate AST, and rendering that AST into interactive Vue components in the browser (or server).
High-Level Architectural Macro–Areas
A. Runtime Parsing (blue)
B. Runtime Rendering (green)
Main Components & Flow
1. Input (Raw Markdown)
• Sources: .md files, inline strings in Vue components, or Playground endpoint (playground/server/api/markdown.ts).
2. Runtime Parsing (blue zone)
• parseMarkdown() entry point (src/runtime/index.ts)
• Parser pipeline:
• Remark-based tokenizer (src/runtime/parser)
• rehype transformer (src/runtime/highlighter/rehype.ts)
• Optional syntax highlighter plugin (Shiki via rehype-nuxt.ts / shiki.ts)
• AST utilities (src/runtime/utils/ast.ts, etc.)
• Output: MDCParserResult (AST body + metadata)
3. Runtime Rendering (green zone)
• MDC.vue wrapper → MDCRenderer.vue (src/runtime/components)
• MDCRenderer takes AST → recursively renders nodes:
• Prose components map (ProseP, ProseH1… in src/runtime/components/prose)
• Block components (Alert, Callout etc. under components/mdc)
• MDCSlot for unwrapping wrappers
• Async component resolution (AsyncComponent.vue, PageSnippet.vue in playground)
• Final output: Vue VNodes → DOM
4. Feedback & Extensions
• Config module (src/module.ts) for Nuxt integration, global component registration, user overrides
• Playground environment demonstrates end-to-end flow
Relationships and Interactions
• Side note: Nuxt module config injects runtime parsing/rendering into Nuxt build
Architectural Patterns & Principles
• Clear separation of Concerns: parsing pipeline vs. rendering pipeline
• Plugin architecture: remark and rehype plugins can be extended
• Component map injection: map HTML tags → Vue components (prose map)
• Asynchronous rendering flow using Vue Suspense
Final Touches
• Every component and sub-module is clearly named.
• Keep it simple: only two macro areas with their internal sub-components listed.