mdxld
Parse, Stringify, Validate, and Compile MDXLD Documents
mdxld
mdxld is the core package for working with MDXLD (MDX + Linked Data) documents. It provides utilities to parse, stringify, validate, and compile MDX documents with semantic frontmatter.
Installation
What is MDXLD?
MDXLD extends standard MDX frontmatter with JSON-LD compatible properties, enabling semantic web capabilities in your MDX documents.
Standard MDX
MDXLD
Core Concepts
Linked Data Properties
MDXLD recognizes special frontmatter properties that map to JSON-LD:
| MDXLD | JSON-LD | Description |
|---|---|---|
$type | @type | Document or entity type |
$id | @id | Unique identifier (URI) |
$context | @context | JSON-LD context |
Document Structure
An MDXLD document consists of:
Quick Start
Parsing
Stringifying
Converting to AST
Submodules
mdxld/ast
Work with the MDX abstract syntax tree:
mdxld/validate
Validate documents with ArkType schemas:
mdxld/compile
Compile MDX to executable code:
mdxld/types
TypeScript types for MDXLD:
API Reference
parse(content: string): MDXLDDocument
Parse MDX string into a document object.
stringify(doc: MDXLDDocument): string
Convert a document object back to MDX string.
toAst(doc: MDXLDDocument): MDXLDAst
Convert a document to an abstract syntax tree.
fromAst(ast: MDXLDAst): MDXLDDocument
Convert an AST back to a document.
TypeScript Support
mdxld is written in TypeScript and provides full type definitions:
Format Conversion Packages
The @mdxld/* ecosystem includes packages for bi-directional conversion between objects and various formats:
| Package | Description |
|---|---|
@mdxld/markdown | Object ↔ Markdown conversion |
@mdxld/json | JSON, JSON-LD, JSON Schema, OpenAPI, MCP, GraphQL |
@mdxld/html | Semantic HTML with microdata |
@mdxld/yaml | YAML for configs, K8s, CI/CD |
@mdxld/typescript | TypeScript types, Zod schemas, JSON5 |
@mdxld/diff | Git-style diffing and 3-way merge |
See Format Conversion for the complete guide.
Next Steps
- Parsing Documents - Deep dive into parsing
- Validation - Schema validation with ArkType
- AST Manipulation - Working with the syntax tree
- Compilation - Compiling MDX to code
- Format Conversion - Convert to/from Markdown, JSON, HTML, etc.