
Dinja
Safe, deterministic MDX rendering powered by a Rust HTTP service with Python and TypeScript clients.
Links
Quick Start
1. Start the Service
2. Install a Client
| Target | Command |
|---|---|
| Python | pip install dinja |
| TypeScript | npm install @dinja/core |
3. Render MDX
Python:
=
=
# Output: <h1>Hello <strong>World</strong></h1>
TypeScript:
import { Renderer, getOutput } from "@dinja/core";
const renderer = new Renderer({ baseUrl: "http://localhost:8080" });
const result = await renderer.html({
views: { "page.mdx": "# Hello **World**" },
});
console.log(getOutput(result, "page.mdx"));
// Output: <h1>Hello <strong>World</strong></h1>
Output Formats
| Format | Description |
|---|---|
html |
Rendered HTML |
javascript |
JavaScript code |
schema |
Extract custom component names |
json |
JSON tree representation |
Components
Define custom components that render in your MDX:
Python:
=
TypeScript:
const result = await renderer.html({
views: { "app.mdx": "# App\n\n<Button>Click me</Button>" },
components: {
Button:
"export default function Component(props) { return <button>{props.children}</button>; }",
},
});
Global Utilities
Inject JavaScript utilities available to all components:
=
YAML Frontmatter
Extract metadata from YAML frontmatter:
=
=
# "My Post"
API Reference
Python
=
# Render methods
=
=
=
=
=
# Health check
=
# Result methods
TypeScript
import { Renderer, isAllSuccess, getOutput, getMetadata } from '@dinja/core';
const renderer = new Renderer({ baseUrl: 'http://localhost:8080', timeout: 30000 });
// Render methods
const result = await renderer.html({ views: {...}, components: {...}, utils: '...', minify: true, directives: [...] });
const result = await renderer.javascript({ views: {...} });
const result = await renderer.schema({ views: {...} });
const result = await renderer.json({ views: {...} });
const result = await renderer.render('html', { views: {...} });
// Health check
const isHealthy = await renderer.health();
// Helper functions
isAllSuccess(result);
getOutput(result, 'filename.mdx');
getMetadata(result, 'filename.mdx');
Rust Core
For direct Rust integration, see dinja-core on crates.io.
use ;
use ;
use HashMap;
License
BSD 3-Clause. See LICENSE.