@mdxld/html
Bi-directional conversion between Objects and semantic HTML with microdata
@mdxld/html
Convert objects to semantic HTML with Schema.org microdata. Produces clean, accessible HTML5 with proper semantic elements and structured data markup.
Installation
Quick Start
Output:
API Reference
toHTML(object, options?)
Convert an object to semantic HTML.
Example with options:
fromHTML(html, options?)
Extract structured data from HTML.
Example:
toJSONLDScript(object, options?)
Generate a JSON-LD <script> tag for SEO.
Example:
Semantic HTML Conventions
Objects are rendered using semantic HTML5 elements:
| Object Shape | HTML Element |
|---|---|
| Root | <article> |
name | <h1> |
description | <p> |
properties[] | <table> |
sections[] | <section> with <h2> |
items[] | <ul> with <li> |
| Other key-value pairs | <dl>, <dt>, <dd> |
Heading Hierarchy
Nested structures create proper heading hierarchy:
Microdata (Schema.org)
When microdata: true (default), Schema.org attributes are added:
Automatic Type Inference
The itemtype is automatically inferred from object shape:
| Object Shape | Inferred itemtype |
|---|---|
email + name | Person or Organization |
address | Place or PostalAddress |
startDate + endDate | Event |
ingredients + instructions | Recipe |
headline + author | Article |
Property Tables
Objects with properties[] render as tables:
Output:
Use Cases
Server-Side Rendering
Email Templates
Static Site Generation
Content Extraction
Relationship to @mdxui/html
| Package | Purpose |
|---|---|
@mdxld/html | Semantic conversion (data structure → HTML) |
@mdxui/html | Presentation (adds styling, themes, CSS) |
Related Packages
| Package | Description |
|---|---|
@mdxld/markdown | Object ↔ Markdown |
@mdxld/json | JSON-LD and JSON Schema |
@mdxui/html | Styled HTML output |
@mdxld/jsx | JSX runtime for HTML |